$treeview $search $mathjax
AirInv Logo  1.00.1
$projectbrief
$projectbrief
$searchbox

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       return;
00028     }
00029     // Retrieve the first and the last legs of the routing.
00030     // Note that in the majority of the cases, as flights are mono-legs,
00031     // the first and last legs are thus the same.
00032     const stdair::LegDateList_T& lLegDateList =
00033       stdair::BomManager::getList<stdair::LegDate> (ioSegmentDate);
00034     stdair::LegDateList_T::const_iterator itFirstLeg = lLegDateList.begin();
00035     const stdair::LegDate* lFirstLeg_ptr = *itFirstLeg;
00036     assert (lFirstLeg_ptr != NULL);
00037     stdair::LegDateList_T::const_reverse_iterator itLastLeg =
00038       lLegDateList.rbegin();
00039     const stdair::LegDate* lLastLeg_ptr = *itLastLeg;
00040     assert (lLastLeg_ptr != NULL);
00041     
00042     // Set the Boarding Date
00043     const stdair::Date_T& lBoardingDate = lFirstLeg_ptr->getBoardingDate();
00044     ioSegmentDate.setBoardingDate (lBoardingDate);
00045     // Set the Boarding Time
00046     const stdair::Duration_T& lBoardingTime = lFirstLeg_ptr->getBoardingTime();
00047     ioSegmentDate.setBoardingTime (lBoardingTime);
00048     // Set the Off Date
00049     const stdair::Date_T& lOffDate = lLastLeg_ptr->getOffDate();
00050     ioSegmentDate.setOffDate (lOffDate);
00051     // Set the Off Time
00052     const stdair::Duration_T& lOffTime = lLastLeg_ptr->getOffTime();
00053     ioSegmentDate.setOffTime (lOffTime);
00054     // Set the Elapsed Time for the whole path
00055     updateElapsedTimeFromRouting (ioSegmentDate);
00056 
00057     // Initialise the AU for all classes.
00058     const stdair::SegmentCabinList_T& lSegmentCabinList =
00059       stdair::BomManager::getList<stdair::SegmentCabin> (ioSegmentDate);
00060     for (stdair::SegmentCabinList_T::const_iterator itSC =
00061            lSegmentCabinList.begin(); itSC != lSegmentCabinList.end(); ++itSC) {
00062       stdair::SegmentCabin* lSC_ptr = *itSC;
00063       assert (lSC_ptr != NULL);
00064       
00065       // Initialise the AU for children booking classes.
00066       SegmentCabinHelper::initialiseAU (*lSC_ptr);
00067     }
00068   }
00069 
00070   // //////////////////////////////////////////////////////////////////////
00071   void SegmentDateHelper::
00072   updateElapsedTimeFromRouting (stdair::SegmentDate& ioSegmentDate) {
00073 
00074     const stdair::LegDateList_T& lLegDateList =
00075       stdair::BomManager::getList<stdair::LegDate> (ioSegmentDate);
00076       
00077     stdair::LegDateList_T::const_iterator itLegDate = lLegDateList.begin();
00078     const stdair::LegDate* lCurrentLegDate_ptr = *itLegDate;
00079     assert (lCurrentLegDate_ptr != NULL);
00080 
00081     // Retrieve the elapsed time of the first leg
00082     stdair::Duration_T lElapsedTime = lCurrentLegDate_ptr->getElapsedTime();
00083 
00084     // Go to the next leg, if existing. If not existing, the following
00085     // loop will not be entered (as it means: currentLeg == _legDateList.end()).
00086     ++itLegDate;
00087 
00088     for (const stdair::LegDate* lPreviousLegDate_ptr = lCurrentLegDate_ptr;
00089          itLegDate != lLegDateList.end();
00090          ++itLegDate, lPreviousLegDate_ptr = lCurrentLegDate_ptr) {
00091       lCurrentLegDate_ptr = *itLegDate;
00092       
00093       // As the boarding point of the current leg is the same as the off point
00094       // of the previous leg (by construction), there is no time difference.
00095       assert (lCurrentLegDate_ptr->getBoardingPoint()
00096               == lPreviousLegDate_ptr->getOffPoint());
00097       const stdair::Duration_T& lStopOverTime =
00098         lCurrentLegDate_ptr->getBoardingTime() - lPreviousLegDate_ptr->getOffTime();
00099       lElapsedTime += lStopOverTime;
00100 
00101       // Add the elapsed time of the current leg
00102       const stdair::Duration_T& currentElapsedTime =
00103         lCurrentLegDate_ptr->getElapsedTime();
00104       lElapsedTime += currentElapsedTime;
00105     }
00106       
00107     // Store the result
00108     ioSegmentDate.setElapsedTime (lElapsedTime);
00109     // From the elapsed time, update the distance
00110     updateDistanceFromElapsedTime (ioSegmentDate);
00111   }
00112 
00113   // //////////////////////////////////////////////////////////////////////
00114   void SegmentDateHelper::
00115   updateDistanceFromElapsedTime (stdair::SegmentDate& ioSegmentDate) {
00116     const stdair::Duration_T& lElapsedTime = ioSegmentDate.getElapsedTime();
00117     const double lElapseInHours=static_cast<const double>(lElapsedTime.hours());
00118     const long int lDistance =
00119       static_cast<const long int>(stdair::DEFAULT_FLIGHT_SPEED*lElapseInHours);
00120     ioSegmentDate.setDistance (lDistance);
00121   }
00122 
00123 }