AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InventoryBuilder.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/basic/BasConst_BookingClass.hpp>
10 #include <stdair/basic/BasConst_Yield.hpp>
11 #include <stdair/basic/BasConst_Inventory.hpp>
12 #include <stdair/bom/BomManager.hpp>
13 #include <stdair/bom/BomRoot.hpp>
14 #include <stdair/bom/Inventory.hpp>
15 #include <stdair/bom/FlightDate.hpp>
16 #include <stdair/bom/SegmentDate.hpp>
17 #include <stdair/bom/SegmentCabin.hpp>
18 #include <stdair/bom/FareFamily.hpp>
19 #include <stdair/bom/BookingClass.hpp>
20 #include <stdair/bom/LegDate.hpp>
21 #include <stdair/bom/LegCabin.hpp>
22 #include <stdair/bom/Bucket.hpp>
23 #include <stdair/factory/FacBom.hpp>
24 #include <stdair/factory/FacBomManager.hpp>
25 #include <stdair/service/Logger.hpp>
26 // AirInv
29 
30 namespace AIRINV {
31 
32  // ////////////////////////////////////////////////////////////////////
33  void InventoryBuilder::
34  buildInventory (stdair::BomRoot& ioBomRoot,
35  const FlightDateStruct& iFlightDateStruct) {
36  const stdair::AirlineCode_T& lAirlineCode = iFlightDateStruct._airlineCode;
37 
38  // Instantiate an inventory object (if not exist)
39  // for the given key (airline code)
40  stdair::Inventory* lInventory_ptr = stdair::BomManager::
41  getObjectPtr<stdair::Inventory> (ioBomRoot, lAirlineCode);
42  if (lInventory_ptr == NULL) {
43  stdair::InventoryKey lKey (lAirlineCode);
44  lInventory_ptr =
45  &stdair::FacBom<stdair::Inventory>::instance().create (lKey);
46  stdair::FacBomManager::addToListAndMap (ioBomRoot, *lInventory_ptr);
47  stdair::FacBomManager::linkWithParent (ioBomRoot, *lInventory_ptr);
48  }
49  assert (lInventory_ptr != NULL);
50 
51  // Build the flight-date within the inventory.
52  buildFlightDate (*lInventory_ptr, iFlightDateStruct);
53  }
54 
55  // ////////////////////////////////////////////////////////////////////
56  void InventoryBuilder::
57  buildFlightDate (stdair::Inventory& ioInventory,
58  const FlightDateStruct& iFlightDateStruct) {
59  // Create the FlightDateKey
60  const stdair::FlightDateKey lFlightDateKey (iFlightDateStruct._flightNumber,
61  iFlightDateStruct._flightDate);
62 
63  // Check that the flight-date object is not already existing. If a
64  // flight-date object with the same key has already been created,
65  // then just update it, ifnot, create a flight-date and update it.
66  stdair::FlightDate* lFlightDate_ptr = stdair::BomManager::
67  getObjectPtr<stdair::FlightDate> (ioInventory, lFlightDateKey.toString());
68  if (lFlightDate_ptr == NULL) {
69  // Instantiate a flighy-date object for the given key (flight number and
70  // flight date)
71  lFlightDate_ptr =
72  &stdair::FacBom<stdair::FlightDate>::instance().create (lFlightDateKey);
73  stdair::FacBomManager::addToListAndMap (ioInventory, *lFlightDate_ptr);
74  stdair::FacBomManager::linkWithParent (ioInventory, *lFlightDate_ptr);
75  }
76  assert (lFlightDate_ptr != NULL);
77 
78  // Update the BOM flight-date with the attributes of the flight-date struct.
79 
80  // Browse the list of leg-date struct and segment-date struct and
81  // create the corresponding BOM.
82  for (LegStructList_T::const_iterator itLegDate =
83  iFlightDateStruct._legList.begin();
84  itLegDate != iFlightDateStruct._legList.end(); ++itLegDate) {
85  const LegStruct& lCurrentLegDateStruct = *itLegDate;
86  buildLegDate (*lFlightDate_ptr, lCurrentLegDateStruct);
87  }
88 
89  for (SegmentStructList_T::const_iterator itSegmentDate =
90  iFlightDateStruct._segmentList.begin();
91  itSegmentDate != iFlightDateStruct._segmentList.end();
92  ++itSegmentDate) {
93  const SegmentStruct& lCurrentSegmentDateStruct = *itSegmentDate;
94  buildSegmentDate (*lFlightDate_ptr, lCurrentSegmentDateStruct);
95  }
96  }
97 
98  // ////////////////////////////////////////////////////////////////////
99  void InventoryBuilder::
100  buildLegDate (stdair::FlightDate& ioFlightDate,
101  const LegStruct& iLegDateStruct) {
102  // Check that the leg-date object is not already existing. If a
103  // leg-date object with the same key has already been created,
104  // then just update it, ifnot, create a leg-date and update it.
105  stdair::LegDate* lLegDate_ptr = stdair::BomManager::
106  getObjectPtr<stdair::LegDate>(ioFlightDate, iLegDateStruct._boardingPoint);
107 
108  if (lLegDate_ptr == NULL) {
109  // Instantiate a leg-date object for the given key (boarding point);
110  stdair::LegDateKey lKey (iLegDateStruct._boardingPoint);
111  lLegDate_ptr = &stdair::FacBom<stdair::LegDate>::instance().create (lKey);
112  stdair::FacBomManager::addToListAndMap (ioFlightDate, *lLegDate_ptr);
113  stdair::FacBomManager::linkWithParent (ioFlightDate, *lLegDate_ptr);
114  }
115  assert (lLegDate_ptr != NULL);
116 
117  // Update the BOM leg-date with the attributes of the leg-date struct.
118  iLegDateStruct.fill (*lLegDate_ptr);
119 
120  // Browse the list of leg-cabin structs and create the corresponding BOM.
121  for (LegCabinStructList_T::const_iterator itLegCabin =
122  iLegDateStruct._cabinList.begin();
123  itLegCabin != iLegDateStruct._cabinList.end(); ++itLegCabin) {
124  const LegCabinStruct& lCurrentLegCabinStruct = *itLegCabin;
125  buildLegCabin (*lLegDate_ptr, lCurrentLegCabinStruct);
126  }
127  }
128 
129  // ////////////////////////////////////////////////////////////////////
130  void InventoryBuilder::
131  buildLegCabin (stdair::LegDate& ioLegDate,
132  const LegCabinStruct& iLegCabinStruct) {
133  // Check that the leg-cabin object is not already existing. If a
134  // leg-cabin object with the same key has already been created,
135  // then just update it, ifnot, create a leg-cabin and update it.
136  stdair::LegCabin* lLegCabin_ptr = stdair::BomManager::
137  getObjectPtr<stdair::LegCabin> (ioLegDate, iLegCabinStruct._cabinCode);
138  if (lLegCabin_ptr == NULL) {
139  // Instantiate a leg-cabin object for the given key (cabin code);
140  stdair::LegCabinKey lKey (iLegCabinStruct._cabinCode);
141  lLegCabin_ptr = &stdair::FacBom<stdair::LegCabin>::instance().create(lKey);
142  stdair::FacBomManager::addToListAndMap (ioLegDate, *lLegCabin_ptr);
143  stdair::FacBomManager::linkWithParent (ioLegDate, *lLegCabin_ptr);
144  }
145  assert (lLegCabin_ptr != NULL);
146 
147  // TODO: Update the BOM leg-cabin with the attributes of the
148  // leg-cabin struct.
149  iLegCabinStruct.fill (*lLegCabin_ptr);
150 
151  // Browse the list of bucket structs and create the corresponding BOM.
152  for (BucketStructList_T::const_iterator itBucket =
153  iLegCabinStruct._bucketList.begin();
154  itBucket != iLegCabinStruct._bucketList.end(); ++itBucket) {
155  const BucketStruct& lCurrentBucketStruct = *itBucket;
156  buildBucket (*lLegCabin_ptr, lCurrentBucketStruct);
157  }
158  }
159 
160  // ////////////////////////////////////////////////////////////////////
161  void InventoryBuilder::buildBucket (stdair::LegCabin& ioLegCabin,
162  const BucketStruct& iBucketStruct) {
163  // Create the BucketKey
164  const stdair::BucketKey lBucketKey (iBucketStruct._seatIndex);
165 
166  // Check that the bucket object is not already existing. If a
167  // bucket object with the same key has already been created,
168  // then just update it, ifnot, create a bucket and update it.
169  stdair::Bucket* lBucket_ptr = stdair::BomManager::
170  getObjectPtr<stdair::Bucket> (ioLegCabin, lBucketKey.toString());
171  if (lBucket_ptr == NULL) {
172  // Instantiate a bucket object for the given key (seat index);
173  stdair::BucketKey lKey (iBucketStruct._seatIndex);
174  lBucket_ptr = &stdair::FacBom<stdair::Bucket>::instance().create (lKey);
175  stdair::FacBomManager::addToListAndMap (ioLegCabin, *lBucket_ptr);
176  stdair::FacBomManager::linkWithParent (ioLegCabin, *lBucket_ptr);
177  }
178  assert (lBucket_ptr != NULL);
179 
180  //
181  iBucketStruct.fill (*lBucket_ptr);
182  }
183 
184  // ////////////////////////////////////////////////////////////////////
185  void InventoryBuilder::
186  buildSegmentDate (stdair::FlightDate& ioFlightDate,
187  const SegmentStruct& iSegmentDateStruct) {
188  // Check that the segment-date object is not already existing. If a
189  // segment-date object with the same key has already been created,
190  // then just update it, ifnot, create a segment-date and update it.
191  const stdair::SegmentDateKey
192  lSegmentDateKey (iSegmentDateStruct._boardingPoint,
193  iSegmentDateStruct._offPoint);
194  stdair::SegmentDate* lSegmentDate_ptr = stdair::BomManager::
195  getObjectPtr<stdair::SegmentDate>(ioFlightDate,lSegmentDateKey.toString());
196  if (lSegmentDate_ptr == NULL) {
197  // Instantiate a segment-date object for the given key (boarding
198  // and off points);
199  lSegmentDate_ptr = &stdair::FacBom<stdair::SegmentDate>::
200  instance().create (lSegmentDateKey);
201  stdair::FacBomManager::addToListAndMap (ioFlightDate, *lSegmentDate_ptr);
202  stdair::FacBomManager::linkWithParent (ioFlightDate, *lSegmentDate_ptr);
203  }
204  assert (lSegmentDate_ptr != NULL);
205 
206  // Update the BOM segment-date with the attributes of the
207  // segment-date struct.
208  iSegmentDateStruct.fill (*lSegmentDate_ptr);
209 
210  // Browse the list of segment-cabin struct and create the corresponding BOM.
211  for (SegmentCabinStructList_T::const_iterator itSegmentCabin =
212  iSegmentDateStruct._cabinList.begin();
213  itSegmentCabin != iSegmentDateStruct._cabinList.end();
214  ++itSegmentCabin) {
215  const SegmentCabinStruct& lCurrentSegmentCabinStruct = *itSegmentCabin;
216  buildSegmentCabin (*lSegmentDate_ptr, lCurrentSegmentCabinStruct);
217  }
218  }
219 
220  // ////////////////////////////////////////////////////////////////////
221  void InventoryBuilder::
222  buildSegmentCabin (stdair::SegmentDate& ioSegmentDate,
223  const SegmentCabinStruct& iSegmentCabinStruct) {
224  // Check that the segment-cabin object is not already existing. If a
225  // segment-cabin object with the same key has already been created,
226  // then just update it, ifnot, create a segment-cabin and update it.
227  stdair::SegmentCabin* lSegmentCabin_ptr = stdair::BomManager::
228  getObjectPtr<stdair::SegmentCabin> (ioSegmentDate,
229  iSegmentCabinStruct._cabinCode);
230  if (lSegmentCabin_ptr == NULL) {
231  // Instantiate a segment-cabin object for the given key (cabin code);
232  stdair::SegmentCabinKey lKey (iSegmentCabinStruct._cabinCode);
233  lSegmentCabin_ptr =
234  &stdair::FacBom<stdair::SegmentCabin>::instance().create (lKey);
235 
236  // Link the segment-cabin to the segment-date
237  stdair::FacBomManager::addToListAndMap (ioSegmentDate, *lSegmentCabin_ptr);
238  stdair::FacBomManager::linkWithParent (ioSegmentDate, *lSegmentCabin_ptr);
239  }
240  assert (lSegmentCabin_ptr != NULL);
241 
242  // TODO: Update the BOM segment-cabin with the attributes of the
243  // segment-cabin struct.
244  iSegmentCabinStruct.fill (*lSegmentCabin_ptr);
245 
246  // Browse the list of fare family struct and create the corresponding BOM.
247  for (FareFamilyStructList_T::const_iterator itFareFamily =
248  iSegmentCabinStruct._fareFamilies.begin();
249  itFareFamily != iSegmentCabinStruct._fareFamilies.end();
250  ++itFareFamily) {
251  const FareFamilyStruct& lCurrentFareFamilyStruct = *itFareFamily;
252  buildFareFamily (*lSegmentCabin_ptr, lCurrentFareFamilyStruct);
253  }
254  }
255 
256  // ////////////////////////////////////////////////////////////////////
257  void InventoryBuilder::
258  buildFareFamily (stdair::SegmentCabin& ioSegmentCabin,
259  const FareFamilyStruct& iFareFamilyStruct) {
260 
261  // Check that the fare family object is not already existing. If a
262  // fare family object with the same key has already been created,
263  // then just update it. If not, create a fare family and update it.
264  stdair::FareFamily* lFareFamily_ptr = stdair::BomManager::
265  getObjectPtr<stdair::FareFamily> (ioSegmentCabin,
266  iFareFamilyStruct._familyCode);
267  if (lFareFamily_ptr == NULL) {
268  // Instantiate a fare family object for the given key (fare family code);
269  const stdair::FareFamilyKey lFFKey (iFareFamilyStruct._familyCode);
270  lFareFamily_ptr =
271  &stdair::FacBom<stdair::FareFamily>::instance().create (lFFKey);
272 
273  // Link the fare family to the segment-cabin
274  stdair::FacBomManager::addToListAndMap (ioSegmentCabin, *lFareFamily_ptr);
275  stdair::FacBomManager::linkWithParent (ioSegmentCabin, *lFareFamily_ptr);
276  }
277  assert (lFareFamily_ptr != NULL);
278 
279  // TODO: Upcabin the BOM fare family with the attributes of the
280  // fare family struct.
281  iFareFamilyStruct.fill (*lFareFamily_ptr);
282 
283  // Browse the list of booking-class struct and create the corresponding BOM.
284  for (BookingClassStructList_T::const_iterator itBookingClass =
285  iFareFamilyStruct._classList.begin();
286  itBookingClass != iFareFamilyStruct._classList.end();
287  ++itBookingClass) {
288  const BookingClassStruct& lCurrentBookingClassStruct = *itBookingClass;
289  buildBookingClass (*lFareFamily_ptr, lCurrentBookingClassStruct);
290  }
291  }
292 
293  // ////////////////////////////////////////////////////////////////////
294  void InventoryBuilder::
295  buildBookingClass (stdair::FareFamily& ioFareFamily,
296  const BookingClassStruct& iBookingClassStruct) {
297 
298  // Check that the booking class object is not already existing. If a
299  // booking-class object with the same key has already been created,
300  // then just update it. If not, create a booking-class and update it.
301  stdair::BookingClass* lBookingClass_ptr = stdair::BomManager::
302  getObjectPtr<stdair::BookingClass> (ioFareFamily,
303  iBookingClassStruct._classCode);
304  if (lBookingClass_ptr == NULL) {
305  // Instantiate a booking class object for the given key (class code);
306  const stdair::BookingClassKey lClassKey (iBookingClassStruct._classCode);
307  lBookingClass_ptr =
308  &stdair::FacBom<stdair::BookingClass>::instance().create (lClassKey);
309 
310  // Link the booking-class to the fare family
311  stdair::FacBomManager::addToListAndMap (ioFareFamily, *lBookingClass_ptr);
312  stdair::FacBomManager::linkWithParent (ioFareFamily, *lBookingClass_ptr);
313 
314  // Link the booking-class to the segment-cabin
315  stdair::SegmentCabin& lSegmentCabin =
316  stdair::BomManager::getParent<stdair::SegmentCabin> (ioFareFamily);
317  stdair::FacBomManager::addToListAndMap (lSegmentCabin, *lBookingClass_ptr);
318 
319  // Link the booking-class to the segment-date
320  stdair::SegmentDate& lSegmentDate =
321  stdair::BomManager::getParent<stdair::SegmentDate> (lSegmentCabin);
322  stdair::FacBomManager::addToListAndMap (lSegmentDate, *lBookingClass_ptr);
323  }
324  assert (lBookingClass_ptr != NULL);
325 
326  // TODO: Upcabin the BOM booking-class with the attributes of the
327  // booking-class struct.
328  iBookingClassStruct.fill (*lBookingClass_ptr);
329  }
330 
331 }