AirInv Logo  1.00.0
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  return;
28  }
29  // Retrieve the first and the last legs of the routing.
30  // Note that in the majority of the cases, as flights are mono-legs,
31  // the first and last legs are thus the same.
32  const stdair::LegDateList_T& lLegDateList =
33  stdair::BomManager::getList<stdair::LegDate> (ioSegmentDate);
34  stdair::LegDateList_T::const_iterator itFirstLeg = lLegDateList.begin();
35  const stdair::LegDate* lFirstLeg_ptr = *itFirstLeg;
36  assert (lFirstLeg_ptr != NULL);
37  stdair::LegDateList_T::const_reverse_iterator itLastLeg =
38  lLegDateList.rbegin();
39  const stdair::LegDate* lLastLeg_ptr = *itLastLeg;
40  assert (lLastLeg_ptr != NULL);
41 
42  // Set the Boarding Date
43  const stdair::Date_T& lBoardingDate = lFirstLeg_ptr->getBoardingDate();
44  ioSegmentDate.setBoardingDate (lBoardingDate);
45  // Set the Boarding Time
46  const stdair::Duration_T& lBoardingTime = lFirstLeg_ptr->getBoardingTime();
47  ioSegmentDate.setBoardingTime (lBoardingTime);
48  // Set the Off Date
49  const stdair::Date_T& lOffDate = lLastLeg_ptr->getOffDate();
50  ioSegmentDate.setOffDate (lOffDate);
51  // Set the Off Time
52  const stdair::Duration_T& lOffTime = lLastLeg_ptr->getOffTime();
53  ioSegmentDate.setOffTime (lOffTime);
54  // Set the Elapsed Time for the whole path
55  updateElapsedTimeFromRouting (ioSegmentDate);
56 
57  // Initialise the AU for all classes.
58  const stdair::SegmentCabinList_T& lSegmentCabinList =
59  stdair::BomManager::getList<stdair::SegmentCabin> (ioSegmentDate);
60  for (stdair::SegmentCabinList_T::const_iterator itSC =
61  lSegmentCabinList.begin(); itSC != lSegmentCabinList.end(); ++itSC) {
62  stdair::SegmentCabin* lSC_ptr = *itSC;
63  assert (lSC_ptr != NULL);
64 
65  // Initialise the AU for children booking classes.
67  }
68  }
69 
70  // //////////////////////////////////////////////////////////////////////
72  updateElapsedTimeFromRouting (stdair::SegmentDate& ioSegmentDate) {
73 
74  const stdair::LegDateList_T& lLegDateList =
75  stdair::BomManager::getList<stdair::LegDate> (ioSegmentDate);
76 
77  stdair::LegDateList_T::const_iterator itLegDate = lLegDateList.begin();
78  const stdair::LegDate* lCurrentLegDate_ptr = *itLegDate;
79  assert (lCurrentLegDate_ptr != NULL);
80 
81  // Retrieve the elapsed time of the first leg
82  stdair::Duration_T lElapsedTime = lCurrentLegDate_ptr->getElapsedTime();
83 
84  // Go to the next leg, if existing. If not existing, the following
85  // loop will not be entered (as it means: currentLeg == _legDateList.end()).
86  ++itLegDate;
87 
88  for (const stdair::LegDate* lPreviousLegDate_ptr = lCurrentLegDate_ptr;
89  itLegDate != lLegDateList.end();
90  ++itLegDate, lPreviousLegDate_ptr = lCurrentLegDate_ptr) {
91  lCurrentLegDate_ptr = *itLegDate;
92 
93  // As the boarding point of the current leg is the same as the off point
94  // of the previous leg (by construction), there is no time difference.
95  assert (lCurrentLegDate_ptr->getBoardingPoint()
96  == lPreviousLegDate_ptr->getOffPoint());
97  const stdair::Duration_T& lStopOverTime =
98  lCurrentLegDate_ptr->getBoardingTime() - lPreviousLegDate_ptr->getOffTime();
99  lElapsedTime += lStopOverTime;
100 
101  // Add the elapsed time of the current leg
102  const stdair::Duration_T& currentElapsedTime =
103  lCurrentLegDate_ptr->getElapsedTime();
104  lElapsedTime += currentElapsedTime;
105  }
106 
107  // Store the result
108  ioSegmentDate.setElapsedTime (lElapsedTime);
109  // From the elapsed time, update the distance
110  updateDistanceFromElapsedTime (ioSegmentDate);
111  }
112 
113  // //////////////////////////////////////////////////////////////////////
115  updateDistanceFromElapsedTime (stdair::SegmentDate& ioSegmentDate) {
116  const stdair::Duration_T& lElapsedTime = ioSegmentDate.getElapsedTime();
117  const double lElapseInHours=static_cast<const double>(lElapsedTime.hours());
118  const long int lDistance =
119  static_cast<const long int>(stdair::DEFAULT_FLIGHT_SPEED*lElapseInHours);
120  ioSegmentDate.setDistance (lDistance);
121  }
122 
123 }