AirSched Logo  0.1.4
C++ Simulated Airline Schedule Manager Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InventoryGenerator.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // Boost
7 #include <boost/date_time/date_iterator.hpp>
8 // StdAir
9 #include <stdair/stdair_basic_types.hpp>
10 #include <stdair/basic/BasConst_Inventory.hpp>
11 #include <stdair/bom/BomManager.hpp>
12 #include <stdair/bom/BomRoot.hpp>
13 #include <stdair/bom/Inventory.hpp>
14 #include <stdair/bom/FlightPeriod.hpp>
15 #include <stdair/bom/SegmentPeriod.hpp>
16 #include <stdair/factory/FacBomManager.hpp>
17 #include <stdair/service/Logger.hpp>
18 // AirSched
22 
23 namespace AIRSCHED {
24 
25  // ////////////////////////////////////////////////////////////////////
26  void InventoryGenerator::
27  createFlightPeriod (stdair::BomRoot& ioBomRoot,
28  const FlightPeriodStruct& iFlightPeriodStruct) {
29 
30  const stdair::AirlineCode_T& lAirlineCode = iFlightPeriodStruct._airlineCode;
31 
32  // Instantiate an inventory object (if not exist)
33  // for the given key (airline code)
34  stdair::Inventory* lInventory_ptr = stdair::BomManager::
35  getObjectPtr<stdair::Inventory> (ioBomRoot, lAirlineCode);
36  if (lInventory_ptr == NULL) {
37  stdair::InventoryKey lKey (lAirlineCode);
38 
39  lInventory_ptr =
40  &stdair::FacBom<stdair::Inventory>::instance().create (lKey);
41  stdair::FacBomManager::addToListAndMap (ioBomRoot, *lInventory_ptr);
42  stdair::FacBomManager::linkWithParent (ioBomRoot, *lInventory_ptr);
43  }
44  assert (lInventory_ptr != NULL);
45 
46  // Create the flight-period key.
47  const stdair::PeriodStruct lPeriod (iFlightPeriodStruct._dateRange,
48  iFlightPeriodStruct._dow);
49  const stdair::FlightPeriodKey
50  lFlightPeriodKey (iFlightPeriodStruct._flightNumber, lPeriod);
51 
52  // Check that the flight-period object is not already created.
53  stdair::FlightPeriod* lFlightPeriod_ptr = stdair::BomManager::
54  getObjectPtr<stdair::FlightPeriod> (*lInventory_ptr,
55  lFlightPeriodKey.toString());
56  if (lFlightPeriod_ptr != NULL) {
57  throw stdair::ObjectCreationgDuplicationException ("");
58  }
59  assert (lFlightPeriod_ptr == NULL);
60 
61  // Instantiate a flight-period object with the given key.
62  lFlightPeriod_ptr = &stdair::FacBom<stdair::FlightPeriod>::
63  instance().create (lFlightPeriodKey);
64  stdair::FacBomManager::addToListAndMap (*lInventory_ptr, *lFlightPeriod_ptr);
65  stdair::FacBomManager::linkWithParent (*lInventory_ptr, *lFlightPeriod_ptr);
66 
67  // Create the segment-periods.
68  createSegmentPeriods (*lFlightPeriod_ptr, iFlightPeriodStruct);
69  }
70 
71  // ////////////////////////////////////////////////////////////////////
72  void InventoryGenerator::
73  createSegmentPeriods (stdair::FlightPeriod& ioFlightPeriod,
74  const FlightPeriodStruct& iFlightPeriodStruct) {
75 
76  // Iterate on the segment strutures.
77  const SegmentStructList_T& lSegmentList = iFlightPeriodStruct._segmentList;
78  for (SegmentStructList_T::const_iterator itSegment = lSegmentList.begin();
79  itSegment != lSegmentList.end(); ++itSegment) {
80 
81  const SegmentStruct& lSegment = *itSegment;
82 
83  // Set the segment-period primary key.
84  const stdair::AirportCode_T& lBoardingPoint = lSegment._boardingPoint;
85  const stdair::AirportCode_T& lOffPoint = lSegment._offPoint;
86  const stdair::SegmentPeriodKey lSegmentPeriodKey (lBoardingPoint,
87  lOffPoint);
88 
89  // Instantiate a segment-perioed with the key.
90  stdair::SegmentPeriod& lSegmentPeriod = stdair::
91  FacBom<stdair::SegmentPeriod>::instance().create (lSegmentPeriodKey);
92  stdair::FacBomManager::addToListAndMap (ioFlightPeriod, lSegmentPeriod);
93  stdair::FacBomManager::linkWithParent (ioFlightPeriod, lSegmentPeriod);
94 
95  // Set the segment-period attributes.
96  SegmentPeriodHelper::fill (lSegmentPeriod, lSegment);
97  SegmentPeriodHelper::fill (lSegmentPeriod, iFlightPeriodStruct._legList);
98  }
99  }
100 
101 }