SimCRS Logo  1.00.0
C++ Simulated Travel-Oriented Distribution System Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
DistributionManager.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // StdAir
7 #include <stdair/bom/FareOptionStruct.hpp>
8 #include <stdair/bom/TravelSolutionStruct.hpp>
9 #include <stdair/bom/CancellationStruct.hpp>
10 #include <stdair/service/Logger.hpp>
11 // Airline Inventory
12 #include <airinv/AIRINV_Master_Service.hpp>
13 // SimCRS
15 
16 namespace SIMCRS {
17 
18  // ////////////////////////////////////////////////////////////////////
19  void DistributionManager::
20  calculateAvailability (AIRINV::AIRINV_Master_Service& ioAIRINV_Master_Service,
21  stdair::TravelSolutionList_T& ioTravelSolutionList) {
22  for (stdair::TravelSolutionList_T::iterator itTS =
23  ioTravelSolutionList.begin();
24  itTS != ioTravelSolutionList.end(); ++itTS) {
25  stdair::TravelSolutionStruct& lCurrentTravelSolution = *itTS;
26 
27  // Forward the work to the dedicated service.
28  ioAIRINV_Master_Service.calculateAvailability (lCurrentTravelSolution);
29  }
30  }
31 
32  // ////////////////////////////////////////////////////////////////////
33  bool DistributionManager::
34  sell (AIRINV::AIRINV_Master_Service& ioAIRINV_Master_Service,
35  const stdair::TravelSolutionStruct& iTravelSolution,
36  const stdair::NbOfSeats_T& iPartySize) {
37  bool hasSaleBeenSuccessful = false;
38 
39  const stdair::ClassObjectIDMapHolder_T& lClassObjectIDMapHolder =
40  iTravelSolution.getClassObjectIDMapHolder();
41  if (lClassObjectIDMapHolder.size() > 0) {
42  const stdair::FareOptionStruct& lChosenFareOption =
43  iTravelSolution.getChosenFareOption ();
44  const stdair::ClassList_StringList_T& lClassPath =
45  lChosenFareOption.getClassPath();
46  stdair::ClassList_StringList_T::const_iterator itClassKeyList =
47  lClassPath.begin();
48  for (stdair::ClassObjectIDMapHolder_T::const_iterator itClassObjectIDMap =
49  lClassObjectIDMapHolder.begin();
50  itClassObjectIDMap != lClassObjectIDMapHolder.end();
51  ++itClassObjectIDMap, ++itClassKeyList) {
52  const stdair::ClassObjectIDMap_T& lClassObjectIDMap =
53  *itClassObjectIDMap;
54 
55  // TODO: Removed this hardcode.
56  std::ostringstream ostr;
57  const stdair::ClassList_String_T& lClassList = *itClassKeyList;
58  assert (lClassList.size() > 0);
59  ostr << lClassList.at(0);
60  const stdair::ClassCode_T lClassCode (ostr.str());
61  stdair::ClassObjectIDMap_T::const_iterator itClassID =
62  lClassObjectIDMap.find (lClassCode);
63  assert (itClassID != lClassObjectIDMap.end());
64  const stdair::BookingClassID_T& lClassID = itClassID->second;
65 
66  hasSaleBeenSuccessful =
67  ioAIRINV_Master_Service.sell (lClassID, iPartySize);
68  }
69  } else {
70  const stdair::KeyList_T& lSegmentDateKeyList =
71  iTravelSolution.getSegmentPath();
72  const stdair::FareOptionStruct& lChosenFareOption =
73  iTravelSolution.getChosenFareOption ();
74  const stdair::ClassList_StringList_T& lClassPath =
75  lChosenFareOption.getClassPath();
76  stdair::ClassList_StringList_T::const_iterator itClassKeyList =
77  lClassPath.begin();
78  for (stdair::KeyList_T::const_iterator itKey= lSegmentDateKeyList.begin();
79  itKey != lSegmentDateKeyList.end(); ++itKey, ++itClassKeyList) {
80  const std::string& lSegmentDateKey = *itKey;
81 
82  // TODO: Removed this hardcode.
83  std::ostringstream ostr;
84  const stdair::ClassList_String_T& lClassList = *itClassKeyList;
85  assert (lClassList.size() > 0);
86  ostr << lClassList.at(0);
87  const stdair::ClassCode_T lClassCode (ostr.str());
88 
89  hasSaleBeenSuccessful =
90  ioAIRINV_Master_Service.sell (lSegmentDateKey, lClassCode,
91  iPartySize);
92  }
93  }
94 
95  return hasSaleBeenSuccessful;
96  }
97 
98  // ////////////////////////////////////////////////////////////////////
99  bool DistributionManager::
100  playCancellation (AIRINV::AIRINV_Master_Service& ioAIRINV_Master_Service,
101  const stdair::CancellationStruct& iCancellation) {
102  bool hasCancellationBeenSuccessful = false;
103 
104  const stdair::PartySize_T& lPartySize = iCancellation.getPartySize();
105  const stdair::BookingClassIDList_T& lClassIDList =
106  iCancellation.getClassIDList();
107 
108  for (stdair::BookingClassIDList_T::const_iterator itClassID =
109  lClassIDList.begin(); itClassID != lClassIDList.end(); ++itClassID) {
110  const stdair::BookingClassID_T& lClassID = *itClassID;
111 
112  hasCancellationBeenSuccessful =
113  ioAIRINV_Master_Service.cancel (lClassID, lPartySize);
114  }
115  return hasCancellationBeenSuccessful;
116  }
117 
118 }