AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SegmentDateHelper.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // STDAIR
7 #include <stdair/basic/BasConst_General.hpp>
8 #include <stdair/bom/BomManager.hpp>
9 #include <stdair/bom/SegmentDate.hpp>
10 #include <stdair/bom/SegmentCabin.hpp>
11 #include <stdair/bom/LegDate.hpp>
12 // AIRINV
15 
16 namespace AIRINV {
17  // ////////////////////////////////////////////////////////////////////
18  void SegmentDateHelper::fillFromRouting (stdair::SegmentDate& ioSegmentDate) {
19  /*
20  * If the segment is just marketed by this carrier,
21  * retrieve the operating segment and call the fillFromRouting
22  * method on it.
23  */
24  stdair::SegmentDate* lOperatingSegmentDate_ptr =
25  ioSegmentDate.getOperatingSegmentDate ();
26  if (lOperatingSegmentDate_ptr != NULL) {
27  fillFromRouting (*lOperatingSegmentDate_ptr);
28  return;
29  }
30  // Retrieve the first and the last legs of the routing.
31  // Note that in the majority of the cases, as flights are mono-legs,
32  // the first and last legs are thus the same.
33  const stdair::LegDateList_T& lLegDateList =
34  stdair::BomManager::getList<stdair::LegDate> (ioSegmentDate);
35  stdair::LegDateList_T::const_iterator itFirstLeg = lLegDateList.begin();
36  const stdair::LegDate* lFirstLeg_ptr = *itFirstLeg;
37  assert (lFirstLeg_ptr != NULL);
38  stdair::LegDateList_T::const_reverse_iterator itLastLeg =
39  lLegDateList.rbegin();
40  const stdair::LegDate* lLastLeg_ptr = *itLastLeg;
41  assert (lLastLeg_ptr != NULL);
42 
43  // Set the Boarding Date
44  const stdair::Date_T& lBoardingDate = lFirstLeg_ptr->getBoardingDate();
45  ioSegmentDate.setBoardingDate (lBoardingDate);
46  // Set the Boarding Time
47  const stdair::Duration_T& lBoardingTime = lFirstLeg_ptr->getBoardingTime();
48  ioSegmentDate.setBoardingTime (lBoardingTime);
49  // Set the Off Date
50  const stdair::Date_T& lOffDate = lLastLeg_ptr->getOffDate();
51  ioSegmentDate.setOffDate (lOffDate);
52  // Set the Off Time
53  const stdair::Duration_T& lOffTime = lLastLeg_ptr->getOffTime();
54  ioSegmentDate.setOffTime (lOffTime);
55  // Set the Elapsed Time for the whole path
56  updateElapsedTimeFromRouting (ioSegmentDate);
57 
58  // Initialise the AU for all classes.
59  const stdair::SegmentCabinList_T& lSegmentCabinList =
60  stdair::BomManager::getList<stdair::SegmentCabin> (ioSegmentDate);
61  for (stdair::SegmentCabinList_T::const_iterator itSC =
62  lSegmentCabinList.begin(); itSC != lSegmentCabinList.end(); ++itSC) {
63  stdair::SegmentCabin* lSC_ptr = *itSC;
64  assert (lSC_ptr != NULL);
65 
66  // Initialise the AU for children booking classes.
68  }
69  }
70 
71  // //////////////////////////////////////////////////////////////////////
73  updateElapsedTimeFromRouting (stdair::SegmentDate& ioSegmentDate) {
74 
75  const stdair::LegDateList_T& lLegDateList =
76  stdair::BomManager::getList<stdair::LegDate> (ioSegmentDate);
77 
78  stdair::LegDateList_T::const_iterator itLegDate = lLegDateList.begin();
79  const stdair::LegDate* lCurrentLegDate_ptr = *itLegDate;
80  assert (lCurrentLegDate_ptr != NULL);
81 
82  // Retrieve the elapsed time of the first leg
83  stdair::Duration_T lElapsedTime = lCurrentLegDate_ptr->getElapsedTime();
84 
85  // Go to the next leg, if existing. If not existing, the following
86  // loop will not be entered (as it means: currentLeg == _legDateList.end()).
87  ++itLegDate;
88 
89  for (const stdair::LegDate* lPreviousLegDate_ptr = lCurrentLegDate_ptr;
90  itLegDate != lLegDateList.end();
91  ++itLegDate, lPreviousLegDate_ptr = lCurrentLegDate_ptr) {
92  lCurrentLegDate_ptr = *itLegDate;
93 
94  // As the boarding point of the current leg is the same as the off point
95  // of the previous leg (by construction), there is no time difference.
96  assert (lCurrentLegDate_ptr->getBoardingPoint()
97  == lPreviousLegDate_ptr->getOffPoint());
98  const stdair::Duration_T& lStopOverTime =
99  lCurrentLegDate_ptr->getBoardingTime() - lPreviousLegDate_ptr->getOffTime();
100  lElapsedTime += lStopOverTime;
101 
102  // Add the elapsed time of the current leg
103  const stdair::Duration_T& currentElapsedTime =
104  lCurrentLegDate_ptr->getElapsedTime();
105  lElapsedTime += currentElapsedTime;
106  }
107 
108  // Store the result
109  ioSegmentDate.setElapsedTime (lElapsedTime);
110  // From the elapsed time, update the distance
111  updateDistanceFromElapsedTime (ioSegmentDate);
112  }
113 
114  // //////////////////////////////////////////////////////////////////////
116  updateDistanceFromElapsedTime (stdair::SegmentDate& ioSegmentDate) {
117  const stdair::Duration_T& lElapsedTime = ioSegmentDate.getElapsedTime();
118  const double lElapseInHours=static_cast<const double>(lElapsedTime.hours());
119  const long int lDistance =
120  static_cast<const long int>(stdair::DEFAULT_FLIGHT_SPEED*lElapseInHours);
121  ioSegmentDate.setDistance (lDistance);
122  }
123 
124 }