AirInv Logo  1.00.9
C++ Simulated Airline Inventory Management System Library
Loading...
Searching...
No Matches
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/AirlineFeature.hpp>
16#include <stdair/bom/FlightDate.hpp>
17#include <stdair/bom/SegmentDate.hpp>
18#include <stdair/bom/SegmentCabin.hpp>
19#include <stdair/bom/FareFamily.hpp>
20#include <stdair/bom/BookingClass.hpp>
21#include <stdair/bom/LegDate.hpp>
22#include <stdair/bom/LegCabin.hpp>
23#include <stdair/bom/Bucket.hpp>
24#include <stdair/bom/BomKeyManager.hpp>
25#include <stdair/bom/ParsedKey.hpp>
26#include <stdair/bom/BomRetriever.hpp>
27#include <stdair/command/CmdCloneBomManager.hpp>
28#include <stdair/factory/FacBom.hpp>
29#include <stdair/factory/FacBomManager.hpp>
30#include <stdair/service/Logger.hpp>
31// AirInv
35
36namespace AIRINV {
37
38 // ////////////////////////////////////////////////////////////////////
39 void InventoryBuilder::
40 buildInventory (stdair::BomRoot& ioBomRoot,
41 const FlightDateStruct& iFlightDateStruct) {
42 const stdair::AirlineCode_T& lAirlineCode = iFlightDateStruct._airlineCode;
43
44 // Instantiate an inventory object (if not exist)
45 // for the given key (airline code)
46 stdair::Inventory* lInventory_ptr = stdair::BomManager::
47 getObjectPtr<stdair::Inventory> (ioBomRoot, lAirlineCode);
48 if (lInventory_ptr == NULL) {
49 stdair::InventoryKey lKey (lAirlineCode);
50 lInventory_ptr =
51 &stdair::FacBom<stdair::Inventory>::instance().create (lKey);
52 stdair::FacBomManager::addToListAndMap (ioBomRoot, *lInventory_ptr);
53 stdair::FacBomManager::linkWithParent (ioBomRoot, *lInventory_ptr);
54
55 // Add the airline feature object to the inventory
56 const stdair::AirlineFeatureKey lAirlineFeatureKey (lAirlineCode);
57 stdair::AirlineFeature& lAirlineFeature =
58 stdair::FacBom<stdair::AirlineFeature>::instance().create (lAirlineFeatureKey);
59 stdair::FacBomManager::setAirlineFeature (*lInventory_ptr,
60 lAirlineFeature);
61 stdair::FacBomManager::linkWithParent (*lInventory_ptr, lAirlineFeature);
62 // Link the airline feature object with the top of the BOM tree
63 stdair::FacBomManager::addToListAndMap (ioBomRoot, lAirlineFeature);
64 }
65 assert (lInventory_ptr != NULL);
66
67 // Build the flight-date within the inventory.
68 buildFlightDate (*lInventory_ptr, iFlightDateStruct);
69 }
70
71 // ////////////////////////////////////////////////////////////////////
72 void InventoryBuilder::
73 buildFlightDate (stdair::Inventory& ioInventory,
74 const FlightDateStruct& iFlightDateStruct) {
75 // Create the FlightDateKey
76 const stdair::FlightDateKey lFlightDateKey (iFlightDateStruct._flightNumber,
77 iFlightDateStruct._flightDate);
78
79 // Check that the flight-date object is not already existing. If a
80 // flight-date object with the same key has already been created,
81 // then just update it, ifnot, create a flight-date and update it.
82 stdair::FlightDate* lFlightDate_ptr = stdair::BomManager::
83 getObjectPtr<stdair::FlightDate> (ioInventory, lFlightDateKey.toString());
84 if (lFlightDate_ptr == NULL) {
85 // Instantiate a flighy-date object for the given key (flight number and
86 // flight date)
87 lFlightDate_ptr =
88 &stdair::FacBom<stdair::FlightDate>::instance().create (lFlightDateKey);
89 stdair::FacBomManager::addToListAndMap (ioInventory, *lFlightDate_ptr);
90 stdair::FacBomManager::linkWithParent (ioInventory, *lFlightDate_ptr);
91 }
92 assert (lFlightDate_ptr != NULL);
93
94 // Update the BOM flight-date with the attributes of the flight-date struct.
95
96 // Browse the list of leg-date struct and segment-date struct and
97 // create the corresponding BOM.
98 for (LegStructList_T::const_iterator itLegDate =
99 iFlightDateStruct._legList.begin();
100 itLegDate != iFlightDateStruct._legList.end(); ++itLegDate) {
101 const LegStruct& lCurrentLegDateStruct = *itLegDate;
102 buildLegDate (*lFlightDate_ptr, lCurrentLegDateStruct);
103 }
104
105 for (SegmentStructList_T::const_iterator itSegmentDate =
106 iFlightDateStruct._segmentList.begin();
107 itSegmentDate != iFlightDateStruct._segmentList.end();
108 ++itSegmentDate) {
109 const SegmentStruct& lCurrentSegmentDateStruct = *itSegmentDate;
110 buildSegmentDate (*lFlightDate_ptr, lCurrentSegmentDateStruct);
111 }
112
113 buildRoutingLegKey (*lFlightDate_ptr);
114 }
115
116 // ////////////////////////////////////////////////////////////////////
117 void InventoryBuilder::
118 buildLegDate (stdair::FlightDate& ioFlightDate,
119 const LegStruct& iLegDateStruct) {
120 // Check that the leg-date object is not already existing. If a
121 // leg-date object with the same key has already been created,
122 // then just update it, ifnot, create a leg-date and update it.
123 stdair::LegDate* lLegDate_ptr = stdair::BomManager::
124 getObjectPtr<stdair::LegDate>(ioFlightDate, iLegDateStruct._boardingPoint);
125
126 if (lLegDate_ptr == NULL) {
127 // Instantiate a leg-date object for the given key (boarding point);
128 stdair::LegDateKey lKey (iLegDateStruct._boardingPoint);
129 lLegDate_ptr = &stdair::FacBom<stdair::LegDate>::instance().create (lKey);
130 stdair::FacBomManager::addToListAndMap (ioFlightDate, *lLegDate_ptr);
131 stdair::FacBomManager::linkWithParent (ioFlightDate, *lLegDate_ptr);
132 }
133 assert (lLegDate_ptr != NULL);
134
135 // Update the BOM leg-date with the attributes of the leg-date struct.
136 iLegDateStruct.fill (*lLegDate_ptr);
137
138 // Browse the list of leg-cabin structs and create the corresponding BOM.
139 for (LegCabinStructList_T::const_iterator itLegCabin =
140 iLegDateStruct._cabinList.begin();
141 itLegCabin != iLegDateStruct._cabinList.end(); ++itLegCabin) {
142 const LegCabinStruct& lCurrentLegCabinStruct = *itLegCabin;
143 buildLegCabin (*lLegDate_ptr, lCurrentLegCabinStruct);
144 }
145 }
146
147 // ////////////////////////////////////////////////////////////////////
148 void InventoryBuilder::
149 buildRoutingLegKey (stdair::FlightDate& ioFlightDate) {
150
151 // Browse the list of segment-dates and create direct accesses
152 // within each segment-date.
153 const stdair::SegmentDateList_T& lSegmentDateList =
154 stdair::BomManager::getList<stdair::SegmentDate> (ioFlightDate);
155 for (stdair::SegmentDateList_T::const_iterator itSegmentDate =
156 lSegmentDateList.begin();
157 itSegmentDate != lSegmentDateList.end(); ++itSegmentDate) {
158
159 stdair::SegmentDate* lCurrentSegmentDate_ptr = *itSegmentDate;
160 assert (lCurrentSegmentDate_ptr != NULL);
161
162 /*
163 * If the segment is just marketed by this carrier,
164 * retrieve the operating segment and call the createDirectAcces
165 * method on its parent (flight date).
166 */
167 const stdair::SegmentDate* lOperatingSegmentDate_ptr =
168 lCurrentSegmentDate_ptr->getOperatingSegmentDate ();
169 if (lOperatingSegmentDate_ptr == NULL) {
170
171 const stdair::AirportCode_T& lBoardingPoint =
172 lCurrentSegmentDate_ptr->getBoardingPoint();
173
174 stdair::AirportCode_T currentBoardingPoint = lBoardingPoint;
175 const stdair::AirportCode_T& lOffPoint =
176 lCurrentSegmentDate_ptr->getOffPoint();
177
178 // Add a sanity check so as to ensure that the loop stops. If
179 // there are more than MAXIMAL_NUMBER_OF_LEGS legs, there is
180 // an issue somewhere in the code (not in the parser, as the
181 // segments are derived from the legs thanks to the
182 // FlightPeriodStruct::buildSegments() method).
183 unsigned short i = 1;
184 while (currentBoardingPoint != lOffPoint
185 && i <= stdair::MAXIMAL_NUMBER_OF_LEGS_IN_FLIGHT) {
186 // Retrieve the (unique) LegDate getting that Boarding Point
187 stdair::LegDate& lLegDate = stdair::BomManager::
188 getObject<stdair::LegDate> (ioFlightDate, currentBoardingPoint);
189
190 // Link the SegmentDate and LegDate together
191 const std::string& lRoutingKeyStr = lLegDate.describeRoutingKey();
192 lCurrentSegmentDate_ptr->addLegKey(lRoutingKeyStr);
193
194 // Prepare the next iteration
195 currentBoardingPoint = lLegDate.getOffPoint();
196 ++i;
197 }
198 assert (i <= stdair::MAXIMAL_NUMBER_OF_LEGS_IN_FLIGHT);
199 }
200 }
201 }
202
203 // ////////////////////////////////////////////////////////////////////
204 void InventoryBuilder::
205 buildLegCabin (stdair::LegDate& ioLegDate,
206 const LegCabinStruct& iLegCabinStruct) {
207 // Check that the leg-cabin object is not already existing. If a
208 // leg-cabin object with the same key has already been created,
209 // then just update it, ifnot, create a leg-cabin and update it.
210 stdair::LegCabin* lLegCabin_ptr = stdair::BomManager::
211 getObjectPtr<stdair::LegCabin> (ioLegDate, iLegCabinStruct._cabinCode);
212 if (lLegCabin_ptr == NULL) {
213 // Instantiate a leg-cabin object for the given key (cabin code);
214 stdair::LegCabinKey lKey (iLegCabinStruct._cabinCode);
215 lLegCabin_ptr = &stdair::FacBom<stdair::LegCabin>::instance().create(lKey);
216 stdair::FacBomManager::addToListAndMap (ioLegDate, *lLegCabin_ptr);
217 stdair::FacBomManager::linkWithParent (ioLegDate, *lLegCabin_ptr);
218 }
219 assert (lLegCabin_ptr != NULL);
220
221 // TODO: Update the BOM leg-cabin with the attributes of the
222 // leg-cabin struct.
223 iLegCabinStruct.fill (*lLegCabin_ptr);
224
225 // Browse the list of bucket structs and create the corresponding BOM.
226 for (BucketStructList_T::const_iterator itBucket =
227 iLegCabinStruct._bucketList.begin();
228 itBucket != iLegCabinStruct._bucketList.end(); ++itBucket) {
229 const BucketStruct& lCurrentBucketStruct = *itBucket;
230 buildBucket (*lLegCabin_ptr, lCurrentBucketStruct);
231 }
232 }
233
234 // ////////////////////////////////////////////////////////////////////
235 void InventoryBuilder::buildBucket (stdair::LegCabin& ioLegCabin,
236 const BucketStruct& iBucketStruct) {
237 // Create the BucketKey
238 const stdair::BucketKey lBucketKey (iBucketStruct._seatIndex);
239
240 // Check that the bucket object is not already existing. If a
241 // bucket object with the same key has already been created,
242 // then just update it, ifnot, create a bucket and update it.
243 stdair::Bucket* lBucket_ptr = stdair::BomManager::
244 getObjectPtr<stdair::Bucket> (ioLegCabin, lBucketKey.toString());
245 if (lBucket_ptr == NULL) {
246 // Instantiate a bucket object for the given key (seat index);
247 stdair::BucketKey lKey (iBucketStruct._seatIndex);
248 lBucket_ptr = &stdair::FacBom<stdair::Bucket>::instance().create (lKey);
249 stdair::FacBomManager::addToListAndMap (ioLegCabin, *lBucket_ptr);
250 stdair::FacBomManager::linkWithParent (ioLegCabin, *lBucket_ptr);
251 }
252 assert (lBucket_ptr != NULL);
253
254 //
255 iBucketStruct.fill (*lBucket_ptr);
256 }
257
258 // ////////////////////////////////////////////////////////////////////
259 void InventoryBuilder::
260 buildSegmentDate (stdair::FlightDate& ioFlightDate,
261 const SegmentStruct& iSegmentDateStruct) {
262 // Check that the segment-date object is not already existing. If a
263 // segment-date object with the same key has already been created,
264 // then just update it, ifnot, create a segment-date and update it.
265 const stdair::SegmentDateKey
266 lSegmentDateKey (iSegmentDateStruct._boardingPoint,
267 iSegmentDateStruct._offPoint);
268 stdair::SegmentDate* lSegmentDate_ptr = stdair::BomManager::
269 getObjectPtr<stdair::SegmentDate>(ioFlightDate,lSegmentDateKey.toString());
270 if (lSegmentDate_ptr == NULL) {
271 // Instantiate a segment-date object for the given key (boarding
272 // and off points);
273 lSegmentDate_ptr = &stdair::FacBom<stdair::SegmentDate>::
274 instance().create (lSegmentDateKey);
275 stdair::FacBomManager::addToListAndMap (ioFlightDate, *lSegmentDate_ptr);
276 stdair::FacBomManager::linkWithParent (ioFlightDate, *lSegmentDate_ptr);
277 }
278 assert (lSegmentDate_ptr != NULL);
279
280 // Update the BOM segment-date with the attributes of the
281 // segment-date struct.
282 iSegmentDateStruct.fill (*lSegmentDate_ptr);
283
284 // Browse the list of segment-cabin struct and create the corresponding BOM.
285 for (SegmentCabinStructList_T::const_iterator itSegmentCabin =
286 iSegmentDateStruct._cabinList.begin();
287 itSegmentCabin != iSegmentDateStruct._cabinList.end();
288 ++itSegmentCabin) {
289 const SegmentCabinStruct& lCurrentSegmentCabinStruct = *itSegmentCabin;
290 buildSegmentCabin (*lSegmentDate_ptr, lCurrentSegmentCabinStruct);
291 }
292 }
293
294 // ////////////////////////////////////////////////////////////////////
295 void InventoryBuilder::
296 buildSegmentCabin (stdair::SegmentDate& ioSegmentDate,
297 const SegmentCabinStruct& iSegmentCabinStruct) {
298 // Check that the segment-cabin object is not already existing. If a
299 // segment-cabin object with the same key has already been created,
300 // then just update it, ifnot, create a segment-cabin and update it.
301 stdair::SegmentCabin* lSegmentCabin_ptr = stdair::BomManager::
302 getObjectPtr<stdair::SegmentCabin> (ioSegmentDate,
303 iSegmentCabinStruct._cabinCode);
304 if (lSegmentCabin_ptr == NULL) {
305 // Instantiate a segment-cabin object for the given key (cabin code);
306 stdair::SegmentCabinKey lKey (iSegmentCabinStruct._cabinCode);
307 lSegmentCabin_ptr =
308 &stdair::FacBom<stdair::SegmentCabin>::instance().create (lKey);
309
310 // Link the segment-cabin to the segment-date
311 stdair::FacBomManager::addToListAndMap (ioSegmentDate, *lSegmentCabin_ptr);
312 stdair::FacBomManager::linkWithParent (ioSegmentDate, *lSegmentCabin_ptr);
313 }
314 assert (lSegmentCabin_ptr != NULL);
315
316 // TODO: Update the BOM segment-cabin with the attributes of the
317 // segment-cabin struct.
318 iSegmentCabinStruct.fill (*lSegmentCabin_ptr);
319
320 // Browse the list of fare family struct and create the corresponding BOM.
321 for (FareFamilyStructList_T::const_iterator itFareFamily =
322 iSegmentCabinStruct._fareFamilies.begin();
323 itFareFamily != iSegmentCabinStruct._fareFamilies.end();
324 ++itFareFamily) {
325 const FareFamilyStruct& lCurrentFareFamilyStruct = *itFareFamily;
326 buildFareFamily (*lSegmentCabin_ptr, lCurrentFareFamilyStruct);
327 }
328 }
329
330 // ////////////////////////////////////////////////////////////////////
331 void InventoryBuilder::
332 buildFareFamily (stdair::SegmentCabin& ioSegmentCabin,
333 const FareFamilyStruct& iFareFamilyStruct) {
334
335 // Check that the fare family object is not already existing. If a
336 // fare family object with the same key has already been created,
337 // then just update it. If not, create a fare family and update it.
338 stdair::FareFamily* lFareFamily_ptr = stdair::BomManager::
339 getObjectPtr<stdair::FareFamily> (ioSegmentCabin,
340 iFareFamilyStruct._familyCode);
341 if (lFareFamily_ptr == NULL) {
342 // Instantiate a fare family object for the given key (fare family code);
343 const stdair::FareFamilyKey lFFKey (iFareFamilyStruct._familyCode);
344 lFareFamily_ptr =
345 &stdair::FacBom<stdair::FareFamily>::instance().create (lFFKey);
346
347 // Link the fare family to the segment-cabin
348 stdair::FacBomManager::addToListAndMap (ioSegmentCabin, *lFareFamily_ptr);
349 stdair::FacBomManager::linkWithParent (ioSegmentCabin, *lFareFamily_ptr);
350 }
351 assert (lFareFamily_ptr != NULL);
352
353 // TODO: Upcabin the BOM fare family with the attributes of the
354 // fare family struct.
355 iFareFamilyStruct.fill (*lFareFamily_ptr);
356
357 // Browse the list of booking-class struct and create the corresponding BOM.
358 for (BookingClassStructList_T::const_iterator itBookingClass =
359 iFareFamilyStruct._classList.begin();
360 itBookingClass != iFareFamilyStruct._classList.end();
361 ++itBookingClass) {
362 const BookingClassStruct& lCurrentBookingClassStruct = *itBookingClass;
363 buildBookingClass (*lFareFamily_ptr, lCurrentBookingClassStruct);
364 }
365 }
366
367 // ////////////////////////////////////////////////////////////////////
368 void InventoryBuilder::
369 buildBookingClass (stdair::FareFamily& ioFareFamily,
370 const BookingClassStruct& iBookingClassStruct) {
371
372 // Check that the booking class object is not already existing. If a
373 // booking-class object with the same key has already been created,
374 // then just update it. If not, create a booking-class and update it.
375 stdair::BookingClass* lBookingClass_ptr = stdair::BomManager::
376 getObjectPtr<stdair::BookingClass> (ioFareFamily,
377 iBookingClassStruct._classCode);
378 if (lBookingClass_ptr == NULL) {
379 // Instantiate a booking class object for the given key (class code);
380 const stdair::BookingClassKey lClassKey (iBookingClassStruct._classCode);
381 lBookingClass_ptr =
382 &stdair::FacBom<stdair::BookingClass>::instance().create (lClassKey);
383
384 // Link the booking-class to the fare family
385 stdair::FacBomManager::addToListAndMap (ioFareFamily, *lBookingClass_ptr);
386 stdair::FacBomManager::linkWithParent (ioFareFamily, *lBookingClass_ptr);
387
388 // Link the booking-class to the segment-cabin
389 stdair::SegmentCabin& lSegmentCabin =
390 stdair::BomManager::getParent<stdair::SegmentCabin> (ioFareFamily);
391 stdair::FacBomManager::addToListAndMap (lSegmentCabin, *lBookingClass_ptr);
392
393 // Link the booking-class to the segment-date
394 stdair::SegmentDate& lSegmentDate =
395 stdair::BomManager::getParent<stdair::SegmentDate> (lSegmentCabin);
396 stdair::FacBomManager::addToListAndMap (lSegmentDate, *lBookingClass_ptr);
397 }
398 assert (lBookingClass_ptr != NULL);
399
400 // TODO: Upcabin the BOM booking-class with the attributes of the
401 // booking-class struct.
402 iBookingClassStruct.fill (*lBookingClass_ptr);
403 }
404
405 // ////////////////////////////////////////////////////////////////////
406 void InventoryBuilder::buildPartnerInventories (stdair::BomRoot& ioBomRoot) {
407
408 // Browse the list of inventories to build partner inventories
409 // within each inventory.
410 const stdair::InventoryList_T& lInvList =
411 stdair::BomManager::getList<stdair::Inventory> (ioBomRoot);
412 for (stdair::InventoryList_T::const_iterator itInv = lInvList.begin();
413 itInv != lInvList.end(); ++itInv) {
414 stdair::Inventory* lCurrentInv_ptr = *itInv;
415 assert (lCurrentInv_ptr != NULL);
416
417 buildPartnerInventories (ioBomRoot, *lCurrentInv_ptr);
418 }
419 }
420
421 // ////////////////////////////////////////////////////////////////////
422 void InventoryBuilder::buildPartnerInventories (stdair::BomRoot& ioBomRoot,
423 stdair::Inventory& ioInventory) {
424
425 // Browse the list of flight-dates to build partner inventories.
426 const stdair::FlightDateList_T& lFlightDateList =
427 stdair::BomManager::getList<stdair::FlightDate> (ioInventory);
428 for (stdair::FlightDateList_T::const_iterator itFlightDate =
429 lFlightDateList.begin();
430 itFlightDate != lFlightDateList.end(); ++itFlightDate) {
431 stdair::FlightDate* lCurrentFlightDate_ptr = *itFlightDate;
432 assert (lCurrentFlightDate_ptr != NULL);
433
434 buildPartnerInventories (ioBomRoot, ioInventory, *lCurrentFlightDate_ptr);
435 }
436
437 }
438
439 // ////////////////////////////////////////////////////////////////////
440 void InventoryBuilder::buildPartnerInventories (stdair::BomRoot& ioBomRoot,
441 stdair::Inventory& ioInventory,
442 stdair::FlightDate& iFlightDate) {
443
444 // Browse the list of flight-dates to build partner inventories.
445 const stdair::SegmentDateList_T& lSegmentDateList =
446 stdair::BomManager::getList<stdair::SegmentDate> (iFlightDate);
447 for (stdair::SegmentDateList_T::const_iterator itSegmentDate =
448 lSegmentDateList.begin();
449 itSegmentDate != lSegmentDateList.end(); ++itSegmentDate) {
450
451 stdair::SegmentDate* lCurrentSegmentDate_ptr = *itSegmentDate;
452 assert (lCurrentSegmentDate_ptr != NULL);
453
454 const stdair::RoutingLegKeyList_T& lRoutingLegKeyList =
455 lCurrentSegmentDate_ptr->getLegKeyList ();
456
457 // Browse the list of routing leg keys.
458 for (stdair::RoutingLegKeyList_T::const_iterator itRoutingLegKey =
459 lRoutingLegKeyList.begin();
460 itRoutingLegKey != lRoutingLegKeyList.end(); ++itRoutingLegKey) {
461
462 // Extract the operating airline code
463 const stdair::ParsedKey& lParsedKey =
464 stdair::BomKeyManager::extractKeys (*itRoutingLegKey);
465 const stdair::InventoryKey& lInventoryKey =
466 lParsedKey.getInventoryKey();
467 const stdair::AirlineCode_T lOperatingAirlineCode =
468 lInventoryKey.getAirlineCode();
469
470 // Extract the current airline code
471 const stdair::AirlineCode_T lAirlineCode =
472 iFlightDate.getAirlineCode();
473
474 // If the operating airline is not the current one
475 if (lOperatingAirlineCode != lAirlineCode) {
476
477 // Look for the inventory of the partner within the Bom root
478 stdair::Inventory* lInventory_ptr =
479 stdair::BomRetriever::
480 retrieveInventoryFromKey (ioBomRoot, lOperatingAirlineCode);
481
482 // Build the current segment full key
483 std::ostringstream lRoutingSegment;
484 lRoutingSegment << iFlightDate.getAirlineCode() << ";"
485 << iFlightDate.describeKey() << ";"
486 << lCurrentSegmentDate_ptr->getBoardingPoint() << ";"
487 << lCurrentSegmentDate_ptr->getOffPoint();
488
489 // If such inventory does not exist, throw an exception
490 if (lInventory_ptr == NULL) {
491 std::ostringstream oMessage;
492 oMessage << "The input file does not contain information about "
493 << "the '" << *itRoutingLegKey << "' leg date needed by "
494 << "the '" << lRoutingSegment.str() << "' segment.";
495 STDAIR_LOG_ERROR (oMessage.str());
496 throw MissingPartnerFlightDateWithinScheduleFile (oMessage.str());
497 }
498 assert (lInventory_ptr != NULL);
499
500 // Build the partner inventory within the current inventory
501 buildInventory (ioBomRoot, ioInventory, *itRoutingLegKey);
502
503 // Build the current inventory as a partner of the partner inventory
504 buildInventory (ioBomRoot, *lInventory_ptr, lRoutingSegment.str());
505 }
506 }
507 }
508 }
509
510 // ////////////////////////////////////////////////////////////////////
511 void InventoryBuilder::
512 buildInventory (stdair::BomRoot& ioBomRoot,
513 stdair::Inventory& ioInventory,
514 const std::string& iFullKeyStr) {
515
516 // Check that the inventory object is not already existing. If an
517 // inventory object with the same key has already been created,
518 // then just update it, ifnot, create an inventory and update it.
519 // for the given key (iFullKeyStr)
520 stdair::Inventory* lInventory_ptr =
521 stdair::BomRetriever::retrieveInventoryFromLongKey (ioInventory,
522 iFullKeyStr);
523 if (lInventory_ptr == NULL) {
524 // Instantiate a flighy-date object for the given key (airline code
525 // within the iFullKeyStr)
526 stdair::Inventory* lOperatingInventory_ptr =
527 stdair::BomRetriever::retrieveInventoryFromLongKey (ioBomRoot,
528 iFullKeyStr);
529 assert (lOperatingInventory_ptr != NULL);
530 lInventory_ptr =
531 &stdair::FacBom<stdair::Inventory>::instance().create (*lOperatingInventory_ptr);
532 stdair::FacBomManager::addToListAndMap (ioInventory, *lInventory_ptr);
533 stdair::FacBomManager::linkWithParent (ioInventory, *lInventory_ptr);
534 }
535 assert (lInventory_ptr != NULL);
536
537 // Build the flight-date within the inventory.
538 buildFlightDate (ioBomRoot, *lInventory_ptr, iFullKeyStr);
539 }
540
541 // ////////////////////////////////////////////////////////////////////
542 void InventoryBuilder::
543 buildFlightDate (stdair::BomRoot& ioBomRoot,
544 stdair::Inventory& ioInventory,
545 const std::string& iFullKeyStr) {
546
547 // Check that the flight-date object is not already existing. If a
548 // flight-date object with the same key has already been created,
549 // then just update it, ifnot, create a flight-date and update it.
550 stdair::FlightDate* lFlightDate_ptr =
551 stdair::BomRetriever::retrieveFlightDateFromLongKey (ioInventory,
552 iFullKeyStr);
553 if (lFlightDate_ptr == NULL) {
554 // Instantiate a flighy-date object for the given key (flight number and
555 // flight date within the iFullKeyStr)
556 stdair::FlightDate* lOperatingFlightDate_ptr =
557 stdair::BomRetriever::retrieveFlightDateFromLongKey (ioBomRoot,
558 iFullKeyStr);
559 assert (lOperatingFlightDate_ptr != NULL);
560 stdair::FlightDate& lFlightDate =
561 cloneFlightDate (*lOperatingFlightDate_ptr);
562 stdair::FacBomManager::addToListAndMap (ioInventory, lFlightDate);
563 stdair::FacBomManager::linkWithParent (ioInventory, lFlightDate);
564 }
565 }
566
567 // ////////////////////////////////////////////////////////////////////
568 stdair::FlightDate& InventoryBuilder::
569 cloneFlightDate (const stdair::FlightDate& iFlightDate) {
570
574 stdair::FlightDate& lCloneFlightDate =
575 stdair::FacBom<stdair::FlightDate>::instance().create (iFlightDate);
576
577 // Check whether there are LegDate objects
578 const bool hasLegDateList = stdair::BomManager::hasList<stdair::LegDate> (iFlightDate);
579 if (hasLegDateList == true) {
580
581 // Browse the leg-dates
582 const stdair::LegDateList_T& lLegDateList =
583 stdair::BomManager::getList<stdair::LegDate> (iFlightDate);
584 for (stdair::LegDateList_T::const_iterator itLD = lLegDateList.begin();
585 itLD != lLegDateList.end(); ++itLD) {
586 const stdair::LegDate* lLD_ptr = *itLD;
587 assert (lLD_ptr != NULL);
588
589 // Clone the current leg-date
590 stdair::LegDate& lCloneLegDate = cloneLegDate (*lLD_ptr);
591 stdair::FacBomManager::addToListAndMap (lCloneFlightDate, lCloneLegDate);
592 stdair::FacBomManager::linkWithParent (lCloneFlightDate, lCloneLegDate);
593 }
594 }
595
596 // Check whether there are SegmentDate objects
597 const bool hasSegmentDateList =
598 stdair::BomManager::hasList<stdair::SegmentDate> (iFlightDate);
599 if (hasSegmentDateList == true) {
600
601 // Browse the segment-dates
602 const stdair::SegmentDateList_T& lSegmentDateList =
603 stdair::BomManager::getList<stdair::SegmentDate> (iFlightDate);
604 for (stdair::SegmentDateList_T::const_iterator itSD = lSegmentDateList.begin();
605 itSD != lSegmentDateList.end(); ++itSD) {
606 const stdair::SegmentDate* lSD_ptr = *itSD;
607 assert (lSD_ptr != NULL);
608
609 // Clone the current segment-date
610 stdair::SegmentDate& lCloneSegmentDate = cloneSegmentDate (*lSD_ptr);
611 stdair::FacBomManager::addToListAndMap (lCloneFlightDate, lCloneSegmentDate);
612 stdair::FacBomManager::linkWithParent (lCloneFlightDate, lCloneSegmentDate);
613
614 }
615 }
616
617 return lCloneFlightDate;
618 }
619
620 // ////////////////////////////////////////////////////////////////////
621 stdair::LegDate& InventoryBuilder::cloneLegDate (const stdair::LegDate& iLegDate) {
622
626 stdair::LegDate& lCloneLegDate =
627 stdair::FacBom<stdair::LegDate>::instance().create (iLegDate);
628
629 // Check whether there are LegCabin objects
630 const bool hasLegCabinList = stdair::BomManager::hasList<stdair::LegCabin> (iLegDate);
631 if (hasLegCabinList == true) {
632 // Browse the leg-cabins
633 const stdair::LegCabinList_T& lLegCabinList =
634 stdair::BomManager::getList<stdair::LegCabin> (iLegDate);
635 for (stdair::LegCabinList_T::const_iterator itLC = lLegCabinList.begin();
636 itLC != lLegCabinList.end(); ++itLC) {
637 const stdair::LegCabin* lLC_ptr = *itLC;
638 assert (lLC_ptr != NULL);
639
640 // Clone the current leg-cabin
641 stdair::LegCabin& lCloneLegCabin = cloneLegCabin (*lLC_ptr);
642 stdair::FacBomManager::addToListAndMap (lCloneLegDate, lCloneLegCabin);
643 stdair::FacBomManager::linkWithParent (lCloneLegDate, lCloneLegCabin);
644 }
645 }
646
647 return lCloneLegDate;
648 }
649
650 // ////////////////////////////////////////////////////////////////////
651 stdair::LegCabin& InventoryBuilder::cloneLegCabin (const stdair::LegCabin& iLegCabin) {
652
656 stdair::LegCabin& lCloneLegCabin =
657 stdair::FacBom<stdair::LegCabin>::instance().create (iLegCabin);
658
659 // Check whether there are Bucket objects
660 const bool hasBucketList = stdair::BomManager::hasList<stdair::Bucket> (iLegCabin);
661 if (hasBucketList == true) {
662 // Browse the buckets
663 const stdair::BucketList_T& lBucketList =
664 stdair::BomManager::getList<stdair::Bucket> (iLegCabin);
665 for (stdair::BucketList_T::const_iterator itBucket = lBucketList.begin();
666 itBucket != lBucketList.end(); ++itBucket) {
667 const stdair::Bucket* lBucket_ptr = *itBucket;
668 assert (lBucket_ptr != NULL);
669
670 // Clone the current bucket
671 stdair::Bucket& lCloneBucket = cloneBucket (*lBucket_ptr);
672 stdair::FacBomManager::addToListAndMap (lCloneLegCabin, lCloneBucket);
673 stdair::FacBomManager::linkWithParent (lCloneLegCabin, lCloneBucket);
674 }
675 }
676
677 return lCloneLegCabin;
678 }
679
680 // ////////////////////////////////////////////////////////////////////
681 stdair::Bucket& InventoryBuilder::cloneBucket (const stdair::Bucket& iBucket) {
682
686 stdair::Bucket& lCloneBucket =
687 stdair::FacBom<stdair::Bucket>::instance().create (iBucket);
688
689 return lCloneBucket;
690 }
691
692 // ////////////////////////////////////////////////////////////////////
693 stdair::SegmentDate& InventoryBuilder::
694 cloneSegmentDate (const stdair::SegmentDate& iSegmentDate) {
695
699 stdair::SegmentDate& lCloneSegmentDate =
700 stdair::FacBom<stdair::SegmentDate>::instance().create (iSegmentDate);
701
702 // Check whether there are SegmentCabin objects
703 const bool hasSegmentCabinList =
704 stdair::BomManager::hasList<stdair::SegmentCabin> (iSegmentDate);
705 if (hasSegmentCabinList == true) {
706 // Browse the segment-cabins
707 const stdair::SegmentCabinList_T& lSegmentCabinList =
708 stdair::BomManager::getList<stdair::SegmentCabin> (iSegmentDate);
709 for (stdair::SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin();
710 itSC != lSegmentCabinList.end(); ++itSC) {
711 const stdair::SegmentCabin* lSC_ptr = *itSC;
712 assert (lSC_ptr != NULL);
713
714 // Clone the current segment-cabin
715 stdair::SegmentCabin& lCloneSegmentCabin = cloneSegmentCabin (*lSC_ptr);
716 stdair::FacBomManager::addToListAndMap (lCloneSegmentDate, lCloneSegmentCabin);
717 stdair::FacBomManager::linkWithParent (lCloneSegmentDate, lCloneSegmentCabin);
718
719 linkBookingClassesWithSegment (lCloneSegmentDate,
720 lCloneSegmentCabin);
721
722 }
723 }
724 return lCloneSegmentDate;
725 }
726
727 // ////////////////////////////////////////////////////////////////////
728 void InventoryBuilder::
729 linkBookingClassesWithSegment (stdair::SegmentDate& iCloneSegmentDate,
730 stdair::SegmentCabin& iCloneSegmentCabin) {
731
732 // Browse the fare families to link the booking-classes to the
733 // segment-cabin and to the segment-date
734 const bool hasFareFamilyList =
735 stdair::BomManager::hasList<stdair::FareFamily> (iCloneSegmentCabin);
736 if (hasFareFamilyList == true) {
737 const stdair::FareFamilyList_T& lCloneFFList =
738 stdair::BomManager::getList<stdair::FareFamily> (iCloneSegmentCabin);
739 for (stdair::FareFamilyList_T::const_iterator itCloneFF = lCloneFFList.begin();
740 itCloneFF != lCloneFFList.end(); ++itCloneFF) {
741 const stdair::FareFamily* lCloneFF_ptr = *itCloneFF;
742 assert (lCloneFF_ptr != NULL);
743
744 // Browse the list of booking classes
745 const bool hasBookingClasslist =
746 stdair::BomManager::hasList<stdair::BookingClass> (*lCloneFF_ptr);
747 if (hasBookingClasslist == true) {
748 const stdair::BookingClassList_T& lCloneBCList =
749 stdair::BomManager::getList<stdair::BookingClass> (*lCloneFF_ptr);
750 for (stdair::BookingClassList_T::const_iterator itCloneBC =
751 lCloneBCList.begin();
752 itCloneBC != lCloneBCList.end(); ++itCloneBC) {
753 const stdair::BookingClass* lCloneBC_ptr = *itCloneBC;
754 assert (lCloneBC_ptr != NULL);
755
756 // Link the booking-class to the segment-cabin
757 stdair::FacBomManager::addToListAndMap (iCloneSegmentCabin,
758 *lCloneBC_ptr);
759
760 // Link the booking-class to the segment-date
761 stdair::FacBomManager::addToListAndMap (iCloneSegmentDate,
762 *lCloneBC_ptr);
763 }
764 }
765 }
766 }
767 }
768
769 // ////////////////////////////////////////////////////////////////////
770 stdair::SegmentCabin& InventoryBuilder::
771 cloneSegmentCabin (const stdair::SegmentCabin& iSegmentCabin) {
772
776 stdair::SegmentCabin& lCloneSegmentCabin =
777 stdair::FacBom<stdair::SegmentCabin>::instance().create (iSegmentCabin);
778
779 // Check whether there are fare family objects
780 const bool hasFareFamilyList =
781 stdair::BomManager::hasList<stdair::FareFamily> (iSegmentCabin);
782 if (hasFareFamilyList == true) {
783 // Browse the fare families
784 const stdair::FareFamilyList_T& lFareFamilyList =
785 stdair::BomManager::getList<stdair::FareFamily> (iSegmentCabin);
786 for (stdair::FareFamilyList_T::const_iterator itFF = lFareFamilyList.begin();
787 itFF != lFareFamilyList.end(); ++itFF) {
788 const stdair::FareFamily* lFF_ptr = *itFF;
789 assert (lFF_ptr != NULL);
790
791 // Clone the current fare-family
792 stdair::FareFamily& lCloneFareFamily = cloneFareFamily (*lFF_ptr);
793 stdair::FacBomManager::addToListAndMap (lCloneSegmentCabin, lCloneFareFamily);
794 stdair::FacBomManager::linkWithParent (lCloneSegmentCabin, lCloneFareFamily);
795 }
796 }
797
798 return lCloneSegmentCabin;
799 }
800
801 // ////////////////////////////////////////////////////////////////////
802 stdair::FareFamily& InventoryBuilder::
803 cloneFareFamily (const stdair::FareFamily& iFareFamily) {
807 stdair::FareFamily& lCloneFareFamily =
808 stdair::FacBom<stdair::FareFamily>::instance().create (iFareFamily);
809
810 // Check whether there are booking classes objects
811 const bool hasBookingClassList =
812 stdair::BomManager::hasList<stdair::BookingClass> (iFareFamily);
813 if (hasBookingClassList == true) {
814 // Browse the list of booking classes
815 const stdair::BookingClassList_T& lBookingClassList =
816 stdair::BomManager::getList<stdair::BookingClass> (iFareFamily);
817 for (stdair::BookingClassList_T::const_iterator itBookingClass =
818 lBookingClassList.begin();
819 itBookingClass != lBookingClassList.end(); ++itBookingClass) {
820 const stdair::BookingClass* lBC_ptr = *itBookingClass;
821 assert (lBC_ptr != NULL);
822
823 // Clone the current booking class
824 stdair::BookingClass& lCloneBookingClass = cloneBookingClass (*lBC_ptr);
825 stdair::FacBomManager::addToListAndMap (lCloneFareFamily, lCloneBookingClass);
826 stdair::FacBomManager::linkWithParent (lCloneFareFamily, lCloneBookingClass);
827 }
828 }
829
830 return lCloneFareFamily;
831 }
832
833 // ////////////////////////////////////////////////////////////////////
834 stdair::BookingClass& InventoryBuilder::
835 cloneBookingClass (const stdair::BookingClass& iBookingClass) {
836
840 stdair::BookingClass& lCloneBookingClass =
841 stdair::FacBom<stdair::BookingClass>::instance().create (iBookingClass);
842
843 return lCloneBookingClass;
844 }
845}
846