still no clue
This commit is contained in:
parent
5fa84e866f
commit
c6ce3c821f
@ -7,8 +7,8 @@ Park_spot::Park_spot()
|
|||||||
save_db();
|
save_db();
|
||||||
}
|
}
|
||||||
|
|
||||||
Park_spot::Park_spot(Customer* parked_, int id_, bool taken_)
|
Park_spot::Park_spot(int id_, bool taken_, Customer* parked_)
|
||||||
: parked{nullptr},
|
: parked{parked_},
|
||||||
id{id_},
|
id{id_},
|
||||||
taken{taken_} // TODO: think about how init parked?
|
taken{taken_} // TODO: think about how init parked?
|
||||||
{}
|
{}
|
||||||
|
37
Query.cpp
37
Query.cpp
@ -25,6 +25,10 @@ vector<Park_time> query_parktimes_for_customer(int cid) {
|
|||||||
return park_times;
|
return park_times;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------- customers
|
||||||
|
|
||||||
|
|
||||||
vector<Customer> query_customer_with_name(string name) {
|
vector<Customer> query_customer_with_name(string name) {
|
||||||
/*
|
/*
|
||||||
We use this instead of plain customers because:
|
We use this instead of plain customers because:
|
||||||
@ -71,6 +75,22 @@ Customer query_customer_with_id(int id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Customer* get_customer_ptr_for_parkspot(int id) {
|
||||||
|
if (!id) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < park_customers.size(); i++) {
|
||||||
|
if (park_customers[i].id == id) {
|
||||||
|
|
||||||
|
return &park_customers[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -------------- paroking spots
|
||||||
|
|
||||||
void query_all_parking_spots() {
|
void query_all_parking_spots() {
|
||||||
SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > ?;");
|
SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > ?;");
|
||||||
query.bind(1, 0);
|
query.bind(1, 0);
|
||||||
@ -79,20 +99,9 @@ void query_all_parking_spots() {
|
|||||||
int taken = query.getColumn(1);
|
int taken = query.getColumn(1);
|
||||||
int cid = query.getColumn(2);
|
int cid = query.getColumn(2);
|
||||||
park_customers.push_back(query_customer_with_id(cid));
|
park_customers.push_back(query_customer_with_id(cid));
|
||||||
parking_spots.push_back(
|
parking_spots.push_back({id, taken, get_customer_ptr_for_parkspot(cid)});
|
||||||
Park_spot{get_customer_ptr_for_parkspot(cid), id, bool(taken)});
|
// parking_spots.push_back(temp);
|
||||||
}
|
}
|
||||||
|
cout << "WUT?";
|
||||||
}
|
}
|
||||||
|
|
||||||
Customer* get_customer_ptr_for_parkspot(int id) {
|
|
||||||
if (!id) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < park_customers.size(); i++) {
|
|
||||||
if (park_customers[i].id == id) {
|
|
||||||
|
|
||||||
return &park_customers[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "Park_time.h"
|
#include "Park_time.h"
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
@ -22,7 +23,6 @@ park_time object. Voegt het toe aan een vector.
|
|||||||
|
|
||||||
class Customer {
|
class Customer {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
string name;
|
string name;
|
||||||
string password;
|
string password;
|
||||||
@ -38,17 +38,18 @@ class Customer {
|
|||||||
void delete_db();
|
void delete_db();
|
||||||
|
|
||||||
void gen_monthly(); // remove, make it a function in data
|
void gen_monthly(); // remove, make it a function in data
|
||||||
|
Verhicle_type verhicle;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Verhicle_type verhicle;
|
|
||||||
vector<Park_time> park_instances;
|
vector<Park_time> park_instances;
|
||||||
void save_db();
|
void save_db();
|
||||||
int auto_increment_db();
|
int auto_increment_db();
|
||||||
};
|
};
|
||||||
|
|
||||||
static vector<Customer> park_customers; // save the customers that are parked in here
|
static vector<Customer>
|
||||||
|
park_customers; // save the customers that are parked in here
|
||||||
// parking_spot uses pointers, so it's better to save the parked customers here
|
// parking_spot uses pointers, so it's better to save the parked customers here
|
||||||
// where we know they'll be destroyed at the end of this scope, instead of too early
|
// where we know they'll be destroyed at the end of this scope, instead of too
|
||||||
// and end up with dangling pointers
|
// early and end up with dangling pointers
|
||||||
|
|
||||||
#endif // CUSTOMER_H
|
#endif // CUSTOMER_H
|
@ -16,7 +16,7 @@ class Park_spot {
|
|||||||
bool taken;
|
bool taken;
|
||||||
Customer* parked;
|
Customer* parked;
|
||||||
Park_spot();
|
Park_spot();
|
||||||
Park_spot(Customer* parked_, int id_, bool taken_);
|
Park_spot(int id_, bool taken_, Customer* parked_);
|
||||||
void clock(Customer* c_customer);
|
void clock(Customer* c_customer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -26,4 +26,4 @@ class Park_spot {
|
|||||||
int auto_increment_db();
|
int auto_increment_db();
|
||||||
};
|
};
|
||||||
|
|
||||||
static vector<Park_spot> parking_spots; // to save the parking spots in memory
|
static vector<Park_spot> parking_spots {{0,0,0}}; // to save the parking spots in memory
|
54
main.cpp
54
main.cpp
@ -3,6 +3,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Code strucure like this:
|
Code strucure like this:
|
||||||
class declarations zijn in /headers/class_naam.h, en definitions van de member
|
class declarations zijn in /headers/class_naam.h, en definitions van de member
|
||||||
@ -18,9 +19,6 @@ record die zegt dat een customer voor x tijd geparkeert heeft bij spot x, enz.
|
|||||||
De client clockt in en uit bij een spot.
|
De client clockt in en uit bij een spot.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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.
|
||||||
@ -31,27 +29,43 @@ a wait function where 1 sec represents 1 hour irl.
|
|||||||
|
|
||||||
Customer* get_customer_ptr_for_parkspot(int id);
|
Customer* get_customer_ptr_for_parkspot(int id);
|
||||||
|
|
||||||
int main() {
|
void debug(Customer c) {
|
||||||
query_all_parking_spots();
|
cout << "\n-----------" << &c << "-------------";
|
||||||
|
cout << "\nid: " << c.id << "\nname:" << c.name
|
||||||
|
<< "\ncar:" << int(c.verhicle);
|
||||||
|
cout << "\n------------------------";
|
||||||
|
}
|
||||||
|
|
||||||
|
void debug(Park_spot p) {
|
||||||
|
cout << "\n------------" << &p << "\nid:" << p.id << "\ntaken: " << p.taken
|
||||||
|
<< "\n customer:" << p.parked << "\n------------------";
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
Customer p0 = query_customer_with_name("Shaquile")[0];
|
Customer p0 = query_customer_with_name("Shaquile")[0];
|
||||||
Customer p1 = query_customer_with_name("Sagar Ramsaransing")[0];
|
Customer p1 = query_customer_with_name("Sagar Ramsaransing")[0];
|
||||||
Customer p2 = query_customer_with_name("Joshua karto")[0];
|
Customer p2 = query_customer_with_name("Joshua karto")[0];
|
||||||
Customer p3 = query_customer_with_name("Stefan udit")[0];
|
Customer p3 = query_customer_with_name("Stefan udit")[0];
|
||||||
|
query_all_parking_spots();
|
||||||
parking_spots[2].clock(&p1);
|
// debug(p1);
|
||||||
Wait(2);
|
// debug(p0);
|
||||||
parking_spots[2].clock(&p1);
|
// debug(p2);
|
||||||
Wait(1);
|
// debug(p3);
|
||||||
parking_spots[0].clock(&p2);
|
cout << parking_spots.size();
|
||||||
Wait(1);
|
for (auto i: park_customers){
|
||||||
parking_spots[1].clock(&p3);
|
debug(i);
|
||||||
Wait(1);
|
|
||||||
parking_spots[0].clock(&p2);
|
|
||||||
parking_spots[1].clock(&p3);
|
|
||||||
Wait(1);
|
|
||||||
parking_spots[1].clock(&p3);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parking_spots[2].clock(&p1);
|
||||||
|
// Wait(2);
|
||||||
|
// parking_spots[2].clock(&p1);
|
||||||
|
// Wait(1);
|
||||||
|
// parking_spots[0].clock(&p2);
|
||||||
|
// Wait(1);
|
||||||
|
// parking_spots[1].clock(&p3);
|
||||||
|
// Wait(1);
|
||||||
|
// parking_spots[0].clock(&p2);
|
||||||
|
// parking_spots[1].clock(&p3);
|
||||||
|
// Wait(1);
|
||||||
|
// parking_spots[1].clock(&p3);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user