AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
SegmentDateHelper.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // STDAIR
00007 #include <stdair/basic/BasConst_General.hpp>
00008 #include <stdair/bom/BomManager.hpp>
00009 #include <stdair/bom/SegmentDate.hpp>
00010 #include <stdair/bom/SegmentCabin.hpp>
00011 #include <stdair/bom/LegDate.hpp>
00012 // AIRINV
00013 #include <airinv/bom/SegmentDateHelper.hpp>
00014 #include <airinv/bom/SegmentCabinHelper.hpp>
00015 
00016 namespace AIRINV {
00017   // ////////////////////////////////////////////////////////////////////
00018   void SegmentDateHelper::fillFromRouting (stdair::SegmentDate& ioSegmentDate) {
00019     /*
00020      * If the segment is just marketed by this carrier,
00021      * retrieve the operating segment and call the fillFromRouting
00022      * method on it.
00023      */
00024     stdair::SegmentDate* lOperatingSegmentDate_ptr =
00025       ioSegmentDate.getOperatingSegmentDate ();
00026     if (lOperatingSegmentDate_ptr != NULL) {
00027       fillFromRouting (*lOperatingSegmentDate_ptr);
00028       return;
00029     }
00030     // Retrieve the first and the last legs of the routing.
00031     // Note that in the majority of the cases, as flights are mono-legs,
00032     // the first and last legs are thus the same.
00033     const stdair::LegDateList_T& lLegDateList =
00034       stdair::BomManager::getList<stdair::LegDate> (ioSegmentDate);
00035     stdair::LegDateList_T::const_iterator itFirstLeg = lLegDateList.begin();
00036     const stdair::LegDate* lFirstLeg_ptr = *itFirstLeg;
00037     assert (lFirstLeg_ptr != NULL);
00038     stdair::LegDateList_T::const_reverse_iterator itLastLeg =
00039       lLegDateList.rbegin();
00040     const stdair::LegDate* lLastLeg_ptr = *itLastLeg;
00041     assert (lLastLeg_ptr != NULL);
00042     
00043     // Set the Boarding Date
00044     const stdair::Date_T& lBoardingDate = lFirstLeg_ptr->getBoardingDate();
00045     ioSegmentDate.setBoardingDate (lBoardingDate);
00046     // Set the Boarding Time
00047     const stdair::Duration_T& lBoardingTime = lFirstLeg_ptr->getBoardingTime();
00048     ioSegmentDate.setBoardingTime (lBoardingTime);
00049     // Set the Off Date
00050     const stdair::Date_T& lOffDate = lLastLeg_ptr->getOffDate();
00051     ioSegmentDate.setOffDate (lOffDate);
00052     // Set the Off Time
00053     const stdair::Duration_T& lOffTime = lLastLeg_ptr->getOffTime();
00054     ioSegmentDate.setOffTime (lOffTime);
00055     // Set the Elapsed Time for the whole path
00056     updateElapsedTimeFromRouting (ioSegmentDate);
00057 
00058     // Initialise the AU for all classes.
00059     const stdair::SegmentCabinList_T& lSegmentCabinList =
00060       stdair::BomManager::getList<stdair::SegmentCabin> (ioSegmentDate);
00061     for (stdair::SegmentCabinList_T::const_iterator itSC =
00062            lSegmentCabinList.begin(); itSC != lSegmentCabinList.end(); ++itSC) {
00063       stdair::SegmentCabin* lSC_ptr = *itSC;
00064       assert (lSC_ptr != NULL);
00065       
00066       // Initialise the AU for children booking classes.
00067       SegmentCabinHelper::initialiseAU (*lSC_ptr);
00068     }
00069   }
00070 
00071   // //////////////////////////////////////////////////////////////////////
00072   void SegmentDateHelper::
00073   updateElapsedTimeFromRouting (stdair::SegmentDate& ioSegmentDate) {
00074 
00075     const stdair::LegDateList_T& lLegDateList =
00076       stdair::BomManager::getList<stdair::LegDate> (ioSegmentDate);
00077       
00078     stdair::LegDateList_T::const_iterator itLegDate = lLegDateList.begin();
00079     const stdair::LegDate* lCurrentLegDate_ptr = *itLegDate;
00080     assert (lCurrentLegDate_ptr != NULL);
00081 
00082     // Retrieve the elapsed time of the first leg
00083     stdair::Duration_T lElapsedTime = lCurrentLegDate_ptr->getElapsedTime();
00084 
00085     // Go to the next leg, if existing. If not existing, the following
00086     // loop will not be entered (as it means: currentLeg == _legDateList.end()).
00087     ++itLegDate;
00088 
00089     for (const stdair::LegDate* lPreviousLegDate_ptr = lCurrentLegDate_ptr;
00090          itLegDate != lLegDateList.end();
00091          ++itLegDate, lPreviousLegDate_ptr = lCurrentLegDate_ptr) {
00092       lCurrentLegDate_ptr = *itLegDate;
00093       
00094       // As the boarding point of the current leg is the same as the off point
00095       // of the previous leg (by construction), there is no time difference.
00096       assert (lCurrentLegDate_ptr->getBoardingPoint()
00097               == lPreviousLegDate_ptr->getOffPoint());
00098       const stdair::Duration_T& lStopOverTime =
00099         lCurrentLegDate_ptr->getBoardingTime() - lPreviousLegDate_ptr->getOffTime();
00100       lElapsedTime += lStopOverTime;
00101 
00102       // Add the elapsed time of the current leg
00103       const stdair::Duration_T& currentElapsedTime =
00104         lCurrentLegDate_ptr->getElapsedTime();
00105       lElapsedTime += currentElapsedTime;
00106     }
00107       
00108     // Store the result
00109     ioSegmentDate.setElapsedTime (lElapsedTime);
00110     // From the elapsed time, update the distance
00111     updateDistanceFromElapsedTime (ioSegmentDate);
00112   }
00113 
00114   // //////////////////////////////////////////////////////////////////////
00115   void SegmentDateHelper::
00116   updateDistanceFromElapsedTime (stdair::SegmentDate& ioSegmentDate) {
00117     const stdair::Duration_T& lElapsedTime = ioSegmentDate.getElapsedTime();
00118     const double lElapseInHours=static_cast<const double>(lElapsedTime.hours());
00119     const long int lDistance =
00120       static_cast<const long int>(stdair::DEFAULT_FLIGHT_SPEED*lElapseInHours);
00121     ioSegmentDate.setDistance (lDistance);
00122   }
00123 
00124 }