AirTSP Logo  1.01.0
C++ Simulated Airline Travel Solution Provider 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/AirlineFeature.hpp>
15 #include <stdair/bom/FlightPeriod.hpp>
16 #include <stdair/bom/SegmentPeriod.hpp>
17 #include <stdair/factory/FacBomManager.hpp>
18 #include <stdair/service/Logger.hpp>
19 // AirTSP
23 
24 namespace AIRTSP {
25 
26  // ////////////////////////////////////////////////////////////////////
27  void InventoryGenerator::
28  createFlightPeriod (stdair::BomRoot& ioBomRoot,
29  const FlightPeriodStruct& iFlightPeriodStruct) {
30 
31  const stdair::AirlineCode_T& lAirlineCode = iFlightPeriodStruct._airlineCode;
32 
33  // Instantiate an inventory object (if not exist)
34  // for the given key (airline code)
35  stdair::Inventory* lInventory_ptr = stdair::BomManager::
36  getObjectPtr<stdair::Inventory> (ioBomRoot, lAirlineCode);
37  if (lInventory_ptr == NULL) {
38  stdair::InventoryKey lKey (lAirlineCode);
39 
40  lInventory_ptr =
42  stdair::FacBomManager::addToListAndMap (ioBomRoot, *lInventory_ptr);
43  stdair::FacBomManager::linkWithParent (ioBomRoot, *lInventory_ptr);
44 
45  // Add the airline feature object to the inventory
46  const stdair::AirlineFeatureKey lAirlineFeatureKey (lAirlineCode);
47  stdair::AirlineFeature& lAirlineFeature =
48  stdair::FacBom<stdair::AirlineFeature>::instance().create (lAirlineFeatureKey);
49  stdair::FacBomManager::setAirlineFeature (*lInventory_ptr,
50  lAirlineFeature);
51  stdair::FacBomManager::linkWithParent (*lInventory_ptr, lAirlineFeature);
52  // Link the airline feature object with the top of the BOM tree
53  stdair::FacBomManager::addToListAndMap (ioBomRoot, lAirlineFeature);
54  }
55  assert (lInventory_ptr != NULL);
56 
57  // Create the flight-period key.
58  const stdair::PeriodStruct lPeriod (iFlightPeriodStruct._dateRange,
59  iFlightPeriodStruct._dow);
60  const stdair::FlightPeriodKey
61  lFlightPeriodKey (iFlightPeriodStruct._flightNumber, lPeriod);
62 
63  // Check that the flight-period object is not already created.
64  stdair::FlightPeriod* lFlightPeriod_ptr = stdair::BomManager::
65  getObjectPtr<stdair::FlightPeriod> (*lInventory_ptr,
66  lFlightPeriodKey.toString());
67  if (lFlightPeriod_ptr != NULL) {
68  throw stdair::ObjectCreationgDuplicationException ("");
69  }
70  assert (lFlightPeriod_ptr == NULL);
71 
72  // Instantiate a flight-period object with the given key.
73  lFlightPeriod_ptr = &stdair::FacBom<stdair::FlightPeriod>::
74  instance().create (lFlightPeriodKey);
75  stdair::FacBomManager::addToListAndMap (*lInventory_ptr, *lFlightPeriod_ptr);
76  stdair::FacBomManager::linkWithParent (*lInventory_ptr, *lFlightPeriod_ptr);
77 
78  // Create the segment-periods.
79  createSegmentPeriods (*lFlightPeriod_ptr, iFlightPeriodStruct);
80  }
81 
82  // ////////////////////////////////////////////////////////////////////
83  void InventoryGenerator::
84  createSegmentPeriods (stdair::FlightPeriod& ioFlightPeriod,
85  const FlightPeriodStruct& iFlightPeriodStruct) {
86 
87  // Iterate on the segment strutures.
88  const SegmentStructList_T& lSegmentList = iFlightPeriodStruct._segmentList;
89  for (SegmentStructList_T::const_iterator itSegment = lSegmentList.begin();
90  itSegment != lSegmentList.end(); ++itSegment) {
91 
92  const SegmentStruct& lSegment = *itSegment;
93 
94  // Set the segment-period primary key.
95  const stdair::AirportCode_T& lBoardingPoint = lSegment._boardingPoint;
96  const stdair::AirportCode_T& lOffPoint = lSegment._offPoint;
97  const stdair::SegmentPeriodKey lSegmentPeriodKey (lBoardingPoint,
98  lOffPoint);
99 
100  // Instantiate a segment-perioed with the key.
101  stdair::SegmentPeriod& lSegmentPeriod = stdair::
102  FacBom<stdair::SegmentPeriod>::instance().create (lSegmentPeriodKey);
103  stdair::FacBomManager::addToListAndMap (ioFlightPeriod, lSegmentPeriod);
104  stdair::FacBomManager::linkWithParent (ioFlightPeriod, lSegmentPeriod);
105 
106  // Set the segment-period attributes.
107  SegmentPeriodHelper::fill (lSegmentPeriod, lSegment);
108  SegmentPeriodHelper::fill (lSegmentPeriod, iFlightPeriodStruct._legList);
109  }
110  }
111 
112 }