SimFQT Logo  0.1.3
C++ Simulated Fare Quote System Library
FareRuleStruct.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 #include <vector>
00008 // StdAir
00009 #include <stdair/basic/BasConst_General.hpp>
00010 #include <stdair/service/Logger.hpp>
00011 // SIMFQT
00012 #include <simfqt/bom/FareRuleStruct.hpp>
00013 
00014 namespace SIMFQT {
00015 
00016   // ////////////////////////////////////////////////////////////////////
00017   FareRuleStruct::FareRuleStruct ()
00018     :_fareId(0), 
00019      _origin(""), 
00020      _destination(""),
00021      _dateRangeStart(stdair::DEFAULT_DATE),
00022      _dateRangeEnd(stdair::DEFAULT_DATE),
00023      _timeRangeStart(stdair::DEFAULT_EPSILON_DURATION),
00024      _timeRangeEnd(stdair::DEFAULT_EPSILON_DURATION),
00025      _cabinCode (""), 
00026      _pos (""), 
00027      _advancePurchase(0), 
00028      _saturdayStay("T"),
00029      _changeFees("T"), 
00030      _nonRefundable("T"),
00031      _minimumStay(0), 
00032      _fare(0),
00033      _airlineCode(""), 
00034      _classCode("") {
00035 
00036   }
00037 
00038   // ////////////////////////////////////////////////////////////////////
00039   stdair::Date_T FareRuleStruct::calculateDate() const {
00040     _itYear.check(); _itMonth.check(); _itDay.check();
00041     return stdair::Date_T (_itYear._value, _itMonth._value, _itDay._value);
00042   }
00043 
00044   // ////////////////////////////////////////////////////////////////////
00045   stdair::Duration_T FareRuleStruct::calculateTime() const {
00046     _itHours.check(); _itMinutes.check(); _itSeconds.check();
00047     return boost::posix_time::hours (_itHours._value)
00048       + boost::posix_time::minutes (_itMinutes._value)
00049       + boost::posix_time::seconds (_itSeconds._value);
00050   }
00051   
00052  
00053   // ////////////////////////////////////////////////////////////////////
00054   const std::string FareRuleStruct::describe () const {
00055 
00056     std::ostringstream oStr;
00057     oStr << "FareRule: " << _fareId << ", ";
00058 
00059     oStr << _origin << "-" << _destination << " ("
00060          << _pos << "), " << _channel << ", [";
00061     oStr << _dateRangeStart << "/" << _dateRangeEnd << "] - ["
00062          << boost::posix_time::to_simple_string (_timeRangeStart) << "/"
00063          << boost::posix_time::to_simple_string (_timeRangeEnd) << "], ";
00064 
00065     oStr << _cabinCode << ", " << _fare  << " EUR, ";
00066     oStr << _tripType << ", " << _saturdayStay << ", "
00067          <<  _changeFees << ", " << _nonRefundable << ", "
00068          << _advancePurchase << ", " << _minimumStay << ", ";
00069 
00070     // Sanity check
00071     assert (_airlineCodeList.size() == _classCodeList.size());
00072 
00073     // Browse the airline and class pathes
00074     unsigned short idx = 0;
00075     stdair::ClassList_StringList_T::const_iterator itClass =
00076       _classCodeList.begin();
00077     for (stdair::AirlineCodeList_T::const_iterator itAirline =
00078            _airlineCodeList.begin();
00079          itAirline != _airlineCodeList.end(); ++itAirline, ++itClass, ++idx) {
00080       if (idx != 0) {
00081         oStr << " - ";
00082       }
00083       const stdair::AirlineCode_T lAirlineCode = *itAirline;
00084       const stdair::ClassCode_T lClassCode = *itClass;
00085       oStr << lAirlineCode << " / " << lClassCode;
00086     }
00087 
00088     return oStr.str();
00089   }
00090   
00091 }
00092