76 lines
2.4 KiB
C++
76 lines
2.4 KiB
C++
#ifndef PARK_TIME_H
|
|
#define PARK_TIME_H
|
|
#pragma once
|
|
|
|
#include "data.h"
|
|
|
|
#include <chrono>
|
|
#include <ctime>
|
|
#include <thread>
|
|
|
|
using namespace std::chrono;
|
|
using std::cout;
|
|
using std::flush;
|
|
using std::to_string;
|
|
using std::this_thread::sleep_for;
|
|
/*
|
|
|
|
|
|
Record of who parked at what park_spot and at what time.
|
|
public interface-------------------------------------------
|
|
|
|
The constructors. one for creating new customers, the other one used by the
|
|
query functions to construct the object from information stored in the database.
|
|
|
|
clock_out is the function that gets called from customer.clock_out().
|
|
It verifies that the customer is clocking out at the correct parkspot, and saves
|
|
the current time of clocking out in end. It also calculates duration so it
|
|
doesn't have to be calculated more than once.
|
|
|
|
operator<< is << overload, can(should) be used for report generation.
|
|
|
|
|
|
// implementation stuff------------------------
|
|
start and end are time points representing when someone clocks in and out. they're from the chrono
|
|
namespace.
|
|
|
|
save and update save and update info in the database.
|
|
auto_increment pulls the highest id stored in the db, to be used in the constructor.
|
|
|
|
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 {
|
|
public:
|
|
Park_time(int c_id, int s_id);
|
|
Park_time(int id_, int customer_id_, int spot_id_, int start_, int duration_);
|
|
int id;
|
|
int customer_id;
|
|
int spot_id;
|
|
int duration;
|
|
|
|
void clock_out(int c_id, int s_id);
|
|
friend std::ostream& operator<<(std::ostream& os, const Park_time& pt);
|
|
|
|
private:
|
|
high_resolution_clock::time_point start;
|
|
high_resolution_clock::time_point end;
|
|
void save_db();
|
|
void update_db();
|
|
int auto_increment_db(); // helper
|
|
int start_to_int(); // helper
|
|
};
|
|
|
|
// function that slowly outputs each character one by one
|
|
void text_animation(const string& text, unsigned int pause_time);
|
|
|
|
#endif // Park_time
|