$treeview $search $mathjax
StdAir Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

stdair/bom/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/basic/BasConst_BomDisplay.hpp>
00011 #include <stdair/bom/BomManager.hpp>
00012 #include <stdair/bom/FlightDate.hpp>
00013 #include <stdair/bom/LegCabin.hpp>
00014 #include <stdair/bom/LegDate.hpp>
00015 
00016 namespace stdair {
00017 
00018   // ////////////////////////////////////////////////////////////////////
00019   LegDate::LegDate() : _key (DEFAULT_ORIGIN), _parent (NULL) {
00020     assert (false);
00021   }
00022 
00023   // ////////////////////////////////////////////////////////////////////
00024   LegDate::LegDate (const LegDate& iLegDate) :
00025     _key (iLegDate._key),
00026     _parent (NULL),
00027     _offPoint (iLegDate._offPoint),
00028     _boardingDate (iLegDate._boardingDate),
00029     _boardingTime (iLegDate._boardingTime),
00030     _offDate (iLegDate._offDate),
00031     _offTime (iLegDate._offTime ),
00032     _elapsedTime (iLegDate._elapsedTime),
00033     _distance (iLegDate._distance),
00034     _capacity (iLegDate._capacity) {
00035   }
00036 
00037   // ////////////////////////////////////////////////////////////////////
00038   LegDate::LegDate (const Key_T& iKey) 
00039     : _key (iKey), _parent (NULL), _distance (DEFAULT_DISTANCE_VALUE),
00040       _capacity (DEFAULT_CABIN_CAPACITY) {
00041   }
00042 
00043   // ////////////////////////////////////////////////////////////////////
00044   LegDate::~LegDate () {
00045   }
00046 
00047   // ////////////////////////////////////////////////////////////////////
00048   const AirlineCode_T& LegDate::getAirlineCode() const {
00049     const FlightDate* lFlightDate_ptr =
00050       static_cast<const FlightDate*> (getParent());
00051     assert (lFlightDate_ptr != NULL);
00052     return lFlightDate_ptr->getAirlineCode();
00053   }
00054 
00055   // ////////////////////////////////////////////////////////////////////
00056   std::string LegDate::toString() const {
00057     std::ostringstream oStr;
00058     oStr << describeKey();
00059     return oStr.str();
00060   } 
00061 
00062   // ////////////////////////////////////////////////////////////////////
00063   const std::string LegDate::describeRoutingKey() const {  
00064     const FlightDate* lFlightDate_ptr =
00065       static_cast<const FlightDate*> (getParent());
00066     assert (lFlightDate_ptr != NULL); 
00067     std::ostringstream oStr;
00068     oStr << _operatingAirlineCode << DEFAULT_KEY_FLD_DELIMITER
00069          << _operatingFlightNumber << DEFAULT_KEY_FLD_DELIMITER
00070          << lFlightDate_ptr->getDepartureDate() << DEFAULT_KEY_FLD_DELIMITER 
00071          << describeKey();
00072     return oStr.str();
00073   }
00074 
00075   // ////////////////////////////////////////////////////////////////////
00076   LegCabin* LegDate::getLegCabin (const std::string& iLegCabinKeyStr) const {
00077     LegCabin* oLegCabin_ptr =
00078       BomManager::getObjectPtr<LegCabin> (*this, iLegCabinKeyStr);
00079     return oLegCabin_ptr;
00080   }
00081 
00082   // ////////////////////////////////////////////////////////////////////
00083   LegCabin* LegDate::getLegCabin (const LegCabinKey& iLegCabinKey) const {
00084     return getLegCabin (iLegCabinKey.toString());
00085   }
00086 
00087   // ////////////////////////////////////////////////////////////////////
00088   const Duration_T LegDate::getTimeOffset() const {
00089     // TimeOffset = (OffTime - BoardingTime) + (OffDate - BoardingDate) * 24
00090     //              - ElapsedTime
00091     Duration_T oTimeOffset = (_offTime - _boardingTime);
00092 
00093     const DateOffset_T& lDateOffset = getDateOffset();
00094 
00095     const Duration_T lDateOffsetInHours (lDateOffset.days() * 24, 0, 0);
00096 
00097     oTimeOffset += lDateOffsetInHours - _elapsedTime;
00098 
00099     return oTimeOffset;
00100   }
00101   
00102   // ////////////////////////////////////////////////////////////////////
00103   void LegDate::setElapsedTime (const Duration_T& iElapsedTime) {
00104     // Set Elapsed time
00105     _elapsedTime = iElapsedTime;
00106 
00107     // Update distance according to the mean plane speed
00108     updateDistanceFromElapsedTime();
00109   }
00110 
00111   // ////////////////////////////////////////////////////////////////////
00112   void LegDate::updateDistanceFromElapsedTime() {
00113     //
00114     const double lElapseInHours =
00115       static_cast<const double> (_elapsedTime.hours());
00116 
00117     // Normally, Distance_T is an unsigned long int
00118     const Distance_T lDistance =
00119       static_cast<const Distance_T> (DEFAULT_FLIGHT_SPEED * lElapseInHours);
00120     
00121     _distance = lDistance;
00122   }
00123   
00124 }
00125