code compiles, doesnt run tho

This commit is contained in:
MassiveAtoms 2019-06-24 21:42:08 -03:00
parent 9a10e33279
commit ecbf41ee07
6 changed files with 117 additions and 118 deletions

9
.clang-format Normal file
View File

@ -0,0 +1,9 @@
BasedOnStyle: LLVM
IndentWidth: 4
#-------------
Language: Cpp
PointerAlignment: Left
ColumnLimit: 160

50
db.cpp
View File

@ -1,21 +1,55 @@
#include "headers/db.h"
namespace db
{
namespace data {
char* error_message; // no clue, prolly error message
static int callback(void* NotUsed, int argc, char** argv, char** azColName) {
int i;
for(i=0; i<argc; i++)
{
for (i = 0; i < argc; i++) {
std::cout << azColName[i] << " = " << (argv[i] ? argv[i] : "NULL") << "\n";
}
std::cout << "\n";
return 0;
}
// sqlite3_close(db);
void open_db(sqlite3* db) {
int status = sqlite3_open("database.sqlite", &db);
if (!status) {
std::cout << "Can't open database: " << sqlite3_errmsg(db) << "\n";
}
}
void initialize_db(sqlite3* db) {
// ugh, sqlite3_exec doesn't accept const strings, so i have to use const
// char*
const char* customer_table = "create table Customer (id int, name "
"varchar(50), card_code varchar(20), "
"verhicle int)";
const char* parkspot_table = "create table Park_spot (id int, taken boolean, customer_id int)";
const char* parktime_table = "create table Park_time (id int, customer_id int, spot_id int, start "
"real, end real, duration real)";
int success;
success = sqlite3_exec(db, customer_table, callback, 0, &error_message);
if (success != SQLITE_OK) {
std::cout << "SQL error: " << sqlite3_errmsg(db) << "\n";
sqlite3_free(error_message);
return; // TODO: error handling instead of just logging
}
success = sqlite3_exec(db, parkspot_table, callback, 0, &error_message);
if (success != SQLITE_OK) {
std::cout << "SQL error: " << sqlite3_errmsg(db) << "\n";
sqlite3_free(error_message);
return; // TODO: error handling instead of just logging
}
success = sqlite3_exec(db, parktime_table, callback, 0, &error_message);
if (success != SQLITE_OK) {
std::cout << "SQL error: " << sqlite3_errmsg(db) << "\n";
sqlite3_free(error_message);
return; // TODO: error handling instead of just logging
}
}
} // namespace data

View File

@ -2,12 +2,12 @@
#define CUSTOMER_H
#pragma once
#include <vector>
#include <string>
#include "Park_time.h"
#include <string>
#include <vector>
using std::vector;
using std::string;
using std::vector;
// enum type is basically een manier om categories te representen als een integer in the background, maar om t in code
// aan te geven als de actual category.
@ -45,9 +45,6 @@ private:
Verhicle_type verhicle;
vector<Park_time> park_instances;
string gen_cardcode();
};
#endif // CUSTOMER_H

View File

@ -1,56 +1,16 @@
#include <iostream>
#include <sqlite3.h>
#include <string>
#include <iostream>
namespace db
{
namespace data {
static int callback(void* NotUsed, int argc, char** argv, char** azColName);
sqlite3* db;
char* error_message;
void open_db(sqlite3* db_);
/*
this initializes the table in the database.
*/
void initialize_db(sqlite3* db_);
void open_db(sqlite3* db_){
int success = sqlite3_open("sqlite.db", &db);
if (!success) {
std::cout << "Can't open database: "<<sqlite3_errmsg(db)<<"\n";
}
}
// stupid lib
void initialize_db(sqlite3* db_){
// ugh, sqlite3_exec doesn't accept const strings, so i have to use const char*
const char* customer_table = "create table Customer (id int, name varchar(50), card_code varchar(20), verhicle int)";
const char* parkspot_table = "create table Park_spot (id int, taken boolean, customer_id int)";
const char* parktime_table = "create table Park_time (id int, customer_id int, spot_id int, start real, end real, duration real)";
int success;
success = sqlite3_exec(db_, customer_table, callback, 0, &error_message);
if( success!=SQLITE_OK )
{
std::cout<<"SQL error: "<<sqlite3_errmsg(db)<<"\n";
sqlite3_free(error_message);
return; // TODO: error handling instead of just logging
}
success = sqlite3_exec(db_, parkspot_table, callback, 0, &error_message);
if( success!=SQLITE_OK )
{
std::cout<<"SQL error: "<<sqlite3_errmsg(db)<<"\n";
sqlite3_free(error_message);
return; // TODO: error handling instead of just logging
}
success = sqlite3_exec(db_, parktime_table, callback, 0, &error_message);
if( success!=SQLITE_OK )
{
std::cout<<"SQL error: "<<sqlite3_errmsg(db)<<"\n";
sqlite3_free(error_message);
return; // TODO: error handling instead of just logging
}
}
}
} // namespace data

View File

@ -1,20 +1,20 @@
#include "headers/Park_spot.h"
#include "headers/db.h"
#include <iostream>
#include <thread> // to make pausing work, not sure if i need chrono, or this, or both
#include <vector>
/*
Code strucure like this:
class declarations zijn in /headers/class_naam.h, en definitions van de member functs in /class_naam.cpp
elke klas in zn eigen file omdat ik incomplete class declarations wilt tegengaan, omdat ik ze niet goed begrijp.
En header/source split om multiple definition errors tegen te gaan.
class declarations zijn in /headers/class_naam.h, en definitions van de member
functs in /class_naam.cpp elke klas in zn eigen file omdat ik incomplete class
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.
Een customer is een customer.
Park time is een object die reffereert naar parkspot en customer, basically een record die zegt dat
een customer voor x tijd geparkeert heeft bij spot x, enz.
Park time is een object die reffereert naar parkspot en customer, basically een
record die zegt dat een customer voor x tijd geparkeert heeft bij spot x, enz.
De client clockt in en uit bij een spot.
*/
@ -29,37 +29,30 @@ a wait function where 1 sec represents 1 hour irl.
using std::cout;
int main()
{
std::vector<Park_spot> spots {
1, 2, 3, 4, 5
};
int main() {
std::vector<Park_spot> spots{1, 2, 3, 4, 5};
std::vector<Customer> customers{
{ 1, "Sagar Ram", Verhicle_type::small },
{ 2, "Shaq", Verhicle_type::medium },
{ 3, "Josh", Verhicle_type::large },
{ 4, "Stefano", Verhicle_type::small }
};
{1, "Sagar Ram", Verhicle_type::small}, {2, "Shaq", Verhicle_type::medium}, {3, "Josh", Verhicle_type::large}, {4, "Stefano", Verhicle_type::small}};
spots[1].clock(&customers[3]); // stefano parks at spot 2
Wait(2);
spots[3].clock(&customers[2]); // josh parks at spot 4
Wait(1);
spots[1].clock(&customers[3]); // stefano clocks out of spot 1
Wait(5);
spots[1].clock(&customers[1]); // shaq clocks in at spot 1
Wait(6);
spots[2].clock(&customers[0]); // sagar clocks in at spot 3. what the fuck is he doing here?
Wait(2);
spots[2].clock(&customers[0]); // sagar clocks out from spot 2
Wait(3);
spots[3].clock(&customers[2]); // josh clocks out from spot 4
spots[1].clock(&customers[1]); // shaq clocks out at spot 1
// spots[1].clock(&customers[3]); // stefano parks at spot 2
// Wait(2);
// spots[3].clock(&customers[2]); // josh parks at spot 4
// Wait(1);
// spots[1].clock(&customers[3]); // stefano clocks out of spot 1
// Wait(5);
// spots[1].clock(&customers[1]); // shaq clocks in at spot 1
// Wait(6);
// spots[2].clock(&customers[0]); // sagar clocks in at spot 3. what the fuck
// // is he doing here?
// Wait(2);
// spots[2].clock(&customers[0]); // sagar clocks out from spot 2
// Wait(3);
// spots[3].clock(&customers[2]); // josh clocks out from spot 4
// spots[1].clock(&customers[1]); // shaq clocks out at spot 1
spots[2].clock(&customers[1]); // shaq clocks out at spot 3
Wait(4);
spots[2].clock(&customers[1]); // shaq clocks out at spot 2
// spots[2].clock(&customers[1]); // shaq clocks out at spot 3
// Wait(4);
// spots[2].clock(&customers[1]); // shaq clocks out at spot 2
/*
so:
@ -72,4 +65,10 @@ int main()
customers[1].gen_monthly();
customers[2].gen_monthly();
customers[3].gen_monthly();
// test
sqlite3* db;
data::open_db(db);
data::initialize_db(db);
sqlite3_close(db);
}

View File

@ -1,7 +1,7 @@
use
```
g++ main.cpp Park_time.cpp Customer.cpp Park_spot.cpp -o test.exe
g++ Park_time.cpp Customer.cpp Park_spot.cpp db.cpp main.cpp -lsqlite3 -o test.exe
```
to build the project