7 #include <boost/date_time/date_iterator.hpp>
9 #include <stdair/stdair_types.hpp>
10 #include <stdair/basic/BasConst_Inventory.hpp>
11 #include <stdair/basic/BasConst_SellUpCurves.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/SimpleNestingStructure.hpp>
24 #include <stdair/bom/NestingNode.hpp>
25 #include <stdair/bom/Policy.hpp>
26 #include <stdair/bom/Bucket.hpp>
27 #include <stdair/bom/BomKeyManager.hpp>
28 #include <stdair/factory/FacBomManager.hpp>
29 #include <stdair/service/Logger.hpp>
37 void InventoryGenerator::
38 createFlightDate (stdair::BomRoot& ioBomRoot,
39 const FlightPeriodStruct& iFlightPeriod) {
40 const stdair::AirlineCode_T& lAirlineCode = iFlightPeriod._airlineCode;
44 stdair::Inventory* lInventory_ptr = stdair::BomManager::
45 getObjectPtr<stdair::Inventory> (ioBomRoot, lAirlineCode);
46 if (lInventory_ptr == NULL) {
47 stdair::InventoryKey lKey (lAirlineCode);
49 &stdair::FacBom<stdair::Inventory>::instance().create (lKey);
50 stdair::FacBomManager::addToListAndMap (ioBomRoot, *lInventory_ptr);
51 stdair::FacBomManager::linkWithParent (ioBomRoot, *lInventory_ptr);
54 const stdair::AirlineFeatureKey lAirlineFeatureKey (lAirlineCode);
55 stdair::AirlineFeature& lAirlineFeature =
56 stdair::FacBom<stdair::AirlineFeature>::instance().create (lAirlineFeatureKey);
57 stdair::FacBomManager::setAirlineFeature (*lInventory_ptr,
59 stdair::FacBomManager::linkWithParent (*lInventory_ptr, lAirlineFeature);
61 stdair::FacBomManager::addToListAndMap (ioBomRoot, lAirlineFeature);
63 assert (lInventory_ptr != NULL);
67 const stdair::DatePeriod_T lDateRange = iFlightPeriod._dateRange;
69 for (boost::gregorian::day_iterator itDate = lDateRange.begin();
70 itDate != lDateRange.end(); ++itDate) {
71 const stdair::Date_T& currentDate = *itDate;
74 const unsigned short currentDoW = currentDate.day_of_week().as_number();
79 const stdair::DoWStruct& lDoWList = iFlightPeriod._dow;
80 const bool isDoWActive = lDoWList.getStandardDayOfWeek (currentDoW);
82 if (isDoWActive ==
true) {
83 createFlightDate (ioBomRoot, *lInventory_ptr, currentDate,
90 void InventoryGenerator::
91 createFlightDate (stdair::BomRoot& ioBomRoot,
92 stdair::Inventory& ioInventory,
93 const stdair::Date_T& iFlightDate,
94 const FlightPeriodStruct& iFlightPeriod) {
96 const stdair::FlightNumber_T& lFlightNumber = iFlightPeriod._flightNumber;
97 stdair::FlightDateKey lFlightDateKey (lFlightNumber, iFlightDate);
106 stdair::FlightDate* lFlightDate_ptr = stdair::BomManager::
107 getObjectPtr<stdair::FlightDate> (ioInventory, lFlightDateKey.toString());
108 if (lFlightDate_ptr != NULL) {
109 std::ostringstream oMessage;
110 oMessage << ioInventory.describeKey() <<
", "
111 << lFlightDate_ptr->describeKey();
112 throw FlightDateDuplicationException (oMessage.str());
118 &stdair::FacBom<stdair::FlightDate>::instance().create (lFlightDateKey);
119 stdair::FacBomManager::addToListAndMap (ioInventory, *lFlightDate_ptr);
120 stdair::FacBomManager::linkWithParent (ioInventory, *lFlightDate_ptr);
123 stdair::Duration_T currentOffTime (0, 0, 0);
124 stdair::AirportCode_T previousOffPoint;
126 for (LegStructList_T::const_iterator itLeg = lLegList.begin();
127 itLeg != lLegList.end(); ++itLeg) {
128 const LegStruct& lLeg = *itLeg;
131 stdair::LegDate& lLegDate =
132 createLegDate (*lFlightDate_ptr, iFlightDate, lLeg);
145 if (itLeg != lLegList.begin()) {
146 const stdair::AirportCode_T& currentBoardingPoint =
147 lLegDate.getBoardingPoint();
148 assert (currentBoardingPoint == previousOffPoint);
152 previousOffPoint = lLegDate.getOffPoint();
157 for (SegmentStructList_T::const_iterator itSegment = lSegmentList.begin();
158 itSegment != lSegmentList.end(); ++itSegment) {
159 const SegmentStruct& lSegment = *itSegment;
161 createSegmentDate (ioBomRoot, *lFlightDate_ptr, lSegment);
164 createRoutingLegKey (*lFlightDate_ptr);
168 void InventoryGenerator::
169 createRoutingLegKey (stdair::FlightDate& ioFlightDate) {
173 const stdair::SegmentDateList_T& lSegmentDateList =
174 stdair::BomManager::getList<stdair::SegmentDate> (ioFlightDate);
175 for (stdair::SegmentDateList_T::const_iterator itSegmentDate =
176 lSegmentDateList.begin();
177 itSegmentDate != lSegmentDateList.end(); ++itSegmentDate) {
179 stdair::SegmentDate* lCurrentSegmentDate_ptr = *itSegmentDate;
180 assert (lCurrentSegmentDate_ptr != NULL);
182 const stdair::AirportCode_T& lBoardingPoint =
183 lCurrentSegmentDate_ptr->getBoardingPoint();
185 stdair::AirportCode_T currentBoardingPoint = lBoardingPoint;
186 const stdair::AirportCode_T& lOffPoint =
187 lCurrentSegmentDate_ptr->getOffPoint();
194 unsigned short i = 1;
195 while (currentBoardingPoint != lOffPoint
196 && i <= stdair::MAXIMAL_NUMBER_OF_LEGS_IN_FLIGHT) {
198 stdair::LegDate& lLegDate = stdair::BomManager::
199 getObject<stdair::LegDate> (ioFlightDate, currentBoardingPoint);
202 const std::string& lRoutingKeyStr = lLegDate.describeRoutingKey();
203 lCurrentSegmentDate_ptr->addLegKey(lRoutingKeyStr);
206 currentBoardingPoint = lLegDate.getOffPoint();
209 assert (i <= stdair::MAXIMAL_NUMBER_OF_LEGS_IN_FLIGHT);
214 stdair::LegDate& InventoryGenerator::
215 createLegDate (stdair::FlightDate& ioFlightDate,
216 const stdair::Date_T& iReferenceDate,
217 const LegStruct& iLeg) {
219 stdair::LegDateKey lKey (iLeg._boardingPoint);
220 stdair::LegDate& lLegDate =
221 stdair::FacBom<stdair::LegDate>::instance().create (lKey);
222 stdair::FacBomManager::addToListAndMap (ioFlightDate, lLegDate);
223 stdair::FacBomManager::linkWithParent (ioFlightDate, lLegDate);
226 iLeg.fill (iReferenceDate, lLegDate);
230 for (LegCabinStructList_T::const_iterator itCabin = lCabinList.begin();
231 itCabin != lCabinList.end(); ++itCabin) {
232 const LegCabinStruct& lCabin = *itCabin;
235 createLegCabin (lLegDate, lCabin);
242 void InventoryGenerator::
243 createLegCabin (stdair::LegDate& ioLegDate,
244 const LegCabinStruct& iCabin) {
246 const stdair::LegCabinKey lKey (iCabin._cabinCode);
247 stdair::LegCabin& lLegCabin =
248 stdair::FacBom<stdair::LegCabin>::instance().create (lKey);
249 stdair::FacBomManager::addToListAndMap (ioLegDate, lLegCabin);
250 stdair::FacBomManager::linkWithParent (ioLegDate, lLegCabin);
253 iCabin.fill (lLegCabin);
257 for (BucketStructList_T::const_iterator itBucket = lBucketList.begin();
258 itBucket != lBucketList.end(); ++itBucket) {
259 const BucketStruct& lBucket = *itBucket;
262 createBucket (lLegCabin, lBucket);
267 void InventoryGenerator::createBucket (stdair::LegCabin& ioLegCabin,
268 const BucketStruct& iBucket) {
270 const stdair::BucketKey lKey (iBucket._seatIndex);
271 stdair::Bucket& lBucket =
272 stdair::FacBom<stdair::Bucket>::instance().create (lKey);
273 stdair::FacBomManager::addToListAndMap (ioLegCabin, lBucket);
274 stdair::FacBomManager::linkWithParent (ioLegCabin, lBucket);
277 iBucket.fill (lBucket);
281 void InventoryGenerator::
282 createSegmentDate (stdair::BomRoot& ioBomRoot,
283 stdair::FlightDate& ioFlightDate,
284 const SegmentStruct& iSegment) {
286 const stdair::AirportCode_T& lBoardingPoint = iSegment._boardingPoint;
287 const stdair::AirportCode_T& lOffPoint = iSegment._offPoint;
288 stdair::SegmentDateKey lSegmentDateKey (lBoardingPoint, lOffPoint);
290 stdair::SegmentDate& lSegmentDate =
291 stdair::FacBom<stdair::SegmentDate>::instance().create (lSegmentDateKey);
292 stdair::FacBomManager::addToListAndMap (ioFlightDate, lSegmentDate);
293 stdair::FacBomManager::linkWithParent (ioFlightDate, lSegmentDate);
296 iSegment.fill (lSegmentDate);
300 for (SegmentCabinStructList_T::const_iterator itCabin =
301 lCabinList.begin(); itCabin != lCabinList.end(); ++itCabin) {
302 const SegmentCabinStruct& lCabin = *itCabin;
305 createSegmentCabin (ioBomRoot, lSegmentDate, lCabin);
310 void InventoryGenerator::
311 createSegmentCabin (stdair::BomRoot& ioBomRoot,
312 stdair::SegmentDate& ioSegmentDate,
313 const SegmentCabinStruct& iCabin) {
316 stdair::SegmentCabinKey lKey (iCabin._cabinCode);
317 stdair::SegmentCabin& lSegmentCabin =
318 stdair::FacBom<stdair::SegmentCabin>::instance().create (lKey);
321 stdair::FacBomManager::addToListAndMap (ioSegmentDate, lSegmentCabin);
322 stdair::FacBomManager::linkWithParent (ioSegmentDate, lSegmentCabin);
325 iCabin.fill (lSegmentCabin);
328 for (FareFamilyStructList_T::const_iterator itFareFamily =
329 iCabin._fareFamilies.begin();
330 itFareFamily != iCabin._fareFamilies.end(); itFareFamily++) {
331 const FareFamilyStruct& lFareFamilyStruct = *itFareFamily;
334 createFareFamily (ioBomRoot, lSegmentCabin, lFareFamilyStruct);
337 const unsigned int lNbOfFareFamilies = iCabin._fareFamilies.size();
338 if (lNbOfFareFamilies > 1) {
339 lSegmentCabin.activateFareFamily();
343 createDisplayNestingStructure (lSegmentCabin);
347 void InventoryGenerator::
348 createFareFamily (stdair::BomRoot& ioBomRoot,
349 stdair::SegmentCabin& ioSegmentCabin,
350 const FareFamilyStruct& iFF) {
352 stdair::FareFamilyKey lKey (iFF._familyCode);
353 stdair::FareFamily& lFareFamily =
354 stdair::FacBom<stdair::FareFamily>::instance().create (lKey);
357 stdair::FacBomManager::addToListAndMap (ioSegmentCabin, lFareFamily);
358 stdair::FacBomManager::linkWithParent (ioSegmentCabin, lFareFamily);
361 iFF.fill (lFareFamily);
363 ioBomRoot.getFRAT5Curve (iFF._frat5CurveKey);
364 lFareFamily.setFrat5Curve (lFRAT5Curve);
365 const stdair::FFDisutilityCurve_T& lDisutilityCurve =
366 ioBomRoot.getFFDisutilityCurve (iFF._ffDisutilityCurveKey);
367 lFareFamily.setDisutilityCurve (lDisutilityCurve);
370 const stdair::ClassList_String_T& lClassList = iFF._classes;
371 for (stdair::ClassList_String_T::const_iterator itClass =
372 lClassList.begin(); itClass != lClassList.end(); ++itClass) {
374 std::ostringstream ostr;
376 const stdair::ClassCode_T lClassCode (ostr.str());
379 createClass (lFareFamily, lClassCode);
384 void InventoryGenerator::createClass (stdair::FareFamily& ioFareFamily,
385 const stdair::ClassCode_T& iClassCode) {
388 const stdair::BookingClassKey lClassKey (iClassCode);
389 stdair::BookingClass& lClass =
390 stdair::FacBom<stdair::BookingClass>::instance().create (lClassKey);
393 stdair::FacBomManager::addToListAndMap (ioFareFamily, lClass);
394 stdair::FacBomManager::linkWithParent (ioFareFamily, lClass);
397 stdair::SegmentCabin& lSegmentCabin =
398 stdair::BomManager::getParent<stdair::SegmentCabin> (ioFareFamily);
399 stdair::FacBomManager::addToListAndMap (lSegmentCabin, lClass);
402 stdair::SegmentDate& lSegmentDate =
403 stdair::BomManager::getParent<stdair::SegmentDate> (lSegmentCabin);
404 stdair::FacBomManager::addToListAndMap (lSegmentDate, lClass);
408 void InventoryGenerator::
409 createDisplayNestingStructure (stdair::SegmentCabin& ioSegmentCabin) {
411 stdair::NestingStructureKey lKey (stdair::DISPLAY_NESTING_STRUCTURE_CODE);
412 stdair::SimpleNestingStructure& lNestingStructure =
413 stdair::FacBom<stdair::SimpleNestingStructure>::instance().create(lKey);
414 stdair::FacBomManager::addToListAndMap (ioSegmentCabin, lNestingStructure);
415 stdair::FacBomManager::linkWithParent (ioSegmentCabin, lNestingStructure);
419 const stdair::BookingClassList_T& lBCList =
420 stdair::BomManager::getList<stdair::BookingClass>(ioSegmentCabin);
421 for (stdair::BookingClassList_T::const_iterator itBC = lBCList.begin();
422 itBC != lBCList.end(); ++itBC) {
423 stdair::BookingClass* lBC_ptr = *itBC;
424 assert (lBC_ptr != NULL);
427 stdair::NestingNodeCode_T lNodeCode (lBC_ptr->describeKey());
428 stdair::NestingNodeKey lNodeKey (lNodeCode);
429 stdair::NestingNode& lNestingNode =
430 stdair::FacBom<stdair::NestingNode>::instance().create (lNodeKey);
431 stdair::FacBomManager::addToList (lNestingStructure, lNestingNode);
432 stdair::FacBomManager::linkWithParent (lNestingStructure, lNestingNode);
435 stdair::FacBomManager::addToList (lNestingNode, *lBC_ptr);