parent
f321e5f397
commit
c4db7f3de5
10 changed files with 489 additions and 2 deletions
Binary file not shown.
@ -1 +1 @@ |
||||
ECHO 处于打开状态。 |
||||
# API |
@ -0,0 +1,60 @@ |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef __CAR_H__ |
||||
#define __CAR_H__ |
||||
|
||||
#include <iostream> |
||||
#include <vector> |
||||
#include <string> |
||||
#include "../lib/ovo.h" |
||||
|
||||
|
||||
using namespace std; |
||||
|
||||
class Car{ |
||||
|
||||
public: |
||||
Car(const string& licenseNum, const string& type){ |
||||
this->_d["id"] = licenseNum; |
||||
this->_d["type"] = type; |
||||
this->_d["plot"] = "null"; |
||||
this->_d["LastInTime"] = "null"; |
||||
this->_d["LastOutTime"] = "null"; |
||||
}; |
||||
|
||||
Car(const string& licenseNum){ |
||||
|
||||
this->_d = db.getData(licenseNum); |
||||
}; |
||||
|
||||
~Car(){ |
||||
|
||||
this->_d.classify(); |
||||
db.pushData(this->_d["id"], this->_d); |
||||
}; |
||||
|
||||
inline string getID(){ |
||||
return this->_d["id"]; |
||||
}; |
||||
|
||||
inline string getType(){ |
||||
return this->_d["type"]; |
||||
}; |
||||
|
||||
inline string getPlot(){ |
||||
return this->_d["plot"]; |
||||
}; |
||||
|
||||
|
||||
private: |
||||
ovo::data _d; |
||||
ovo::db db; |
||||
|
||||
|
||||
}; |
||||
|
||||
|
||||
#endif //__CAR_H__
|
@ -1 +1,34 @@ |
||||
ECHO 处于打开状态。 |
||||
#include <iostream> |
||||
#include <vector> |
||||
#include <map> |
||||
#include "park.h" |
||||
|
||||
using namespace std; |
||||
|
||||
int main(int argc, char const *argv[]) |
||||
{ |
||||
|
||||
Park p; |
||||
|
||||
cout << p.isExist(); |
||||
|
||||
std::vector<map<string, int>> v; |
||||
|
||||
map<string, int> m; |
||||
|
||||
m["Bycycle"] = 5; |
||||
m["Cars"] = 2; |
||||
|
||||
v.push_back(m); |
||||
|
||||
m["Carsss"] = 99; |
||||
v.push_back(m); |
||||
|
||||
//p.ini(v);
|
||||
|
||||
//cout << p.checkType("Cadrs");
|
||||
|
||||
cout << p.getPlots(1).size(); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,304 @@ |
||||
|
||||
|
||||
#ifndef __PARK_H__ |
||||
#define __PARK_H__ |
||||
|
||||
#include <iostream> |
||||
#include <vector> |
||||
#include <string> |
||||
#include <map> |
||||
#include <thread> |
||||
#include "../lib/ovo.h" |
||||
|
||||
#include "plot.h" |
||||
#include "car.h" |
||||
|
||||
const string g_ParkID = "EEE102AS4"; |
||||
|
||||
using namespace std; |
||||
|
||||
class Park{ |
||||
|
||||
public: |
||||
Park(){ |
||||
|
||||
this->_threadFinished = true; |
||||
|
||||
this->_d = db.getData(g_ParkID); |
||||
if(!this->isExist()) return ; |
||||
|
||||
this->_threadFinished = false; |
||||
|
||||
this->_t = new std::thread([&]{ |
||||
|
||||
this->_plotsList = db.getData(this->_d["plotsList"]); |
||||
this->_carsList = db.getData(this->_d["carsList"]); |
||||
|
||||
this->_plotsList.forEach([&](string first, string second){ |
||||
this->_plots.push_back(Plot(first)); |
||||
}); |
||||
|
||||
this->_carsList.forEach([&](string first, string second){ |
||||
this->_cars.push_back(Car(first)); |
||||
}); |
||||
|
||||
this->_threadFinished = true; |
||||
}); |
||||
|
||||
|
||||
}; |
||||
|
||||
|
||||
|
||||
~Park(){ |
||||
|
||||
if(!this->_threadFinished) this->_t->join(); |
||||
delete this->_t; |
||||
|
||||
this->_d.classify(); |
||||
this->_plotsList.classify(); |
||||
this->_carsList.classify(); |
||||
db.pushData(g_ParkID, this->_d); |
||||
db.pushData(this->_d["plotsList"], this->_plotsList); |
||||
db.pushData(this->_d["carsList"], this->_carsList); |
||||
}; |
||||
|
||||
void join(){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
} |
||||
|
||||
bool isExist(){ |
||||
|
||||
if(this->_d["_isExist"] == "NO"){ |
||||
return false; |
||||
} |
||||
return true; |
||||
}; |
||||
|
||||
inline int getMaxLevel(){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
return this->_levels; |
||||
} |
||||
|
||||
bool checkType(const string& type){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
if(find(this->_types.begin(), this->_types.end(), type) == this->_types.end()){ |
||||
return false; |
||||
} |
||||
return true; |
||||
}; |
||||
|
||||
std::vector<Plot> getPlots(){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
return this->_plots; |
||||
}; |
||||
|
||||
std::vector<Plot> getPlots(const int& level){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
int t = time(NULL); |
||||
std::vector<Plot> v; |
||||
for(auto i : this->_plots){ |
||||
if(i.getLevel() == level){ |
||||
v.push_back(i); |
||||
} |
||||
} |
||||
cout << endl << time(NULL) - t << endl; |
||||
return v; |
||||
}; |
||||
|
||||
std::vector<Plot> getPlots(const string& type){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
int t = time(NULL); |
||||
std::vector<Plot> v; |
||||
for(auto i : this->_plots){ |
||||
if(i.getType() == type){ |
||||
v.push_back(i); |
||||
} |
||||
} |
||||
cout << endl << time(NULL) - t << endl; |
||||
return v; |
||||
}; |
||||
|
||||
std::vector<Plot> getPlots(const int& level, const string& type){ |
||||
return getPlots(type, level); |
||||
} |
||||
|
||||
std::vector<Plot> getPlots(const string& type, const int& level){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
int t = time(NULL); |
||||
std::vector<Plot> v; |
||||
for(auto i : this->_plots){ |
||||
if(i.getLevel() == level && i.getType() == type){ |
||||
v.push_back(i); |
||||
} |
||||
} |
||||
cout << endl << time(NULL) - t << endl; |
||||
return v; |
||||
}; |
||||
|
||||
Plot getPlot(Car& car){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
int t = time(NULL); |
||||
if(car.getPlot() == "null") throw "Park::getPlots::Plot Not Exist!!!"; |
||||
for(auto i : this->_plots){ |
||||
if(i.getID() == car.getPlot()){ |
||||
return i; |
||||
} |
||||
} |
||||
cout << endl << time(NULL) - t << endl; |
||||
return Plot("null", "null"); |
||||
}; |
||||
|
||||
std::vector<Car> getCars(){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
return this->_cars; |
||||
}; |
||||
|
||||
std::vector<Car> getCars(const int& level){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
int t = time(NULL); |
||||
std::vector<Car> v; |
||||
for(auto i : this->_plots){ |
||||
if(i.getLevel() == level && i.getCar() != "null"){ |
||||
for(auto ii : this->_cars){ |
||||
if(ii.getID() == i.getCar()){ |
||||
v.push_back(ii); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
cout << endl << time(NULL) - t << endl; |
||||
return v; |
||||
}; |
||||
|
||||
std::vector<Car> getCars(const string& type){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
int t = time(NULL); |
||||
std::vector<Car> v; |
||||
for(auto i : this->_cars){ |
||||
if(i.getType() == type){ |
||||
v.push_back(i); |
||||
} |
||||
} |
||||
cout << endl << time(NULL) - t << endl; |
||||
return v; |
||||
}; |
||||
|
||||
std::vector<Car> getCars(const int& level, const string& type){ |
||||
return getCars(type, level); |
||||
} |
||||
|
||||
std::vector<Car> getCars(const string& type, const int& level){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
int t = time(NULL); |
||||
std::vector<Car> v, v1, v2; |
||||
|
||||
v1 = this->getCars(type); |
||||
v2 = this->getCars(level); |
||||
|
||||
/* 待实现 */ |
||||
|
||||
cout << endl << time(NULL) - t << endl; |
||||
return v; |
||||
}; |
||||
|
||||
Car getCar(Plot& p){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
return Car(p.getCar()); |
||||
} |
||||
|
||||
void checkIn(const string& licenseNum, const string& type){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
|
||||
if(!this->checkType(type)) throw "Park::checkIn::Wrong Type!!"; |
||||
Car c = Car(licenseNum, type); |
||||
|
||||
this->_cars.push_back(c); |
||||
this->_carsList[licenseNum] = time(NULL); |
||||
}; |
||||
|
||||
Car checkIn(const string& licenseNum, const string& type, const int& level){ |
||||
if(!this->_threadFinished) this->_t->join(); |
||||
|
||||
if(!this->checkType(type)) throw "Park::checkIn::Wrong Type!!"; |
||||
Car c = Car(licenseNum, type); |
||||
this->_cars.push_back(c); |
||||
this->_carsList[licenseNum] = time(NULL); |
||||
return c; |
||||
}; |
||||
|
||||
|
||||
void ini(std::vector<std::map<string, int>>& v){ |
||||
|
||||
if(!this->_threadFinished) this->_t->join(); |
||||
|
||||
this->_d.clear(); |
||||
this->_getTypes(v); |
||||
this->_levels = v.size(); |
||||
this->_d["id"] = g_ParkID; |
||||
this->_d["carsList"] = m.randStr(); |
||||
this->_d["plotsList"] = m.randStr(); |
||||
this->_d["levels"] = this->_levels; |
||||
this->_d["types"] = ""; |
||||
for(string i : this->_types){ |
||||
|
||||
this->_d["types"] += i + "|||$$|||"; |
||||
} |
||||
this->_setupPlots(v); |
||||
for(Plot i : this->_plots){ |
||||
|
||||
this->_plotsList[i.getID()] = time(NULL); |
||||
} |
||||
|
||||
}; |
||||
|
||||
|
||||
//private:
|
||||
ovo::data _d, _carsList, _plotsList; |
||||
std::vector<string> _types; |
||||
unsigned int _levels; |
||||
ovo::math m; |
||||
ovo::String S; |
||||
ovo::db db; |
||||
std::vector<Plot> _plots; |
||||
std::vector<Car> _cars; |
||||
std::thread *_t; |
||||
bool _threadFinished; |
||||
|
||||
void _getTypes(std::vector<std::map<string, int>>& v){ |
||||
|
||||
this->_types.clear(); //清空vec
|
||||
|
||||
for(auto i : v){ |
||||
for(auto ii : i){ |
||||
if(find(this->_types.begin(), this->_types.end(), ii.first) == this->_types.end()){ |
||||
|
||||
this->_types.push_back(ii.first); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
|
||||
void _setupPlots(std::vector<std::map<string, int>>& v){ |
||||
|
||||
for(unsigned int i = 0; i < v.size(); i ++){ |
||||
|
||||
for(auto ii : v[i]){ |
||||
|
||||
for(int iii = 0; iii < ii.second; iii ++){ |
||||
this->_plots.push_back(Plot(m.randStr(), i, ii.first)); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
|
||||
|
||||
|
||||
}; |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //__PARK_H__
|
@ -0,0 +1,89 @@ |
||||
|
||||
|
||||
#ifndef __PLOT_H__ |
||||
#define __PLOT_H__ |
||||
|
||||
#include <iostream> |
||||
#include <vector> |
||||
#include <string> |
||||
#include <ctime> |
||||
#include <cstdlib> |
||||
#include <cmath> |
||||
#include "../lib/ovo.h" |
||||
|
||||
using namespace std; |
||||
|
||||
class Plot{ |
||||
|
||||
public: |
||||
Plot(const string& id, const unsigned int& level, const string& type){ |
||||
this->_d["id"] = id; |
||||
this->_d["level"] = to_string(level); |
||||
this->_d["type"] = type; |
||||
this->_d["car"] = "null"; |
||||
this->_d["LastOperateTime"] = time(NULL); |
||||
this->_d["CreatedTime"] = time(NULL); |
||||
this->_isExist = true; |
||||
}; |
||||
|
||||
Plot(const string& id){ |
||||
|
||||
this->_d = db.getData(id); |
||||
if(this->_d["_isExist"] == "NO") throw "Plot::Recover Data From NOTHING!!!"; |
||||
this->_d.clear("_isExist"); |
||||
this->_isExist = true; |
||||
}; |
||||
|
||||
Plot(const string& id, const string& isExist){ |
||||
|
||||
this->_isExist = false; |
||||
}; |
||||
|
||||
~Plot(){ |
||||
|
||||
this->_d.classify(); |
||||
db.pushData(this->_d["id"], this->_d); |
||||
}; |
||||
|
||||
inline isExist(){ |
||||
return this->_isExist; |
||||
}; |
||||
|
||||
inline string getID(){ |
||||
return this->_d["id"]; |
||||
}; |
||||
|
||||
inline int getLevel(){ |
||||
return atoi(this->_d["level"].c_str()); |
||||
}; |
||||
|
||||
inline string getType(){ |
||||
return this->_d["type"]; |
||||
}; |
||||
|
||||
inline string getCar(){ |
||||
return this->_d["car"]; |
||||
}; |
||||
|
||||
inline bool isOccupied(){ |
||||
return (this->_d["car"] == "null") ? false : true; |
||||
}; |
||||
|
||||
inline void updateLevel(const unsigned int& level){ |
||||
this->_d["level"] = to_string(level); |
||||
}; |
||||
|
||||
inline void updateType(const string& type){ |
||||
this->_d["type"] = type; |
||||
}; |
||||
|
||||
private: |
||||
ovo::data _d; |
||||
ovo::db db; |
||||
bool _isExist; |
||||
|
||||
|
||||
}; |
||||
|
||||
|
||||
#endif //__PLOT_H__
|
Loading…
Reference in new issue