commenting and doing some cleaning

This commit is contained in:
MassiveAtoms
2019-07-23 11:17:55 -03:00
parent ec089c66e7
commit 16a20ef6d3
13 changed files with 66 additions and 129 deletions

View File

@@ -11,10 +11,11 @@ using std::vector;
/*
enum classes make it easy to represent categories.
So you can use something like Vehicle_type::car instead of 2. but under the
hood, it's still an int. This is here so you won't have to have global variables
for these categories, or worse, use magic numbers in the code.
So you can use something like Vehicle_type::twowheeler instead of 2 in code, so you know it's that.
but under the hood, it's still an int.
This is so you don't have to polute the global namespace with unnecesary variables.
enum classes do not permit implicit conversion between int and the enum class, and are in the
Enumclass:: scope in contrast to plain enums. https://en.cppreference.com/w/cpp/language/enum
*/
enum class Vehicle_type { twoweeler = 1, fourweeler = 2 };
@@ -22,15 +23,9 @@ enum class Vehicle_type { twoweeler = 1, fourweeler = 2 };
Customer constructors do the same stuff as all the other constructors.
clock_in and out create and modify park_time objects and store them to
park_instances. Technically, now that we have a working db, we don't need it.
TODO: fix this.
gen_monthly just prints out all the park_time objects in park_instances.
It should (and can safely) be removed, but it's here as a quick example of
report generation It has no logic to speak of that only generates report of
ptime objects of this month.
TODO: remove when have seperate report generation functions.
save, update, delete and auto increment are the same as in park_time.
It might have some performance benefits to keeping it, though.
TODO: test or fix this.
save, update, delete and auto increment are the same as in park_time but for customers.
*/
class Customer {

View File

@@ -6,11 +6,12 @@
/*
db representation:
int id not null
bool taken not null
int customer_id (null) (many to one, foreign key, whatever)
int taken // the library seems to be having problems with bools as types.
int customer_id (nullable)
Represents a parkspot.
Has the same kind of db functions, same kind of constructors as previous classes.
Dit representeert een parkeerplaats. Het heeft als internal state alleen dat t
bezet is of niet.
*/
class Park_spot {

View File

@@ -6,10 +6,9 @@
#include <chrono>
#include <ctime>
#include <iostream>
#include <string>
#include <thread>
using namespace std::chrono;
using std::cout;
using std::flush;
@@ -44,6 +43,12 @@ auto_increment pulls the highest id stored in the db, to be used in the construc
start_to_int() is used to convert the start timepoint to an integer that can be saved in the
database SQL datetime and chrono datetime don't seem the most compatible.
We choose chrono because it's the recomended way from c++11 onwards, and is more typesafe and
acurate https://stackoverflow.com/questions/36095323/what-is-the-difference-between-chrono-and-ctime
but, it does not have parsing and formatting for human readable time.
It will get that in c++20, but that's a little too late for us :(
So for now, conversion to/from ctime objects it is....
*/
class Park_time {
@@ -67,9 +72,6 @@ class Park_time {
int start_to_int(); // helper
};
// test function
void Wait(int sec);
// function that slowly outputs each character one by one
void text_animation(const string& text, unsigned int pause_time);

View File

@@ -3,7 +3,8 @@
#pragma once
#include "Park_spot.h"
#include <iomanip>
#include <iomanip>
using std::pair;
/*these are the functions that search the database and create objects from it.
@@ -12,49 +13,21 @@ query_parktimes_for_customer searches for the parktimes that are needed in
customer initialisaiton. generally, i see no use outside of that.
query_customer_with_name searches for customer data by name.
NOTE: query_customer_with_name has been removed, nothing is using it
query_customer_with_id does what the above does, but with id.
query_parkspot_with_id does what the above do, but with a vector and not to the db.
populate_spots is used to query for all the park_spots and return them as
objects.
populate_spots is used to query for all the park_spots in db and return them in a vector.
We can keep that in memory to reduce calls to the db, but increasing the memory footprint of this
program
The design desision to use vector<T> instead of <T> is for the following
reasons:
1. some of these can potentially return more than one object. For example, 2
customers who have the same name.
2. I have no clue how many of you have done error handling in c++
(try/catch/finally).
Ya boi is nice and doesn't want to bombard you with more new concepts than needed.
so now you'd do
vector<Customer> test = query_customer_with_name("Testman");
if (!test.size()) {print no customers found, do stuff}
else if (test.size() > 1) { do stuff to get the right one if you only need one
}
instead of
try {
customer test = query_customer_with_name("Testman");
}
catch(someException.probablycalled_not_found) {do_Stuff};
catch(...) {
do stuff
}
finally{
do more stuff
}
3. Ya boi needs to brush up on how to create custom exceptions class, and it will complicate code
furhter.
reports_from_x functions query the db for parktimes with various conditions
current_status_parkspots takes in a vector and outputs the status of them
*/
vector<Park_time> query_parktimes_for_customer(int cid);
vector<Customer> query_customer_with_name(string name);
Customer query_customer_with_id(int id);
Park_spot query_parkspot_with_id(int id, vector<Park_spot>& parkspots);
int query_role_customer(int id);

View File

@@ -9,7 +9,10 @@ namespace data {
/*
start_db is the function that opens the database, and
if the necesary tables are not there, creates them.
db is the database, and is static to avoid multiple redefinition errors.
db is the database, and is static to avoid multiple redefinition errors,
because multiple cpp files import this header.
TODO: remove this namespace, we didn't add more functions here like originally planned.
*/
SQLite::Database start_db();
static SQLite::Database db = start_db();

View File

@@ -10,11 +10,14 @@
using std::string;
/*
hash_password takes the password, and encrypts it. This needs to be done,
because storing passwords in plaintext is BAD!
because storing passwords in plaintext is BAD, no matter if it's just for a school project!
verify_password takes in a password and the hashed password, and then does magic encryption
stuff(no, not really. It basically hashes the password with the same salt and other parameters) and
to see if the password stored and the given password match.
stuff(no, not really. It basically hashes the password with the same salt and other parameters, but
that's not that important to know) and to see if the password stored and the given password match.
call these whenever you are working with passwords.
so to check if passwords match, use something like verifypassword(customer.password,
someplainpassword) see libsodium documentation for more info
*/
string hash_password(string password);