AirRAC Logo  1.00.0
C++ Simulated Revenue Accounting (RAC) System Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
AIRRAC_Service.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // Boost
7 #include <boost/make_shared.hpp>
8 // StdAir
9 #include <stdair/basic/BasChronometer.hpp>
10 #include <stdair/bom/BomDisplay.hpp>
11 #include <stdair/service/Logger.hpp>
12 #include <stdair/STDAIR_Service.hpp>
13 // Airrac
20 
21 namespace AIRRAC {
22 
23  // //////////////////////////////////////////////////////////////////////
24  AIRRAC_Service::AIRRAC_Service() : _airracServiceContext (NULL) {
25  assert (false);
26  }
27 
28  // //////////////////////////////////////////////////////////////////////
29  AIRRAC_Service::AIRRAC_Service (const AIRRAC_Service& iService) {
30  assert (false);
31  }
32 
33  // ////////////////////////////////////////////////////////////////////
34  AIRRAC_Service::AIRRAC_Service (const stdair::BasLogParams& iLogParams)
35  : _airracServiceContext (NULL) {
36 
37  // Initialise the STDAIR service handler
38  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
39  initStdAirService (iLogParams);
40 
41  // Initialise the service context
42  initServiceContext();
43 
44  // Add the StdAir service context to the AIRRAC service context
45  // \note AIRRAC owns the STDAIR service resources here.
46  const bool ownStdairService = true;
47  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
48 
49  // Initialise the (remaining of the) context
50  initAirracService();
51  }
52 
53  // ////////////////////////////////////////////////////////////////////
54  AIRRAC_Service::AIRRAC_Service (const stdair::BasLogParams& iLogParams,
55  const stdair::BasDBParams& iDBParams)
56  : _airracServiceContext (NULL) {
57 
58  // Initialise the STDAIR service handler
59  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
60  initStdAirService (iLogParams, iDBParams);
61 
62  // Initialise the service context
63  initServiceContext();
64 
65  // Add the StdAir service context to the AIRRAC service context
66  // \note AIRRAC owns the STDAIR service resources here.
67  const bool ownStdairService = true;
68  addStdAirService (lSTDAIR_Service_ptr, ownStdairService);
69 
70  // Initialise the (remaining of the) context
71  initAirracService();
72  }
73 
74  // ////////////////////////////////////////////////////////////////////
75  AIRRAC_Service::
76  AIRRAC_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr)
77  : _airracServiceContext (NULL) {
78 
79  // Initialise the service context
80  initServiceContext();
81 
82  // Store the STDAIR service object within the (AIRRAC) service context
83  // \note Airrac does not own the STDAIR service resources here.
84  const bool doesNotOwnStdairService = false;
85  addStdAirService (ioSTDAIR_Service_ptr, doesNotOwnStdairService);
86 
87  // Initialise the context
88  initAirracService();
89  }
90 
91  // //////////////////////////////////////////////////////////////////////
93  // Delete/Clean all the objects from memory
94  finalise();
95  }
96 
97  // //////////////////////////////////////////////////////////////////////
98  void AIRRAC_Service::finalise() {
99  assert (_airracServiceContext != NULL);
100  // Reset the (Boost.)Smart pointer pointing on the STDAIR_Service object.
101  _airracServiceContext->reset();
102  }
103 
104  // //////////////////////////////////////////////////////////////////////
105  void AIRRAC_Service::initServiceContext() {
106  // Initialise the service context
107  AIRRAC_ServiceContext& lAIRRAC_ServiceContext =
109  _airracServiceContext = &lAIRRAC_ServiceContext;
110  }
111 
112  // //////////////////////////////////////////////////////////////////////
113  stdair::STDAIR_ServicePtr_T AIRRAC_Service::
114  initStdAirService (const stdair::BasLogParams& iLogParams,
115  const stdair::BasDBParams& iDBParams) {
116 
124  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
125  boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams);
126 
127  return lSTDAIR_Service_ptr;
128 
129  }
130 
131  // //////////////////////////////////////////////////////////////////////
132  stdair::STDAIR_ServicePtr_T AIRRAC_Service::
133  initStdAirService (const stdair::BasLogParams& iLogParams) {
134 
142  stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr =
143  boost::make_shared<stdair::STDAIR_Service> (iLogParams);
144 
145  return lSTDAIR_Service_ptr;
146  }
147 
148  // ////////////////////////////////////////////////////////////////////
149  void AIRRAC_Service::
150  addStdAirService (stdair::STDAIR_ServicePtr_T ioSTDAIR_Service_ptr,
151  const bool iOwnStdairService) {
152 
153  // Retrieve the Airrac service context
154  assert (_airracServiceContext != NULL);
155  AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
156 
157  // Store the STDAIR service object within the (AIRRAC) service context
158  lAIRRAC_ServiceContext.setSTDAIR_Service (ioSTDAIR_Service_ptr,
159  iOwnStdairService);
160  }
161 
162  // ////////////////////////////////////////////////////////////////////
163  void AIRRAC_Service::initAirracService() {
164  // Do nothing at this stage. A sample BOM tree may be built by
165  // calling the buildSampleBom() method
166  }
167 
168  // ////////////////////////////////////////////////////////////////////
169  void AIRRAC_Service::
170  parseAndLoad (const YieldFilePath& iYieldFilename) {
171 
172  // Retrieve the AirRAC service context
173  if (_airracServiceContext == NULL) {
174  throw stdair::NonInitialisedServiceException ("The AirRAC service has not"
175  " been initialised");
176  }
177  assert (_airracServiceContext != NULL);
178 
179  // Retrieve the AirRAC service context and whether it owns the Stdair
180  // service
181  AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
182  const bool doesOwnStdairService =
183  lAIRRAC_ServiceContext.getOwnStdairServiceFlag();
184 
185  // Retrieve the StdAir service object from the (AirRAC) service context
186  stdair::STDAIR_Service& lSTDAIR_Service =
187  lAIRRAC_ServiceContext.getSTDAIR_Service();
188 
189  // Retrieve the BOM root object.
190  stdair::BomRoot& lPersistentBomRoot =
191  lSTDAIR_Service.getPersistentBomRoot();
192 
196  YieldParser::generateYieldStore (iYieldFilename, lPersistentBomRoot);
197 
210  buildComplementaryLinks (lPersistentBomRoot);
211 
216  if (doesOwnStdairService == true) {
217  //
219  }
220  }
221 
222  // ////////////////////////////////////////////////////////////////////
224 
225  // Retrieve the AirRAC service context
226  if (_airracServiceContext == NULL) {
227  throw stdair::NonInitialisedServiceException ("The AirRAC service has not"
228  " been initialised");
229  }
230  assert (_airracServiceContext != NULL);
231 
232  // Retrieve the AirRAC service context and whether it owns the Stdair
233  // service
234  AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
235  const bool doesOwnStdairService =
236  lAIRRAC_ServiceContext.getOwnStdairServiceFlag();
237 
238  // Retrieve the StdAir service object from the (AirRAC) service context
239  stdair::STDAIR_Service& lSTDAIR_Service =
240  lAIRRAC_ServiceContext.getSTDAIR_Service();
241 
242  // Retrieve the persistent BOM root object.
243  stdair::BomRoot& lPersistentBomRoot =
244  lSTDAIR_Service.getPersistentBomRoot();
245 
250  if (doesOwnStdairService == true) {
251  //
252  lSTDAIR_Service.buildSampleBom();
253  }
254 
267  buildComplementaryLinks (lPersistentBomRoot);
268 
273  if (doesOwnStdairService == true) {
274  //
276  }
277  }
278 
279  // ////////////////////////////////////////////////////////////////////
281 
282  // Retrieve the AirRAC service context
283  if (_airracServiceContext == NULL) {
284  throw stdair::NonInitialisedServiceException ("The AirRAC service has not"
285  " been initialised");
286  }
287  assert (_airracServiceContext != NULL);
288 
289  // Retrieve the AirRAC service context and whether it owns the Stdair
290  // service
291  AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
292  const bool doesOwnStdairService =
293  lAIRRAC_ServiceContext.getOwnStdairServiceFlag();
294 
295  // Retrieve the StdAir service object from the (AirRAC) service context
296  stdair::STDAIR_Service& lSTDAIR_Service =
297  lAIRRAC_ServiceContext.getSTDAIR_Service();
298 
303  if (doesOwnStdairService == true) {
304 
305  //
306  lSTDAIR_Service.clonePersistentBom ();
307  }
308 
321  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
322  buildComplementaryLinks (lBomRoot);
323  }
324 
325  // ////////////////////////////////////////////////////////////////////
326  void AIRRAC_Service::buildComplementaryLinks (stdair::BomRoot& ioBomRoot) {
327  // Currently, no more things to do by AirRAC at that stage.
328  }
329 
330  // //////////////////////////////////////////////////////////////////////
331  void AIRRAC_Service::
332  buildSampleTravelSolutions(stdair::TravelSolutionList_T& ioTravelSolutionList){
333 
334  // Retrieve the AIRRAC service context
335  if (_airracServiceContext == NULL) {
336  throw stdair::NonInitialisedServiceException ("The AirRAC service has not"
337  " been initialised");
338  }
339  assert (_airracServiceContext != NULL);
340 
341  AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
342 
343  // Retrieve the STDAIR service object from the (AirRAC) service context
344  stdair::STDAIR_Service& lSTDAIR_Service =
345  lAIRRAC_ServiceContext.getSTDAIR_Service();
346 
347  // Delegate the BOM building to the dedicated service
348  lSTDAIR_Service.buildSampleTravelSolutions (ioTravelSolutionList);
349  }
350 
351  // //////////////////////////////////////////////////////////////////////
352  std::string AIRRAC_Service::csvDisplay() const {
353 
354  // Retrieve the AIRRAC service context
355  if (_airracServiceContext == NULL) {
356  throw stdair::NonInitialisedServiceException ("The Airrac service "
357  "has not been initialised");
358  }
359  assert (_airracServiceContext != NULL);
360 
361  AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
362 
363  // Retrieve the STDAIR service object from the (Airrac) service context
364  stdair::STDAIR_Service& lSTDAIR_Service =
365  lAIRRAC_ServiceContext.getSTDAIR_Service();
366 
367  // Get the root of the BOM tree, on which all of the other BOM objects
368  // are attached
369  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
370 
371  // Delegate the BOM display to the dedicated service
372  std::ostringstream oCSVStr;
373  stdair::BomDisplay::csvSimFQTAirRACDisplay (oCSVStr, lBomRoot);
374  return oCSVStr.str();
375 
376  }
377 
378  // //////////////////////////////////////////////////////////////////////
379  std::string AIRRAC_Service::
380  csvDisplay (const stdair::TravelSolutionList_T& ioTravelSolutionList) const {
381 
382  // Retrieve the AirRAC service context
383  if (_airracServiceContext == NULL) {
384  throw stdair::NonInitialisedServiceException ("The AirRAC service has not"
385  " been initialised");
386  }
387  assert (_airracServiceContext != NULL);
388 
389  // Retrieve the AirRAC service context
390  AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
391 
392  // Retrieve the STDAIR service object from the (AirRAC) service context
393  stdair::STDAIR_Service& lSTDAIR_Service =
394  lAIRRAC_ServiceContext.getSTDAIR_Service();
395 
396  // Delegate the BOM building to the dedicated service
397  return lSTDAIR_Service.csvDisplay (ioTravelSolutionList);
398  }
399 
400  // ////////////////////////////////////////////////////////////////////
401  void AIRRAC_Service::
402  calculateYields (stdair::TravelSolutionList_T& ioTravelSolutionList) {
403 
404  // Retrieve the Airrac service context
405  if (_airracServiceContext == NULL) {
406  throw stdair::NonInitialisedServiceException ("The AirRAC service has not"
407  " been initialised");
408  }
409  assert (_airracServiceContext != NULL);
410  AIRRAC_ServiceContext& lAIRRAC_ServiceContext = *_airracServiceContext;
411 
412  // Retrieve the StdAir service context
413  stdair::STDAIR_Service& lSTDAIR_Service =
414  lAIRRAC_ServiceContext.getSTDAIR_Service();
415 
416  // Get the root of the BOM tree, on which all of the other BOM objects
417  // will be attached
418  stdair::BomRoot& lBomRoot = lSTDAIR_Service.getBomRoot();
419 
420  // Delegate the booking to the dedicated command: set the yields
421  // for each travel solution of the given list
422  stdair::BasChronometer lYieldChronometer;
423  lYieldChronometer.start();
424  YieldManager::calculateYield (ioTravelSolutionList, lBomRoot);
425  const double lYieldMeasure = lYieldChronometer.elapsed();
426 
427  // DEBUG
428  STDAIR_LOG_DEBUG ("Yield calculation: " << lYieldMeasure << " - "
429  << lAIRRAC_ServiceContext.display());
430  }
431 
432  // ////////////////////////////////////////////////////////////////////
433  void AIRRAC_Service::updateYields (stdair::BomRoot& ioBomRoot) {
434  // Retrieve the AirRAC service context
435  assert (_airracServiceContext != NULL);
436 
437  // Update the default yields to the booking classes.
438  YieldManager::updateYields (ioBomRoot);
439  }
440 }