AirSched Logo  0.1.4
C++ Simulated Airline Schedule Manager Library
InventoryGenerator.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // Boost
00007 #include <boost/date_time/date_iterator.hpp>
00008 // StdAir
00009 #include <stdair/stdair_basic_types.hpp>
00010 #include <stdair/basic/BasConst_Inventory.hpp>
00011 #include <stdair/bom/BomManager.hpp>
00012 #include <stdair/bom/BomRoot.hpp>
00013 #include <stdair/bom/Inventory.hpp>
00014 #include <stdair/bom/FlightPeriod.hpp>
00015 #include <stdair/bom/SegmentPeriod.hpp>
00016 #include <stdair/factory/FacBomManager.hpp>
00017 #include <stdair/service/Logger.hpp>
00018 // AirSched
00019 #include <airsched/bom/FlightPeriodStruct.hpp>
00020 #include <airsched/bom/SegmentPeriodHelper.hpp>
00021 #include <airsched/command/InventoryGenerator.hpp>
00022 
00023 namespace AIRSCHED {
00024   
00025   // ////////////////////////////////////////////////////////////////////
00026   void InventoryGenerator::
00027   createFlightPeriod (stdair::BomRoot& ioBomRoot,
00028                       const FlightPeriodStruct& iFlightPeriodStruct) {
00029       
00030     const stdair::AirlineCode_T& lAirlineCode = iFlightPeriodStruct._airlineCode;
00031     
00032     // Instantiate an inventory object (if not exist)
00033     // for the given key (airline code)
00034     stdair::Inventory* lInventory_ptr = stdair::BomManager::
00035       getObjectPtr<stdair::Inventory> (ioBomRoot, lAirlineCode);
00036     if (lInventory_ptr == NULL) {
00037       stdair::InventoryKey lKey (lAirlineCode);
00038 
00039       lInventory_ptr =
00040         &stdair::FacBom<stdair::Inventory>::instance().create (lKey);
00041       stdair::FacBomManager::addToListAndMap (ioBomRoot, *lInventory_ptr);
00042       stdair::FacBomManager::linkWithParent (ioBomRoot, *lInventory_ptr);
00043     }
00044     assert (lInventory_ptr != NULL);
00045 
00046     // Create the flight-period key.
00047     const stdair::PeriodStruct lPeriod (iFlightPeriodStruct._dateRange,
00048                                         iFlightPeriodStruct._dow);
00049     const stdair::FlightPeriodKey
00050       lFlightPeriodKey (iFlightPeriodStruct._flightNumber, lPeriod);
00051       
00052     // Check that the flight-period object is not already created.
00053     stdair::FlightPeriod* lFlightPeriod_ptr = stdair::BomManager::
00054       getObjectPtr<stdair::FlightPeriod> (*lInventory_ptr, 
00055                                           lFlightPeriodKey.toString());
00056     if (lFlightPeriod_ptr != NULL) {
00057       throw stdair::ObjectCreationgDuplicationException ("");
00058     }
00059     assert (lFlightPeriod_ptr == NULL);
00060 
00061     // Instantiate a flight-period object with the given key.
00062     lFlightPeriod_ptr = &stdair::FacBom<stdair::FlightPeriod>::
00063       instance().create (lFlightPeriodKey);
00064     stdair::FacBomManager::addToListAndMap (*lInventory_ptr, *lFlightPeriod_ptr);
00065     stdair::FacBomManager::linkWithParent (*lInventory_ptr, *lFlightPeriod_ptr);
00066     
00067     // Create the segment-periods.
00068     createSegmentPeriods (*lFlightPeriod_ptr, iFlightPeriodStruct);
00069   }
00070 
00071   // ////////////////////////////////////////////////////////////////////
00072   void InventoryGenerator::
00073   createSegmentPeriods (stdair::FlightPeriod& ioFlightPeriod,
00074                         const FlightPeriodStruct& iFlightPeriodStruct) {
00075 
00076     // Iterate on the segment strutures.
00077     const SegmentStructList_T& lSegmentList = iFlightPeriodStruct._segmentList;
00078     for (SegmentStructList_T::const_iterator itSegment = lSegmentList.begin();
00079          itSegment != lSegmentList.end(); ++itSegment) {
00080 
00081       const SegmentStruct& lSegment = *itSegment;
00082 
00083       // Set the segment-period primary key.
00084       const stdair::AirportCode_T& lBoardingPoint = lSegment._boardingPoint;
00085       const stdair::AirportCode_T& lOffPoint = lSegment._offPoint;
00086       const stdair::SegmentPeriodKey lSegmentPeriodKey (lBoardingPoint,
00087                                                           lOffPoint);
00088 
00089       // Instantiate a segment-perioed with the key.
00090       stdair::SegmentPeriod& lSegmentPeriod = stdair::
00091         FacBom<stdair::SegmentPeriod>::instance().create (lSegmentPeriodKey);
00092       stdair::FacBomManager::addToListAndMap (ioFlightPeriod, lSegmentPeriod);
00093       stdair::FacBomManager::linkWithParent (ioFlightPeriod, lSegmentPeriod);
00094       
00095       // Set the segment-period attributes.
00096       SegmentPeriodHelper::fill (lSegmentPeriod, lSegment);
00097       SegmentPeriodHelper::fill (lSegmentPeriod, iFlightPeriodStruct._legList);
00098     }
00099   }
00100 
00101 }