StdAir Logo  1.00.3
C++ Standard Airline IT Object Library
LegDate.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // StdAir
13 #include <stdair/bom/LegCabin.hpp>
14 #include <stdair/bom/LegDate.hpp>
15 
16 namespace stdair {
17 
18  // ////////////////////////////////////////////////////////////////////
19  LegDate::LegDate() : _key (DEFAULT_ORIGIN), _parent (NULL) {
20  assert (false);
21  }
22 
23  // ////////////////////////////////////////////////////////////////////
24  LegDate::LegDate (const LegDate& iLegDate) :
25  _key (iLegDate._key),
26  _parent (NULL),
27  _offPoint (iLegDate._offPoint),
28  _boardingDate (iLegDate._boardingDate),
29  _boardingTime (iLegDate._boardingTime),
30  _offDate (iLegDate._offDate),
31  _offTime (iLegDate._offTime ),
32  _elapsedTime (iLegDate._elapsedTime),
33  _distance (iLegDate._distance),
34  _capacity (iLegDate._capacity) {
35  }
36 
37  // ////////////////////////////////////////////////////////////////////
38  LegDate::LegDate (const Key_T& iKey)
39  : _key (iKey), _parent (NULL), _distance (DEFAULT_DISTANCE_VALUE),
40  _capacity (DEFAULT_CABIN_CAPACITY) {
41  }
42 
43  // ////////////////////////////////////////////////////////////////////
45  }
46 
47  // ////////////////////////////////////////////////////////////////////
49  const FlightDate* lFlightDate_ptr =
50  static_cast<const FlightDate*> (getParent());
51  assert (lFlightDate_ptr != NULL);
52  return lFlightDate_ptr->getAirlineCode();
53  }
54 
55  // ////////////////////////////////////////////////////////////////////
56  std::string LegDate::toString() const {
57  std::ostringstream oStr;
58  oStr << describeKey();
59  return oStr.str();
60  }
61 
62  // ////////////////////////////////////////////////////////////////////
63  const std::string LegDate::describeRoutingKey() const {
64  const FlightDate* lFlightDate_ptr =
65  static_cast<const FlightDate*> (getParent());
66  assert (lFlightDate_ptr != NULL);
67  std::ostringstream oStr;
70  << lFlightDate_ptr->getDepartureDate() << DEFAULT_KEY_FLD_DELIMITER
71  << describeKey();
72  return oStr.str();
73  }
74 
75  // ////////////////////////////////////////////////////////////////////
76  LegCabin* LegDate::getLegCabin (const std::string& iLegCabinKeyStr) const {
77  LegCabin* oLegCabin_ptr =
78  BomManager::getObjectPtr<LegCabin> (*this, iLegCabinKeyStr);
79  return oLegCabin_ptr;
80  }
81 
82  // ////////////////////////////////////////////////////////////////////
83  LegCabin* LegDate::getLegCabin (const LegCabinKey& iLegCabinKey) const {
84  return getLegCabin (iLegCabinKey.toString());
85  }
86 
87  // ////////////////////////////////////////////////////////////////////
89  // TimeOffset = (OffTime - BoardingTime) + (OffDate - BoardingDate) * 24
90  // - ElapsedTime
91  Duration_T oTimeOffset = (_offTime - _boardingTime);
92 
93  const DateOffset_T& lDateOffset = getDateOffset();
94 
95  const Duration_T lDateOffsetInHours (lDateOffset.days() * 24, 0, 0);
96 
97  oTimeOffset += lDateOffsetInHours - _elapsedTime;
98 
99  return oTimeOffset;
100  }
101 
102  // ////////////////////////////////////////////////////////////////////
103  void LegDate::setElapsedTime (const Duration_T& iElapsedTime) {
104  // Set Elapsed time
105  _elapsedTime = iElapsedTime;
106 
107  // Update distance according to the mean plane speed
108  updateDistanceFromElapsedTime();
109  }
110 
111  // ////////////////////////////////////////////////////////////////////
112  void LegDate::updateDistanceFromElapsedTime() {
113  //
114  const double lElapseInHours =
115  static_cast<const double> (_elapsedTime.hours());
116 
117  // Normally, Distance_T is an unsigned long int
118  const Distance_T lDistance =
119  static_cast<const Distance_T> (DEFAULT_FLIGHT_SPEED * lElapseInHours);
120 
121  _distance = lDistance;
122  }
123 
124 }
125 
BomAbstract *const getParent() const
Definition: LegDate.hpp:44
virtual ~LegDate()
Definition: LegDate.cpp:44
const Distance_T DEFAULT_DISTANCE_VALUE
const Date_T & getDepartureDate() const
Definition: FlightDate.hpp:67
Class representing the actual attributes for an airline leg-cabin.
Definition: LegCabin.hpp:25
const AirportCode_T DEFAULT_ORIGIN
const std::string toString() const
Definition: LegCabinKey.cpp:46
FlightNumber_T _operatingFlightNumber
Definition: LegDate.hpp:267
const unsigned int DEFAULT_FLIGHT_SPEED
Handle on the StdAir library context.
boost::posix_time::time_duration Duration_T
const CabinCapacity_T DEFAULT_CABIN_CAPACITY
const std::string describeKey() const
Definition: LegDate.hpp:207
const std::string DEFAULT_KEY_FLD_DELIMITER
LegCabin * getLegCabin(const std::string &iLegCabinKeyStr) const
Definition: LegDate.cpp:76
const Duration_T getTimeOffset() const
Definition: LegDate.cpp:88
std::string AirlineCode_T
std::string toString() const
Definition: LegDate.cpp:56
AirlineCode_T _operatingAirlineCode
Definition: LegDate.hpp:264
const AirlineCode_T & getAirlineCode() const
Definition: FlightDate.cpp:37
const std::string describeRoutingKey() const
Definition: LegDate.cpp:63
Duration_T _boardingTime
Definition: LegDate.hpp:246
const AirlineCode_T & getAirlineCode() const
Definition: LegDate.cpp:48
Duration_T _elapsedTime
Definition: LegDate.hpp:255
Duration_T _offTime
Definition: LegDate.hpp:252
Key of a given leg-cabin, made of a cabin code (only).
Definition: LegCabinKey.hpp:26
boost::gregorian::date_duration DateOffset_T
Distance_T _distance
Definition: LegDate.hpp:258
const DateOffset_T getDateOffset() const
Definition: LegDate.hpp:134
Class representing the actual attributes for an airline flight-date.
Definition: FlightDate.hpp:35
void setElapsedTime(const Duration_T &)
Definition: LegDate.cpp:103
unsigned long int Distance_T