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 assert (_airracServiceContext != NULL);
175 stdair::STDAIR_Service& lSTDAIR_Service =
176 lAIRRAC_ServiceContext.getSTDAIR_Service();
177 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
187 if (_airracServiceContext == NULL) {
188 throw stdair::NonInitialisedServiceException (
"The AirRAC service has not"
189 " been initialised");
191 assert (_airracServiceContext != NULL);
196 const bool doesOwnStdairService =
197 lAIRRAC_ServiceContext.getOwnStdairServiceFlag();
200 stdair::STDAIR_Service& lSTDAIR_Service =
201 lAIRRAC_ServiceContext.getSTDAIR_Service();
207 if (doesOwnStdairService ==
true) {
209 lSTDAIR_Service.buildSampleBom();
234 if (_airracServiceContext == NULL) {
235 throw stdair::NonInitialisedServiceException (
"The AirRAC service has not"
236 " been initialised");
238 assert (_airracServiceContext != NULL);
243 stdair::STDAIR_Service& lSTDAIR_Service =
244 lAIRRAC_ServiceContext.getSTDAIR_Service();
247 lSTDAIR_Service.buildSampleTravelSolutions (ioTravelSolutionList);
254 if (_airracServiceContext == NULL) {
255 throw stdair::NonInitialisedServiceException (
"The Airrac service "
256 "has not been initialised");
258 assert (_airracServiceContext != NULL);
263 stdair::STDAIR_Service& lSTDAIR_Service =
264 lAIRRAC_ServiceContext.getSTDAIR_Service();
268 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
271 std::ostringstream oCSVStr;
272 stdair::BomDisplay::csvSimFQTAirRACDisplay (oCSVStr, lBomRoot);
273 return oCSVStr.str();
279 csvDisplay (
const stdair::TravelSolutionList_T& ioTravelSolutionList)
const {
282 if (_airracServiceContext == NULL) {
283 throw stdair::NonInitialisedServiceException (
"The AirRAC service has not"
284 " been initialised");
286 assert (_airracServiceContext != NULL);
292 stdair::STDAIR_Service& lSTDAIR_Service =
293 lAIRRAC_ServiceContext.getSTDAIR_Service();
296 return lSTDAIR_Service.csvDisplay (ioTravelSolutionList);
304 if (_airracServiceContext == NULL) {
305 throw stdair::NonInitialisedServiceException (
"The AirRAC service has not"
306 " been initialised");
308 assert (_airracServiceContext != NULL);
312 stdair::STDAIR_Service& lSTDAIR_Service =
313 lAIRRAC_ServiceContext.getSTDAIR_Service();
317 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
321 stdair::BasChronometer lYieldChronometer;
322 lYieldChronometer.start();
323 YieldManager::calculateYield (ioTravelSolutionList, lBomRoot);
324 const double lYieldMeasure = lYieldChronometer.elapsed();
327 STDAIR_LOG_DEBUG (
"Yield calculation: " << lYieldMeasure <<
" - "
328 << lAIRRAC_ServiceContext.display());
334 assert (_airracServiceContext != NULL);
338 stdair::STDAIR_Service& lSTDAIR_Service =
339 lAIRRAC_ServiceContext.getSTDAIR_Service();
343 stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();