$treeview $search $mathjax
StdAir Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

stdair/bom/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::describeSegmentPath() 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     return oStr.str();
00050   }
00051   
00052   // ////////////////////////////////////////////////////////////////////
00053   const std::string TravelSolutionStruct::describe() const {
00054     std::ostringstream oStr;
00055 
00056     //
00057     oStr << "Segment path: ";
00058     unsigned short idx = 0;
00059     for (SegmentPath_T::const_iterator lItSegmentPath = _segmentPath.begin();
00060          lItSegmentPath != _segmentPath.end(); ++lItSegmentPath, ++idx) {
00061       if (idx != 0) {
00062         oStr << "-";
00063       }
00064       const std::string& lSegmentPathString = *lItSegmentPath;
00065       const stdair::ParsedKey& lSegmentParsedKey =
00066         stdair::BomKeyManager::extractKeys (lSegmentPathString);
00067       const std::string& lSegmentKey = lSegmentParsedKey.toString();
00068       oStr << lSegmentKey;
00069     }
00070     oStr << " ### ";
00071 
00072     //
00073     if (_chosenFareOption != NULL) {
00074       oStr << "Chosen fare option: " << _chosenFareOption->describe()
00075            << " ## Among: ";
00076     } else {
00077       oStr << "Fare options: ";
00078     }
00079 
00080     //
00081     idx = 0;
00082     for (FareOptionList_T::const_iterator lItFareOption= _fareOptionList.begin();
00083          lItFareOption != _fareOptionList.end(); ++lItFareOption, ++idx) {
00084       if (idx != 0) {
00085         oStr << " , ";
00086       }
00087       const FareOptionStruct& lFareOption = *lItFareOption;
00088       oStr << lFareOption.describe();
00089     }
00090 
00091     return oStr.str();
00092   }
00093 
00094   // ////////////////////////////////////////////////////////////////////
00095   const std::string TravelSolutionStruct::display() const {
00096     std::ostringstream oStr;
00097 
00098     // List of segment keys (one per segment)
00099     unsigned short idx = 0;
00100     for (SegmentPath_T::const_iterator itSegPath = _segmentPath.begin();
00101          itSegPath != _segmentPath.end(); ++itSegPath, ++idx) {
00102       if (idx != 0) {
00103         oStr << " ; ";
00104       }
00105       const std::string& lSegmentPathString = *itSegPath;
00106       const stdair::ParsedKey& lSegmentParsedKey =
00107         stdair::BomKeyManager::extractKeys (lSegmentPathString);
00108       const std::string& lSegmentKey = lSegmentParsedKey.toString();
00109       oStr << "[" << idx << "] " << lSegmentKey;
00110     }
00111 
00112     // List of fare options (for the whole O&D)
00113     oStr << " --- ";
00114     idx = 0;
00115     for (FareOptionList_T::const_iterator itFareOption = _fareOptionList.begin();
00116          itFareOption != _fareOptionList.end(); ++itFareOption, ++idx) {
00117       if (idx != 0) {
00118         oStr << " , ";
00119       }
00120       const FareOptionStruct& lFareOption = *itFareOption;
00121       oStr << lFareOption.display();
00122     }
00123 
00124     // List of booking class availability maps: one map per segment
00125     oStr << " --- ";
00126     idx = 0;
00127     for (ClassAvailabilityMapHolder_T::const_iterator itSegMap =
00128            _classAvailabilityMapHolder.begin();
00129          itSegMap != _classAvailabilityMapHolder.end(); ++itSegMap, ++idx) {
00130       if (idx != 0) {
00131         oStr << " ; ";
00132       }
00133       // Retrieve the booking class availability map
00134       const ClassAvailabilityMap_T& lClassAvlMap = *itSegMap;
00135       oStr << "[" << idx << "] ";
00136       
00137       // List (map) of booking class availabilities
00138       unsigned short jdx = 0;
00139       for (ClassAvailabilityMap_T::const_iterator itClass = lClassAvlMap.begin();
00140            itClass != lClassAvlMap.end(); ++itClass, ++jdx) {
00141         if (jdx != 0) {
00142           oStr << " ";
00143         }
00144         const ClassCode_T& lClassCode = itClass->first;
00145         const Availability_T& lAvl = itClass->second;
00146         oStr << lClassCode << ":" << lAvl;
00147       }
00148     }
00149 
00150     return oStr.str();
00151   }
00152 
00153   // ////////////////////////////////////////////////////////////////////
00154   void TravelSolutionStruct::addSegment (const std::string& iKey) {
00155     _segmentPath.push_back (iKey);
00156   }
00157 
00158   // ////////////////////////////////////////////////////////////////////
00159   void TravelSolutionStruct::
00160   addClassAvailabilityMap (const ClassAvailabilityMap_T& iMap) {
00161     _classAvailabilityMapHolder.push_back (iMap);
00162   }
00163 
00164   // ////////////////////////////////////////////////////////////////////
00165   void TravelSolutionStruct::
00166   addClassObjectIDMap (const ClassObjectIDMap_T& iMap) {
00167     _classObjectIDMapHolder.push_back (iMap);
00168   }
00169 
00170   // ////////////////////////////////////////////////////////////////////
00171   void TravelSolutionStruct::
00172   addClassYieldMap (const ClassYieldMap_T& iMap) {
00173     _classYieldMapHolder.push_back (iMap);
00174   }
00175 
00176   // ////////////////////////////////////////////////////////////////////
00177   void TravelSolutionStruct::
00178   addBidPriceVector (const BidPriceVector_T& iBpv) {
00179     _bidPriceVectorHolder.push_back (iBpv);
00180   }
00181 
00182   // ////////////////////////////////////////////////////////////////////
00183   void TravelSolutionStruct::
00184   addClassBpvMap (const ClassBpvMap_T& iMap) {
00185     _classBpvMapHolder.push_back (iMap);
00186   }
00187   
00188   // ////////////////////////////////////////////////////////////////////
00189   void TravelSolutionStruct::
00190   addFareOption (const FareOptionStruct& iFareOption) {
00191     _fareOptionList.push_back (iFareOption);
00192   }
00193 
00194 }