Parkmanne/headers/Park_time.h

77 lines
2.1 KiB
C
Raw Permalink Normal View History

2019-07-02 00:18:52 +00:00
#ifndef PARK_TIME_H
#define PARK_TIME_H
#pragma once
#include "data.h"
#include <chrono>
#include <ctime>
#include <iostream>
#include <string>
2019-07-08 20:57:09 +00:00
#include <thread>
2019-07-02 00:18:52 +00:00
using namespace std::chrono;
using std::cout;
2019-07-08 23:46:19 +00:00
using std::flush;
2019-07-02 00:18:52 +00:00
using std::string;
using std::to_string;
2019-07-08 23:46:19 +00:00
using std::this_thread::sleep_for;
using std::chrono::milliseconds;
2019-07-02 00:18:52 +00:00
/*
Record of who parked at what park_spot and at what time.
2019-07-02 18:40:37 +00:00
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------------------------
2019-07-08 20:57:09 +00:00
start and end are time points representing when someone clocks in and out. they're from the chrono
namespace.
2019-07-02 18:40:37 +00:00
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.
2019-07-08 20:57:09 +00:00
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.
2019-07-02 18:40:37 +00:00
2019-07-02 00:18:52 +00:00
*/
class Park_time {
public:
Park_time(int c_id, int s_id);
2019-07-08 20:57:09 +00:00
Park_time(int id_, int customer_id_, int spot_id_, int start_, int duration_);
2019-07-02 00:18:52 +00:00
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
};
2019-07-08 23:46:19 +00:00
// test function
2019-07-06 16:32:00 +00:00
void Wait(int sec);
2019-07-08 23:46:19 +00:00
// function that slowly outputs each character one by one
void text_animation(const string& text, unsigned int pause_time);
#endif // Park_time