-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtripMgr.cpp
35 lines (28 loc) · 1.09 KB
/
tripMgr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "tripMgr.hpp"
TripMgr* TripMgr::tripMgrInstance = nullptr;
mutex TripMgr::mtx;
TripMgr* TripMgr::getTripMgr() {
if (tripMgrInstance == nullptr) {
mtx.lock();
if (tripMgrInstance == nullptr) {
tripMgrInstance = new TripMgr();
}
mtx.unlock();
}
return tripMgrInstance;
}
void TripMgr::CreateTrip(Rider* pRider, Location* pSrcLoc, Location* pDstLoc) {
TripMetaData* metaData = new TripMetaData(pSrcLoc, pDstLoc, pRider->getRating());
StrategyMgr* strategyMgr = StrategyMgr::getStrategyMgr();
PricingStrategy* pricingStrategy = strategyMgr->determinePricingStrategy(metaData);
DriverMatchingStrategy* driverMatchingStrategy = strategyMgr->determineMatchingStrategy(metaData);
Driver* driver = driverMatchingStrategy->matchDriver(metaData);
double tripPrice = pricingStrategy->calculatePrice(metaData);
Trip* trip = new Trip(pRider, driver, pSrcLoc, pDstLoc, tripPrice, pricingStrategy, driverMatchingStrategy);
int tripId = trip->getTripId();
tripsInfo[tripId] = trip;
tripsMetaDataInfo[tripId] = metaData;
}
unordered_map<int, Trip*> TripMgr::getTripsMap() {
return tripsInfo;
}