Documentation underway
This commit is contained in:
		
							
								
								
									
										20
									
								
								Query.cpp
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								Query.cpp
									
									
									
									
									
								
							@@ -78,7 +78,9 @@ Customer query_customer_with_id(int id) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// -------------- paroking spots
 | 
					// -------------- paroking spots
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// vector<Park_spot>  query_all_parking_spots() {
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// vector<Park_spot> populate_spots(){
 | 
				
			||||||
//         vector<Park_spot> spots;
 | 
					//         vector<Park_spot> spots;
 | 
				
			||||||
//     SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;");
 | 
					//     SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;");
 | 
				
			||||||
//     // query.bind(1, 2);
 | 
					//     // query.bind(1, 2);
 | 
				
			||||||
@@ -91,19 +93,3 @@ Customer query_customer_with_id(int id) {
 | 
				
			|||||||
//     }
 | 
					//     }
 | 
				
			||||||
//     return spots;
 | 
					//     return spots;
 | 
				
			||||||
// }
 | 
					// }
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
vector<Park_spot> populate_spots(){
 | 
					 | 
				
			||||||
        vector<Park_spot> spots;
 | 
					 | 
				
			||||||
    SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;");
 | 
					 | 
				
			||||||
    // query.bind(1, 2);
 | 
					 | 
				
			||||||
    while (query.executeStep()) {
 | 
					 | 
				
			||||||
        int id = query.getColumn(0);
 | 
					 | 
				
			||||||
        int taken = query.getColumn(1);
 | 
					 | 
				
			||||||
        int cid = query.getColumn(2);
 | 
					 | 
				
			||||||
        // park_customers.push_back(query_customer_with_id(cid));
 | 
					 | 
				
			||||||
        spots.push_back({id, taken, cid});
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return spots;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										108
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										108
									
								
								main.cpp
									
									
									
									
									
								
							@@ -1,65 +1,103 @@
 | 
				
			|||||||
#include "headers/Query.h"
 | 
					#include "headers/Query.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <chrono>
 | 
					 | 
				
			||||||
#include <thread>
 | 
					#include <thread>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace std::chrono;
 | 
					using namespace std::chrono;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
Code strucure like this:
 | 
					Code structure is like this:
 | 
				
			||||||
class declarations zijn in /headers/class_naam.h, en definitions van de member
 | 
					1. encrypt.cpp en /header/encrypt.h contain functions to hash passwords and
 | 
				
			||||||
functs in /class_naam.cpp elke klas in zn eigen file omdat ik incomplete class
 | 
					verify passwords
 | 
				
			||||||
declarations wilt tegengaan, omdat ik ze niet goed begrijp. En header/source
 | 
					 | 
				
			||||||
split om multiple definition errors tegen te gaan.
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
Park_spot representeert een parkeermeter bij elke parkeer spot.
 | 
					2. data.cpp and /header/data.h contain the code to start up the database.
 | 
				
			||||||
Een customer is een customer.
 | 
					Originally, they were supposed to contain all the functions to save to the
 | 
				
			||||||
Park time is een object die reffereert naar parkspot en customer, basically een
 | 
					database and query from the database. I had trouble doing that, (cyclical
 | 
				
			||||||
record die zegt dat een customer voor x tijd geparkeert heeft bij spot x, enz.
 | 
					includes) and some other issues. the other issues are gone due to the latest
 | 
				
			||||||
 | 
					refactor, but to make it like my original plan is going to take a few hours, and
 | 
				
			||||||
 | 
					I have done too much already to want to do more work unless needed.
 | 
				
			||||||
 | 
					The functions to save to a database have been integrated in the classes
 | 
				
			||||||
 | 
					themself, and unless issues arrise from that I'm not changing that. Functions to
 | 
				
			||||||
 | 
					get objects from the database are in Query.cpp en header.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
De client clockt in en uit bij een spot.
 | 
					3. Park_time.cpp en header.
 | 
				
			||||||
 | 
					Contain the implementation details of Park_time, which is basically a record of
 | 
				
			||||||
 | 
					who parked at what spot and when. Uses a mix of ctime and chrono functions to do
 | 
				
			||||||
 | 
					most of the stuff, it's a mess. I will probably have to commit to Doing it one
 | 
				
			||||||
 | 
					way or the other to make it more comperhensible, especially for whoever will
 | 
				
			||||||
 | 
					make report functions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					4. Customer.cpp and header.
 | 
				
			||||||
 | 
					Contains the implementation of Customer. Customer represents a customer, and
 | 
				
			||||||
 | 
					saves park_time instances in itself. Not much to explain.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					5. Park_spot.cpp and header.
 | 
				
			||||||
 | 
					It contians the implementation details of Park_spot, which represents it's
 | 
				
			||||||
 | 
					namesake.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					6. Query.cpp and header.
 | 
				
			||||||
 | 
					Cointain functions that search the database and return objects(P_time, P_spot,
 | 
				
			||||||
 | 
					Customer) It is the least tested of the whole project, use with care.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Explanation of what members do of P_time, P_spot, Customer are in the respective
 | 
				
			||||||
 | 
					headers. Explanations of how the member functions work(Or how I intended for
 | 
				
			||||||
 | 
					them to work) are in the respective .cpp files. void Wait(int sec)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Wait(int sec)
 | 
					void Wait(int sec)
 | 
				
			||||||
/*
 | 
					
 | 
				
			||||||
a wait function where 1 sec represents 1 hour irl.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    /*
 | 
				
			||||||
 | 
					a wait function where 1 sec represents 1 hour irl. It has been used for testing
 | 
				
			||||||
 | 
					purposes mostly.
 | 
				
			||||||
 | 
					TODO: Needs to be removed at completion of project, or seperated in a test
 | 
				
			||||||
 | 
					cpp/header
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
    std::this_thread::sleep_for(seconds{sec});
 | 
					    std::this_thread::sleep_for(seconds{sec});
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static vector<Park_spot> parking_spots = populate_spots(); // to save the parking spots in memory
 | 
					static vector<Park_spot> parking_spots = populate_spots();
 | 
				
			||||||
static vector<Customer> park_customers; // save the customers that are parked in here
 | 
					// this queries the db for all the saved parking_spots and initializes them
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static vector<Customer> park_customers;
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					This was meant for an older implementation. park_time objects used to store
 | 
				
			||||||
 | 
					pointers to customers and in order to not get dangling pointers(dangerous!) I
 | 
				
			||||||
 | 
					had to have a way to store the customers the pointer pointed to so they didn't
 | 
				
			||||||
 | 
					get destroyed prematurely(I could've used the lower-level, more dangerous new,
 | 
				
			||||||
 | 
					or worse, malloc, but that's ugly).
 | 
				
			||||||
 | 
					For now, it's just here in case you want an easy way to store customers.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main() {
 | 
					int main() {
 | 
				
			||||||
    Customer sagar = query_customer_with_name("stefan udit")[0];
 | 
					    Customer sagar = query_customer_with_name("stefan udit")[0];
 | 
				
			||||||
    Customer sagar1 = query_customer_with_id(2);
 | 
					    Customer sagar1 = query_customer_with_id(2);
 | 
				
			||||||
    cout << sagar.id << "," << sagar.name << "," << sagar.password<< "\n";
 | 
					    cout << sagar.id << "," << sagar.name << "," << sagar.password << "\n";
 | 
				
			||||||
    cout << sagar1.id << "," << sagar1.name << "," << sagar1.password;
 | 
					    cout << sagar1.id << "," << sagar1.name << "," << sagar1.password;
 | 
				
			||||||
    cout << parking_spots.size();
 | 
					    cout << parking_spots.size();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (auto i : parking_spots){
 | 
					    for (auto i : parking_spots) {
 | 
				
			||||||
        cout << "\n" << i.id << "," << i.parked_customer;
 | 
					        cout << "\n" << i.id << "," << i.parked_customer;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    populate_spots();
 | 
					    populate_spots();
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					Why is this not in query.cpp? Because somehow, it errors out when it's there.
 | 
				
			||||||
 | 
					The error message indicates it is a memory issue but I suspect it's a
 | 
				
			||||||
// vector<Park_spot> populate_spots(){
 | 
					concurrency issue. Do not move this.
 | 
				
			||||||
//         vector<Park_spot> spots;
 | 
					 */
 | 
				
			||||||
//     SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;");
 | 
					vector<Park_spot> populate_spots() {
 | 
				
			||||||
//     // query.bind(1, 2);
 | 
					    vector<Park_spot> spots;
 | 
				
			||||||
//     while (query.executeStep()) {
 | 
					    SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;");
 | 
				
			||||||
//         int id = query.getColumn(0);
 | 
					    // query.bind(1, 2);
 | 
				
			||||||
//         int taken = query.getColumn(1);
 | 
					    while (query.executeStep()) {
 | 
				
			||||||
//         int cid = query.getColumn(2);
 | 
					        int id = query.getColumn(0);
 | 
				
			||||||
//         // park_customers.push_back(query_customer_with_id(cid));
 | 
					        int taken = query.getColumn(1);
 | 
				
			||||||
//         spots.push_back({id, taken, cid});
 | 
					        int cid = query.getColumn(2);
 | 
				
			||||||
//     }
 | 
					        // park_customers.push_back(query_customer_with_id(cid));
 | 
				
			||||||
//     return spots;
 | 
					        spots.push_back({id, taken, cid});
 | 
				
			||||||
// }
 | 
					    }
 | 
				
			||||||
 | 
					    return spots;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user