7 #include <boost/make_shared.hpp>
9 #include <stdair/basic/BasChronometer.hpp>
10 #include <stdair/bom/BomDisplay.hpp>
11 #include <stdair/service/Logger.hpp>
12 #include <stdair/STDAIR_Service.hpp>
24 AIRRAC_Service::AIRRAC_Service() : _airracServiceContext (NULL) {
29 AIRRAC_Service::AIRRAC_Service (
const AIRRAC_Service& iService) {
34 AIRRAC_Service::AIRRAC_Service (
const stdair::BasLogParams& iLogParams)
35 : _airracServiceContext (NULL) {
38 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
39 initStdAirService (iLogParams);
46 const bool ownStdairService =
true;
47 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
54 AIRRAC_Service::AIRRAC_Service (
const stdair::BasLogParams& iLogParams,
55 const stdair::BasDBParams& iDBParams)
56 : _airracServiceContext (NULL) {
59 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
60 initStdAirService (iLogParams, iDBParams);
67 const bool ownStdairService =
true;
68 addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
76 AIRRAC_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
77 : _airracServiceContext (NULL) {
84 const bool doesNotOwnStdairService =
false;
85 addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
98 void AIRRAC_Service::finalise() {
99 assert (_airracServiceContext != NULL);
101 _airracServiceContext->reset();
105 void AIRRAC_Service::initServiceContext() {
107 AIRRAC_ServiceContext& lAIRRAC_ServiceContext =
109 _airracServiceContext = &lAIRRAC_ServiceContext;
113 stdair::STDAIR_ServicePtr_T AIRRAC_Service::
114 initStdAirService (
const stdair::BasLogParams& iLogParams,
115 const stdair::BasDBParams& iDBParams) {
124 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
125 boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
127 return lSTDAIR_Service_ptr;
132 stdair::STDAIR_ServicePtr_T AIRRAC_Service::
133 initStdAirService (
const stdair::BasLogParams& iLogParams) {
142 stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
143 boost::make_shared<stdair::STDAIR_Service> (iLogParams);
145 return lSTDAIR_Service_ptr;
149 void AIRRAC_Service::
150 addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
151 const bool iOwnStdairService) {
154 assert (_airracServiceContext != NULL);
155 AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
158 lAIRRAC_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
163 void AIRRAC_Service::initAirracService() {
173 if (_airracServiceContext == NULL) {
174 throw stdair::NonInitialisedServiceException (
"The AirRAC service has not"
175 " been initialised");
177 assert (_airracServiceContext != NULL);
182 const bool doesOwnStdairService =
183 lAIRRAC_ServiceContext.getOwnStdairServiceFlag();
186 stdair::STDAIR_Service& lSTDAIR_Service =
187 lAIRRAC_ServiceContext.getSTDAIR_Service();
190 stdair::BomRoot& lPersistentBomRoot =
191 lSTDAIR_Service.getPersistentBomRoot();
216 if (doesOwnStdairService ==
true) {
226 if (_airracServiceContext == NULL) {
227 throw stdair::NonInitialisedServiceException (
"The AirRAC service has not"
228 " been initialised");
230 assert (_airracServiceContext != NULL);
235 const bool doesOwnStdairService =
236 lAIRRAC_ServiceContext.getOwnStdairServiceFlag();
239 stdair::STDAIR_Service& lSTDAIR_Service =
240 lAIRRAC_ServiceContext.getSTDAIR_Service();
243 stdair::BomRoot& lPersistentBomRoot =
244 lSTDAIR_Service.getPersistentBomRoot();
250 if (doesOwnStdairService ==
true) {
252 lSTDAIR_Service.buildSampleBom();
273 if (doesOwnStdairService ==
true) {
283 if (_airracServiceContext == NULL) {
284 throw stdair::NonInitialisedServiceException (
"The AirRAC service has not"
285 " been initialised");
287 assert (_airracServiceContext != NULL);
292 const bool doesOwnStdairService =
293 lAIRRAC_ServiceContext.getOwnStdairServiceFlag();
296 stdair::STDAIR_Service& lSTDAIR_Service =
297 lAIRRAC_ServiceContext.getSTDAIR_Service();
303 if (doesOwnStdairService ==
true) {
306 lSTDAIR_Service.clonePersistentBom ();
321 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
335 if (_airracServiceContext == NULL) {
336 throw stdair::NonInitialisedServiceException (
"The AirRAC service has not"
337 " been initialised");
339 assert (_airracServiceContext != NULL);
344 stdair::STDAIR_Service& lSTDAIR_Service =
345 lAIRRAC_ServiceContext.getSTDAIR_Service();
348 lSTDAIR_Service.buildSampleTravelSolutions (ioTravelSolutionList);
355 if (_airracServiceContext == NULL) {
356 throw stdair::NonInitialisedServiceException (
"The Airrac service "
357 "has not been initialised");
359 assert (_airracServiceContext != NULL);
364 stdair::STDAIR_Service& lSTDAIR_Service =
365 lAIRRAC_ServiceContext.getSTDAIR_Service();
369 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
372 std::ostringstream oCSVStr;
373 stdair::BomDisplay::csvSimFQTAirRACDisplay (oCSVStr, lBomRoot);
374 return oCSVStr.str();
380 csvDisplay (
const stdair::TravelSolutionList_T& ioTravelSolutionList)
const {
383 if (_airracServiceContext == NULL) {
384 throw stdair::NonInitialisedServiceException (
"The AirRAC service has not"
385 " been initialised");
387 assert (_airracServiceContext != NULL);
393 stdair::STDAIR_Service& lSTDAIR_Service =
394 lAIRRAC_ServiceContext.getSTDAIR_Service();
397 return lSTDAIR_Service.csvDisplay (ioTravelSolutionList);
405 if (_airracServiceContext == NULL) {
406 throw stdair::NonInitialisedServiceException (
"The AirRAC service has not"
407 " been initialised");
409 assert (_airracServiceContext != NULL);
413 stdair::STDAIR_Service& lSTDAIR_Service =
414 lAIRRAC_ServiceContext.getSTDAIR_Service();
418 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
422 stdair::BasChronometer lYieldChronometer;
423 lYieldChronometer.start();
424 YieldManager::calculateYield (ioTravelSolutionList, lBomRoot);
425 const double lYieldMeasure = lYieldChronometer.elapsed();
428 STDAIR_LOG_DEBUG (
"Yield calculation: " << lYieldMeasure <<
" - "
429 << lAIRRAC_ServiceContext.display());
435 assert (_airracServiceContext != NULL);