AirTSP Logo  1.01.0
C++ Simulated Airline Travel Solution Provider Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SegmentPeriodHelper.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/SegmentPeriod.hpp>
9 // AirTSP
11 
12 namespace AIRTSP {
13  // ////////////////////////////////////////////////////////////////////
14  void SegmentPeriodHelper::fill (stdair::SegmentPeriod& ioSegmentPeriod,
15  const SegmentStruct& iSegmentStruct) {
16  // Browse the list of segment cabins and fill the cabin booking
17  // class map of the BOM segment period.
18  for (SegmentCabinStructList_T::const_iterator itCabin =
19  iSegmentStruct._cabinList.begin();
20  itCabin != iSegmentStruct._cabinList.end(); ++itCabin) {
21  const SegmentCabinStruct& lSegmentCabinStruct = *itCabin;
22  ioSegmentPeriod.
23  addCabinBookingClassList (lSegmentCabinStruct._cabinCode,
24  lSegmentCabinStruct._classes);
25  }
26  }
27 
28  // ////////////////////////////////////////////////////////////////////
29  void SegmentPeriodHelper::fill (stdair::SegmentPeriod& ioSegmentPeriod,
30  const LegStructList_T& iLegList) {
31 
32  const stdair::AirportCode_T& lBoardingPoint =
33  ioSegmentPeriod.getBoardingPoint ();
34  const stdair::AirportCode_T& lOffPoint = ioSegmentPeriod.getOffPoint();
35  stdair::Duration_T lElapsedTime;
36 
37  // Find the leg which has the same boarding point.
38  LegStructList_T::const_iterator itLeg = iLegList.begin ();
39  while (itLeg != iLegList.end()) {
40  const LegStruct& lLeg = *itLeg;
41  if (lLeg._boardingPoint == lBoardingPoint) {
42  break;
43  } else {
44  ++itLeg;
45  }
46  }
47  assert (itLeg != iLegList.end());
48  const LegStruct& lFirstLeg = *itLeg;
49  stdair::AirportCode_T lCurrentOffPoint = lFirstLeg._offPoint;
50  stdair::Duration_T lCurrentOffTime = lFirstLeg._offTime;
51 
52  // Update the elapsed time.
53  lElapsedTime += lFirstLeg._elapsed;
54 
55  // Find the last used leg.
56  while (lCurrentOffPoint != lOffPoint) {
57  ++itLeg;
58  assert (itLeg != iLegList.end());
59 
60  const LegStruct& lCurrentLeg = *itLeg;
61  assert (lCurrentOffPoint == lCurrentLeg._boardingPoint);
62  // As the boarding point of the current leg is the same as the off point
63  // of the previous leg (by construction), there is no time difference.
64  const stdair::Duration_T lStopOverTime =
65  lCurrentLeg._boardingTime - lCurrentOffTime;
66  lElapsedTime += lStopOverTime;
67 
68  // Add the elapsed time of the current leg
69  lElapsedTime += lCurrentLeg._elapsed;
70 
71  lCurrentOffTime = lCurrentLeg._offTime;
72  lCurrentOffPoint = lCurrentLeg._offPoint;
73  }
74  const LegStruct& lLastLeg = *itLeg;
75 
76  // Update the attributes of the segment-period.
77  ioSegmentPeriod.setBoardingTime (lFirstLeg._boardingTime);
78  ioSegmentPeriod.setOffTime (lLastLeg._offTime);
79  ioSegmentPeriod.setBoardingDateOffset (lFirstLeg._boardingDateOffset);
80  ioSegmentPeriod.setOffDateOffset (lLastLeg._offDateOffset);
81  ioSegmentPeriod.setElapsedTime (lElapsedTime);
82  }
83 
84 }