StdAir Logo  0.44.0
C++ Standard Airline IT Object Library
TravelSolutionStruct.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // StdAir
00008 #include <stdair/basic/BasConst_BookingClass.hpp>
00009 #include <stdair/bom/TravelSolutionStruct.hpp>
00010 #include <stdair/bom/BomKeyManager.hpp>
00011 #include <stdair/bom/ParsedKey.hpp>
00012 
00013 namespace stdair {
00014   // ////////////////////////////////////////////////////////////////////
00015   TravelSolutionStruct::TravelSolutionStruct() : _chosenFareOption (NULL) {
00016   }
00017   
00018   // ////////////////////////////////////////////////////////////////////
00019   TravelSolutionStruct::~TravelSolutionStruct() {
00020   }
00021   
00022   // ////////////////////////////////////////////////////////////////////
00023   void TravelSolutionStruct::toStream (std::ostream& ioOut) const {
00024     ioOut << describe();
00025   }
00026 
00027   // ////////////////////////////////////////////////////////////////////
00028   void TravelSolutionStruct::fromStream (std::istream& ioIn) {
00029   }
00030   
00031   // ////////////////////////////////////////////////////////////////////
00032   const std::string TravelSolutionStruct::describe() const {
00033     std::ostringstream oStr;
00034 
00035     //
00036     oStr << "Segment path: ";
00037     unsigned short idx = 0;
00038     for (SegmentPath_T::const_iterator lItSegmentPath = _segmentPath.begin();
00039          lItSegmentPath != _segmentPath.end(); ++lItSegmentPath, ++idx) {
00040       if (idx != 0) {
00041         oStr << "-";
00042       }
00043       const std::string& lSegmentPathString = *lItSegmentPath;
00044       const stdair::ParsedKey& lSegmentParsedKey =
00045         stdair::BomKeyManager::extractKeys (lSegmentPathString);
00046       const std::string& lSegmentKey = lSegmentParsedKey.toString();
00047       oStr << lSegmentKey;
00048     }
00049     oStr << " ### ";
00050 
00051     //
00052     if (_chosenFareOption != NULL) {
00053       oStr << "Chosen fare option: " << _chosenFareOption->describe()
00054            << " ## Among: ";
00055     } else {
00056       oStr << "Fare options: ";
00057     }
00058 
00059     //
00060     idx = 0;
00061     for (FareOptionList_T::const_iterator lItFareOption= _fareOptionList.begin();
00062          lItFareOption != _fareOptionList.end(); ++lItFareOption, ++idx) {
00063       if (idx != 0) {
00064         oStr << " , ";
00065       }
00066       const FareOptionStruct& lFareOption = *lItFareOption;
00067       oStr << lFareOption.describe();
00068     }
00069 
00070     return oStr.str();
00071   }
00072 
00073   // ////////////////////////////////////////////////////////////////////
00074   const std::string TravelSolutionStruct::display() const {
00075     std::ostringstream oStr;
00076 
00077     // List of segment keys (one per segment)
00078     unsigned short idx = 0;
00079     for (SegmentPath_T::const_iterator itSegPath = _segmentPath.begin();
00080          itSegPath != _segmentPath.end(); ++itSegPath, ++idx) {
00081       if (idx != 0) {
00082         oStr << " ; ";
00083       }
00084       const std::string& lSegmentPathString = *itSegPath;
00085       const stdair::ParsedKey& lSegmentParsedKey =
00086         stdair::BomKeyManager::extractKeys (lSegmentPathString);
00087       const std::string& lSegmentKey = lSegmentParsedKey.toString();
00088       oStr << "[" << idx << "] " << lSegmentKey;
00089     }
00090 
00091     // List of fare options (for the whole O&D)
00092     oStr << " --- ";
00093     idx = 0;
00094     for (FareOptionList_T::const_iterator itFareOption = _fareOptionList.begin();
00095          itFareOption != _fareOptionList.end(); ++itFareOption, ++idx) {
00096       if (idx != 0) {
00097         oStr << " , ";
00098       }
00099       const FareOptionStruct& lFareOption = *itFareOption;
00100       oStr << lFareOption.display();
00101     }
00102 
00103     // List of booking class availability maps: one map per segment
00104     oStr << " --- ";
00105     idx = 0;
00106     for (ClassAvailabilityMapHolder_T::const_iterator itSegMap =
00107            _classAvailabilityMapHolder.begin();
00108          itSegMap != _classAvailabilityMapHolder.end(); ++itSegMap, ++idx) {
00109       if (idx != 0) {
00110         oStr << " ; ";
00111       }
00112       // Retrieve the booking class availability map
00113       const ClassAvailabilityMap_T& lClassAvlMap = *itSegMap;
00114       oStr << "[" << idx << "] ";
00115       
00116       // List (map) of booking class availabilities
00117       unsigned short jdx = 0;
00118       for (ClassAvailabilityMap_T::const_iterator itClass = lClassAvlMap.begin();
00119            itClass != lClassAvlMap.end(); ++itClass, ++jdx) {
00120         if (jdx != 0) {
00121           oStr << " ";
00122         }
00123         const ClassCode_T& lClassCode = itClass->first;
00124         const Availability_T& lAvl = itClass->second;
00125         oStr << lClassCode << ":" << lAvl;
00126       }
00127     }
00128 
00129     return oStr.str();
00130   }
00131 
00132   // ////////////////////////////////////////////////////////////////////
00133   void TravelSolutionStruct::addSegment (const std::string& iKey) {
00134     _segmentPath.push_back (iKey);
00135   }
00136 
00137   // ////////////////////////////////////////////////////////////////////
00138   void TravelSolutionStruct::
00139   addClassAvailabilityMap (const ClassAvailabilityMap_T& iMap) {
00140     _classAvailabilityMapHolder.push_back (iMap);
00141   }
00142 
00143   // ////////////////////////////////////////////////////////////////////
00144   void TravelSolutionStruct::
00145   addClassYieldMap (const ClassYieldMap_T& iMap) {
00146     _classYieldMapHolder.push_back (iMap);
00147   }
00148 
00149   // ////////////////////////////////////////////////////////////////////
00150   void TravelSolutionStruct::
00151   addBidPriceVector (const BidPriceVector_T& iBpv) {
00152     _bidPriceVectorHolder.push_back (iBpv);
00153   }
00154 
00155   // ////////////////////////////////////////////////////////////////////
00156   void TravelSolutionStruct::
00157   addClassBpvMap (const ClassBpvMap_T& iMap) {
00158     _classBpvMapHolder.push_back (iMap);
00159   }
00160   
00161   // ////////////////////////////////////////////////////////////////////
00162   void TravelSolutionStruct::
00163   addFareOption (const FareOptionStruct& iFareOption) {
00164     _fareOptionList.push_back (iFareOption);
00165   }
00166 
00167 }