$treeview $search $mathjax
AirTSP Logo  1.01.2
$projectbrief
$projectbrief
$searchbox

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/AirlineFeature.hpp>
00015 #include <stdair/bom/FlightPeriod.hpp>
00016 #include <stdair/bom/SegmentPeriod.hpp>
00017 #include <stdair/factory/FacBomManager.hpp>
00018 #include <stdair/service/Logger.hpp>
00019 // AirTSP
00020 #include <airtsp/bom/FlightPeriodStruct.hpp>
00021 #include <airtsp/bom/SegmentPeriodHelper.hpp>
00022 #include <airtsp/command/InventoryGenerator.hpp>
00023 
00024 namespace AIRTSP {
00025   
00026   // ////////////////////////////////////////////////////////////////////
00027   void InventoryGenerator::
00028   createFlightPeriod (stdair::BomRoot& ioBomRoot,
00029                       const FlightPeriodStruct& iFlightPeriodStruct) {
00030       
00031     const stdair::AirlineCode_T& lAirlineCode = iFlightPeriodStruct._airlineCode;
00032     
00033     // Instantiate an inventory object (if not exist)
00034     // for the given key (airline code)
00035     stdair::Inventory* lInventory_ptr = stdair::BomManager::
00036       getObjectPtr<stdair::Inventory> (ioBomRoot, lAirlineCode);
00037     if (lInventory_ptr == NULL) {
00038       stdair::InventoryKey lKey (lAirlineCode);
00039 
00040       lInventory_ptr =
00041         &stdair::FacBom<stdair::Inventory>::instance().create (lKey);
00042       stdair::FacBomManager::addToListAndMap (ioBomRoot, *lInventory_ptr);
00043       stdair::FacBomManager::linkWithParent (ioBomRoot, *lInventory_ptr);
00044 
00045       // Add the airline feature object to the inventory
00046       const stdair::AirlineFeatureKey lAirlineFeatureKey (lAirlineCode);
00047       stdair::AirlineFeature& lAirlineFeature =
00048         stdair::FacBom<stdair::AirlineFeature>::instance().create (lAirlineFeatureKey);
00049       stdair::FacBomManager::setAirlineFeature (*lInventory_ptr,
00050                                                 lAirlineFeature);
00051       stdair::FacBomManager::linkWithParent (*lInventory_ptr, lAirlineFeature);
00052       // Link the airline feature object with the top of the BOM tree
00053       stdair::FacBomManager::addToListAndMap (ioBomRoot, lAirlineFeature);
00054     }
00055     assert (lInventory_ptr != NULL);
00056 
00057     // Create the flight-period key.
00058     const stdair::PeriodStruct lPeriod (iFlightPeriodStruct._dateRange,
00059                                         iFlightPeriodStruct._dow);
00060     const stdair::FlightPeriodKey
00061       lFlightPeriodKey (iFlightPeriodStruct._flightNumber, lPeriod);
00062       
00063     // Check that the flight-period object is not already created.
00064     stdair::FlightPeriod* lFlightPeriod_ptr = stdair::BomManager::
00065       getObjectPtr<stdair::FlightPeriod> (*lInventory_ptr, 
00066                                           lFlightPeriodKey.toString());
00067     if (lFlightPeriod_ptr != NULL) {
00068       throw stdair::ObjectCreationgDuplicationException ("");
00069     }
00070     assert (lFlightPeriod_ptr == NULL);
00071 
00072     // Instantiate a flight-period object with the given key.
00073     lFlightPeriod_ptr = &stdair::FacBom<stdair::FlightPeriod>::
00074       instance().create (lFlightPeriodKey);
00075     stdair::FacBomManager::addToListAndMap (*lInventory_ptr, *lFlightPeriod_ptr);
00076     stdair::FacBomManager::linkWithParent (*lInventory_ptr, *lFlightPeriod_ptr);
00077     
00078     // Create the segment-periods.
00079     createSegmentPeriods (*lFlightPeriod_ptr, iFlightPeriodStruct);
00080   }
00081 
00082   // ////////////////////////////////////////////////////////////////////
00083   void InventoryGenerator::
00084   createSegmentPeriods (stdair::FlightPeriod& ioFlightPeriod,
00085                         const FlightPeriodStruct& iFlightPeriodStruct) {
00086 
00087     // Iterate on the segment strutures.
00088     const SegmentStructList_T& lSegmentList = iFlightPeriodStruct._segmentList;
00089     for (SegmentStructList_T::const_iterator itSegment = lSegmentList.begin();
00090          itSegment != lSegmentList.end(); ++itSegment) {
00091 
00092       const SegmentStruct& lSegment = *itSegment;
00093 
00094       // Set the segment-period primary key.
00095       const stdair::AirportCode_T& lBoardingPoint = lSegment._boardingPoint;
00096       const stdair::AirportCode_T& lOffPoint = lSegment._offPoint;
00097       const stdair::SegmentPeriodKey lSegmentPeriodKey (lBoardingPoint,
00098                                                           lOffPoint);
00099 
00100       // Instantiate a segment-perioed with the key.
00101       stdair::SegmentPeriod& lSegmentPeriod = stdair::
00102         FacBom<stdair::SegmentPeriod>::instance().create (lSegmentPeriodKey);
00103       stdair::FacBomManager::addToListAndMap (ioFlightPeriod, lSegmentPeriod);
00104       stdair::FacBomManager::linkWithParent (ioFlightPeriod, lSegmentPeriod);
00105       
00106       // Set the segment-period attributes.
00107       SegmentPeriodHelper::fill (lSegmentPeriod, lSegment);
00108       SegmentPeriodHelper::fill (lSegmentPeriod, iFlightPeriodStruct._legList);
00109     }
00110   }
00111 
00112 }