StdAir Logo  1.00.3
C++ Standard Airline IT Object Library
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::describeSegmentPath() 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  return oStr.str();
50  }
51 
52  // ////////////////////////////////////////////////////////////////////
53  const std::string TravelSolutionStruct::describe() const {
54  std::ostringstream oStr;
55 
56  //
57  oStr << "Segment path: ";
58  unsigned short idx = 0;
59  for (SegmentPath_T::const_iterator lItSegmentPath = _segmentPath.begin();
60  lItSegmentPath != _segmentPath.end(); ++lItSegmentPath, ++idx) {
61  if (idx != 0) {
62  oStr << "-";
63  }
64  const std::string& lSegmentPathString = *lItSegmentPath;
65  const stdair::ParsedKey& lSegmentParsedKey =
66  stdair::BomKeyManager::extractKeys (lSegmentPathString);
67  const std::string& lSegmentKey = lSegmentParsedKey.toString();
68  oStr << lSegmentKey;
69  }
70  oStr << " ### ";
71 
72  //
73  if (_chosenFareOption != NULL) {
74  oStr << "Chosen fare option: " << _chosenFareOption->describe()
75  << " ## Among: ";
76  } else {
77  oStr << "Fare options: ";
78  }
79 
80  //
81  idx = 0;
82  for (FareOptionList_T::const_iterator lItFareOption= _fareOptionList.begin();
83  lItFareOption != _fareOptionList.end(); ++lItFareOption, ++idx) {
84  if (idx != 0) {
85  oStr << " , ";
86  }
87  const FareOptionStruct& lFareOption = *lItFareOption;
88  oStr << lFareOption.describe();
89  }
90 
91  return oStr.str();
92  }
93 
94  // ////////////////////////////////////////////////////////////////////
95  const std::string TravelSolutionStruct::display() const {
96  std::ostringstream oStr;
97 
98  // List of segment keys (one per segment)
99  unsigned short idx = 0;
100  for (SegmentPath_T::const_iterator itSegPath = _segmentPath.begin();
101  itSegPath != _segmentPath.end(); ++itSegPath, ++idx) {
102  if (idx != 0) {
103  oStr << " ; ";
104  }
105  const std::string& lSegmentPathString = *itSegPath;
106  const stdair::ParsedKey& lSegmentParsedKey =
107  stdair::BomKeyManager::extractKeys (lSegmentPathString);
108  const std::string& lSegmentKey = lSegmentParsedKey.toString();
109  oStr << "[" << idx << "] " << lSegmentKey;
110  }
111 
112  // List of fare options (for the whole O&D)
113  oStr << " --- ";
114  idx = 0;
115  for (FareOptionList_T::const_iterator itFareOption = _fareOptionList.begin();
116  itFareOption != _fareOptionList.end(); ++itFareOption, ++idx) {
117  if (idx != 0) {
118  oStr << " , ";
119  }
120  const FareOptionStruct& lFareOption = *itFareOption;
121  oStr << lFareOption.display();
122  }
123 
124  // List of booking class availability maps: one map per segment
125  oStr << " --- ";
126  idx = 0;
127  for (ClassAvailabilityMapHolder_T::const_iterator itSegMap =
128  _classAvailabilityMapHolder.begin();
129  itSegMap != _classAvailabilityMapHolder.end(); ++itSegMap, ++idx) {
130  if (idx != 0) {
131  oStr << " ; ";
132  }
133  // Retrieve the booking class availability map
134  const ClassAvailabilityMap_T& lClassAvlMap = *itSegMap;
135  oStr << "[" << idx << "] ";
136 
137  // List (map) of booking class availabilities
138  unsigned short jdx = 0;
139  for (ClassAvailabilityMap_T::const_iterator itClass = lClassAvlMap.begin();
140  itClass != lClassAvlMap.end(); ++itClass, ++jdx) {
141  if (jdx != 0) {
142  oStr << " ";
143  }
144  const ClassCode_T& lClassCode = itClass->first;
145  const Availability_T& lAvl = itClass->second;
146  oStr << lClassCode << ":" << lAvl;
147  }
148  }
149 
150  return oStr.str();
151  }
152 
153  // ////////////////////////////////////////////////////////////////////
154  void TravelSolutionStruct::addSegment (const std::string& iKey) {
155  _segmentPath.push_back (iKey);
156  }
157 
158  // ////////////////////////////////////////////////////////////////////
161  _classAvailabilityMapHolder.push_back (iMap);
162  }
163 
164  // ////////////////////////////////////////////////////////////////////
167  _classObjectIDMapHolder.push_back (iMap);
168  }
169 
170  // ////////////////////////////////////////////////////////////////////
173  _classYieldMapHolder.push_back (iMap);
174  }
175 
176  // ////////////////////////////////////////////////////////////////////
179  _bidPriceVectorHolder.push_back (iBpv);
180  }
181 
182  // ////////////////////////////////////////////////////////////////////
185  _classBpvMapHolder.push_back (iMap);
186  }
187 
188  // ////////////////////////////////////////////////////////////////////
190  addFareOption (const FareOptionStruct& iFareOption) {
191  _fareOptionList.push_back (iFareOption);
192  }
193 
194 }
void addClassYieldMap(const ClassYieldMap_T &)
const std::string display() const
Structure holding the elements of a fare option.
const std::string describe() const
void fromStream(std::istream &ioIn)
double Availability_T
std::vector< BidPrice_T > BidPriceVector_T
void toStream(std::ostream &ioOut) const
Handle on the StdAir library context.
void addBidPriceVector(const BidPriceVector_T &)
void addClassAvailabilityMap(const ClassAvailabilityMap_T &)
void addFareOption(const FareOptionStruct &)
const std::string describe() const
std::map< const ClassCode_T, Availability_T > ClassAvailabilityMap_T
const std::string toString() const
Definition: ParsedKey.cpp:139
static ParsedKey extractKeys(const std::string &iFullKeyStr)
const std::string display() const
std::map< const ClassCode_T, BookingClassID_T > ClassObjectIDMap_T
void addSegment(const std::string &)
const std::string describeSegmentPath() const
void addClassBpvMap(const ClassBpvMap_T &)
std::map< const ClassCode_T, YieldValue_T > ClassYieldMap_T
void addClassObjectIDMap(const ClassObjectIDMap_T &)
std::string ClassCode_T
std::map< const ClassCode_T, const BidPriceVector_T * > ClassBpvMap_T