StdAir Logo  0.45.0
C++ Standard Airline IT Object Library
LegDate.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // StdAir
00008 #include <stdair/basic/BasConst_General.hpp>
00009 #include <stdair/basic/BasConst_Inventory.hpp>
00010 #include <stdair/bom/BomManager.hpp>
00011 #include <stdair/bom/FlightDate.hpp>
00012 #include <stdair/bom/LegCabin.hpp>
00013 #include <stdair/bom/LegDate.hpp>
00014 
00015 namespace stdair {
00016 
00017   // ////////////////////////////////////////////////////////////////////
00018   LegDate::LegDate() : _key (DEFAULT_ORIGIN), _parent (NULL) {
00019     assert (false);
00020   }
00021 
00022   // ////////////////////////////////////////////////////////////////////
00023   LegDate::LegDate (const LegDate&) : _key (DEFAULT_ORIGIN), _parent (NULL) {
00024     assert (false);
00025   }
00026 
00027   // ////////////////////////////////////////////////////////////////////
00028   LegDate::LegDate (const Key_T& iKey) 
00029     : _key (iKey), _parent (NULL), _distance (DEFAULT_DISTANCE_VALUE),
00030       _capacity (DEFAULT_CABIN_CAPACITY) {
00031   }
00032 
00033   // ////////////////////////////////////////////////////////////////////
00034   LegDate::~LegDate () {
00035   }
00036 
00037   // ////////////////////////////////////////////////////////////////////
00038   const AirlineCode_T& LegDate::getAirlineCode() const {
00039     const FlightDate* lFlightDate_ptr =
00040       static_cast<const FlightDate*> (getParent());
00041     assert (lFlightDate_ptr != NULL);
00042     return lFlightDate_ptr->getAirlineCode();
00043   }
00044 
00045   // ////////////////////////////////////////////////////////////////////
00046   std::string LegDate::toString() const {
00047     std::ostringstream oStr;
00048     oStr << describeKey();
00049     return oStr.str();
00050   }
00051 
00052   // ////////////////////////////////////////////////////////////////////
00053   LegCabin* LegDate::getLegCabin (const std::string& iLegCabinKeyStr) const {
00054     LegCabin* oLegCabin_ptr =
00055       BomManager::getObjectPtr<LegCabin> (*this, iLegCabinKeyStr);
00056     return oLegCabin_ptr;
00057   }
00058 
00059   // ////////////////////////////////////////////////////////////////////
00060   LegCabin* LegDate::getLegCabin (const LegCabinKey& iLegCabinKey) const {
00061     return getLegCabin (iLegCabinKey.toString());
00062   }
00063 
00064   // ////////////////////////////////////////////////////////////////////
00065   const Duration_T LegDate::getTimeOffset() const {
00066     // TimeOffset = (OffTime - BoardingTime) + (OffDate - BoardingDate) * 24
00067     //              - ElapsedTime
00068     Duration_T oTimeOffset = (_offTime - _boardingTime);
00069 
00070     const DateOffset_T& lDateOffset = getDateOffset();
00071 
00072     const Duration_T lDateOffsetInHours (lDateOffset.days() * 24, 0, 0);
00073 
00074     oTimeOffset += lDateOffsetInHours - _elapsedTime;
00075 
00076     return oTimeOffset;
00077   }
00078   
00079   // ////////////////////////////////////////////////////////////////////
00080   void LegDate::setElapsedTime (const Duration_T& iElapsedTime) {
00081     // Set Elapsed time
00082     _elapsedTime = iElapsedTime;
00083 
00084     // Update distance according to the mean plane speed
00085     updateDistanceFromElapsedTime();
00086   }
00087 
00088   // ////////////////////////////////////////////////////////////////////
00089   void LegDate::updateDistanceFromElapsedTime() {
00090     //
00091     const double lElapseInHours =
00092       static_cast<const double> (_elapsedTime.hours());
00093 
00094     // Normally, Distance_T is an unsigned long int
00095     const Distance_T lDistance =
00096       static_cast<const Distance_T> (DEFAULT_FLIGHT_SPEED * lElapseInHours);
00097     
00098     _distance = lDistance;
00099   }
00100   
00101 }
00102