StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LegDate.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // StdAir
12 #include <stdair/bom/LegCabin.hpp>
13 #include <stdair/bom/LegDate.hpp>
14 
15 namespace stdair {
16 
17  // ////////////////////////////////////////////////////////////////////
18  LegDate::LegDate() : _key (DEFAULT_ORIGIN), _parent (NULL) {
19  assert (false);
20  }
21 
22  // ////////////////////////////////////////////////////////////////////
23  LegDate::LegDate (const LegDate&) : _key (DEFAULT_ORIGIN), _parent (NULL) {
24  assert (false);
25  }
26 
27  // ////////////////////////////////////////////////////////////////////
28  LegDate::LegDate (const Key_T& iKey)
29  : _key (iKey), _parent (NULL), _distance (DEFAULT_DISTANCE_VALUE),
30  _capacity (DEFAULT_CABIN_CAPACITY) {
31  }
32 
33  // ////////////////////////////////////////////////////////////////////
35  }
36 
37  // ////////////////////////////////////////////////////////////////////
39  const FlightDate* lFlightDate_ptr =
40  static_cast<const FlightDate*> (getParent());
41  assert (lFlightDate_ptr != NULL);
42  return lFlightDate_ptr->getAirlineCode();
43  }
44 
45  // ////////////////////////////////////////////////////////////////////
46  std::string LegDate::toString() const {
47  std::ostringstream oStr;
48  oStr << describeKey();
49  return oStr.str();
50  }
51 
52  // ////////////////////////////////////////////////////////////////////
53  LegCabin* LegDate::getLegCabin (const std::string& iLegCabinKeyStr) const {
54  LegCabin* oLegCabin_ptr =
55  BomManager::getObjectPtr<LegCabin> (*this, iLegCabinKeyStr);
56  return oLegCabin_ptr;
57  }
58 
59  // ////////////////////////////////////////////////////////////////////
60  LegCabin* LegDate::getLegCabin (const LegCabinKey& iLegCabinKey) const {
61  return getLegCabin (iLegCabinKey.toString());
62  }
63 
64  // ////////////////////////////////////////////////////////////////////
66  // TimeOffset = (OffTime - BoardingTime) + (OffDate - BoardingDate) * 24
67  // - ElapsedTime
68  Duration_T oTimeOffset = (_offTime - _boardingTime);
69 
70  const DateOffset_T& lDateOffset = getDateOffset();
71 
72  const Duration_T lDateOffsetInHours (lDateOffset.days() * 24, 0, 0);
73 
74  oTimeOffset += lDateOffsetInHours - _elapsedTime;
75 
76  return oTimeOffset;
77  }
78 
79  // ////////////////////////////////////////////////////////////////////
80  void LegDate::setElapsedTime (const Duration_T& iElapsedTime) {
81  // Set Elapsed time
82  _elapsedTime = iElapsedTime;
83 
84  // Update distance according to the mean plane speed
85  updateDistanceFromElapsedTime();
86  }
87 
88  // ////////////////////////////////////////////////////////////////////
89  void LegDate::updateDistanceFromElapsedTime() {
90  //
91  const double lElapseInHours =
92  static_cast<const double> (_elapsedTime.hours());
93 
94  // Normally, Distance_T is an unsigned long int
95  const Distance_T lDistance =
96  static_cast<const Distance_T> (DEFAULT_FLIGHT_SPEED * lElapseInHours);
97 
98  _distance = lDistance;
99  }
100 
101 }
102