StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TravelSolutionStruct.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // StdAir
11 #include <stdair/bom/ParsedKey.hpp>
12 
13 namespace stdair {
14  // ////////////////////////////////////////////////////////////////////
15  TravelSolutionStruct::TravelSolutionStruct() : _chosenFareOption (NULL) {
16  }
17 
18  // ////////////////////////////////////////////////////////////////////
20  }
21 
22  // ////////////////////////////////////////////////////////////////////
23  void TravelSolutionStruct::toStream (std::ostream& ioOut) const {
24  ioOut << describe();
25  }
26 
27  // ////////////////////////////////////////////////////////////////////
28  void TravelSolutionStruct::fromStream (std::istream& ioIn) {
29  }
30 
31  // ////////////////////////////////////////////////////////////////////
32  const std::string TravelSolutionStruct::describe() const {
33  std::ostringstream oStr;
34 
35  //
36  oStr << "Segment path: ";
37  unsigned short idx = 0;
38  for (SegmentPath_T::const_iterator lItSegmentPath = _segmentPath.begin();
39  lItSegmentPath != _segmentPath.end(); ++lItSegmentPath, ++idx) {
40  if (idx != 0) {
41  oStr << "-";
42  }
43  const std::string& lSegmentPathString = *lItSegmentPath;
44  const stdair::ParsedKey& lSegmentParsedKey =
45  stdair::BomKeyManager::extractKeys (lSegmentPathString);
46  const std::string& lSegmentKey = lSegmentParsedKey.toString();
47  oStr << lSegmentKey;
48  }
49  oStr << " ### ";
50 
51  //
52  if (_chosenFareOption != NULL) {
53  oStr << "Chosen fare option: " << _chosenFareOption->describe()
54  << " ## Among: ";
55  } else {
56  oStr << "Fare options: ";
57  }
58 
59  //
60  idx = 0;
61  for (FareOptionList_T::const_iterator lItFareOption= _fareOptionList.begin();
62  lItFareOption != _fareOptionList.end(); ++lItFareOption, ++idx) {
63  if (idx != 0) {
64  oStr << " , ";
65  }
66  const FareOptionStruct& lFareOption = *lItFareOption;
67  oStr << lFareOption.describe();
68  }
69 
70  return oStr.str();
71  }
72 
73  // ////////////////////////////////////////////////////////////////////
74  const std::string TravelSolutionStruct::display() const {
75  std::ostringstream oStr;
76 
77  // List of segment keys (one per segment)
78  unsigned short idx = 0;
79  for (SegmentPath_T::const_iterator itSegPath = _segmentPath.begin();
80  itSegPath != _segmentPath.end(); ++itSegPath, ++idx) {
81  if (idx != 0) {
82  oStr << " ; ";
83  }
84  const std::string& lSegmentPathString = *itSegPath;
85  const stdair::ParsedKey& lSegmentParsedKey =
86  stdair::BomKeyManager::extractKeys (lSegmentPathString);
87  const std::string& lSegmentKey = lSegmentParsedKey.toString();
88  oStr << "[" << idx << "] " << lSegmentKey;
89  }
90 
91  // List of fare options (for the whole O&D)
92  oStr << " --- ";
93  idx = 0;
94  for (FareOptionList_T::const_iterator itFareOption = _fareOptionList.begin();
95  itFareOption != _fareOptionList.end(); ++itFareOption, ++idx) {
96  if (idx != 0) {
97  oStr << " , ";
98  }
99  const FareOptionStruct& lFareOption = *itFareOption;
100  oStr << lFareOption.display();
101  }
102 
103  // List of booking class availability maps: one map per segment
104  oStr << " --- ";
105  idx = 0;
106  for (ClassAvailabilityMapHolder_T::const_iterator itSegMap =
107  _classAvailabilityMapHolder.begin();
108  itSegMap != _classAvailabilityMapHolder.end(); ++itSegMap, ++idx) {
109  if (idx != 0) {
110  oStr << " ; ";
111  }
112  // Retrieve the booking class availability map
113  const ClassAvailabilityMap_T& lClassAvlMap = *itSegMap;
114  oStr << "[" << idx << "] ";
115 
116  // List (map) of booking class availabilities
117  unsigned short jdx = 0;
118  for (ClassAvailabilityMap_T::const_iterator itClass = lClassAvlMap.begin();
119  itClass != lClassAvlMap.end(); ++itClass, ++jdx) {
120  if (jdx != 0) {
121  oStr << " ";
122  }
123  const ClassCode_T& lClassCode = itClass->first;
124  const Availability_T& lAvl = itClass->second;
125  oStr << lClassCode << ":" << lAvl;
126  }
127  }
128 
129  return oStr.str();
130  }
131 
132  // ////////////////////////////////////////////////////////////////////
133  void TravelSolutionStruct::addSegment (const std::string& iKey) {
134  _segmentPath.push_back (iKey);
135  }
136 
137  // ////////////////////////////////////////////////////////////////////
140  _classAvailabilityMapHolder.push_back (iMap);
141  }
142 
143  // ////////////////////////////////////////////////////////////////////
146  _classYieldMapHolder.push_back (iMap);
147  }
148 
149  // ////////////////////////////////////////////////////////////////////
152  _bidPriceVectorHolder.push_back (iBpv);
153  }
154 
155  // ////////////////////////////////////////////////////////////////////
158  _classBpvMapHolder.push_back (iMap);
159  }
160 
161  // ////////////////////////////////////////////////////////////////////
163  addFareOption (const FareOptionStruct& iFareOption) {
164  _fareOptionList.push_back (iFareOption);
165  }
166 
167 }