AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
InventoryBuilder.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // Boost
00007 #include <boost/date_time/date_iterator.hpp>
00008 // StdAir
00009 #include <stdair/basic/BasConst_BookingClass.hpp>
00010 #include <stdair/basic/BasConst_Yield.hpp>
00011 #include <stdair/basic/BasConst_Inventory.hpp>
00012 #include <stdair/bom/BomManager.hpp>
00013 #include <stdair/bom/BomRoot.hpp>
00014 #include <stdair/bom/Inventory.hpp>
00015 #include <stdair/bom/FlightDate.hpp>
00016 #include <stdair/bom/SegmentDate.hpp>
00017 #include <stdair/bom/SegmentCabin.hpp>
00018 #include <stdair/bom/FareFamily.hpp>
00019 #include <stdair/bom/BookingClass.hpp>
00020 #include <stdair/bom/LegDate.hpp>
00021 #include <stdair/bom/LegCabin.hpp>
00022 #include <stdair/bom/Bucket.hpp>
00023 #include <stdair/factory/FacBom.hpp>
00024 #include <stdair/factory/FacBomManager.hpp>
00025 #include <stdair/service/Logger.hpp>
00026 // AirInv
00027 #include <airinv/bom/FlightDateStruct.hpp>
00028 #include <airinv/command/InventoryBuilder.hpp>
00029 
00030 namespace AIRINV {
00031 
00032   // ////////////////////////////////////////////////////////////////////
00033   void InventoryBuilder::
00034   buildInventory (stdair::BomRoot& ioBomRoot,
00035                   const FlightDateStruct& iFlightDateStruct) {
00036     const stdair::AirlineCode_T& lAirlineCode = iFlightDateStruct._airlineCode;
00037  
00038     // Instantiate an inventory object (if not exist)
00039     // for the given key (airline code)
00040     stdair::Inventory* lInventory_ptr = stdair::BomManager::
00041       getObjectPtr<stdair::Inventory> (ioBomRoot, lAirlineCode);
00042     if (lInventory_ptr == NULL) {
00043       stdair::InventoryKey lKey (lAirlineCode);
00044       lInventory_ptr =
00045         &stdair::FacBom<stdair::Inventory>::instance().create (lKey);
00046       stdair::FacBomManager::addToListAndMap (ioBomRoot, *lInventory_ptr);
00047       stdair::FacBomManager::linkWithParent (ioBomRoot, *lInventory_ptr);
00048     }
00049     assert (lInventory_ptr != NULL);
00050 
00051     // Build the flight-date within the inventory.
00052     buildFlightDate (*lInventory_ptr, iFlightDateStruct);
00053   }
00054 
00055   // ////////////////////////////////////////////////////////////////////
00056   void InventoryBuilder::
00057   buildFlightDate (stdair::Inventory& ioInventory,
00058                    const FlightDateStruct& iFlightDateStruct) {
00059     // Create the FlightDateKey
00060     const stdair::FlightDateKey lFlightDateKey (iFlightDateStruct._flightNumber,
00061                                                 iFlightDateStruct._flightDate);
00062 
00063     // Check that the flight-date object is not already existing. If a
00064     // flight-date object with the same key has already been created,
00065     // then just update it, ifnot, create a flight-date and update it.
00066     stdair::FlightDate* lFlightDate_ptr = stdair::BomManager::
00067       getObjectPtr<stdair::FlightDate> (ioInventory, lFlightDateKey.toString());
00068     if (lFlightDate_ptr == NULL) {
00069       // Instantiate a flighy-date object for the given key (flight number and
00070       // flight date)
00071       lFlightDate_ptr =
00072         &stdair::FacBom<stdair::FlightDate>::instance().create (lFlightDateKey);
00073       stdair::FacBomManager::addToListAndMap (ioInventory, *lFlightDate_ptr);
00074       stdair::FacBomManager::linkWithParent (ioInventory, *lFlightDate_ptr);
00075     }
00076     assert (lFlightDate_ptr != NULL);
00077 
00078     // Update the BOM flight-date with the attributes of the flight-date struct.
00079     
00080     // Browse the list of leg-date struct and segment-date struct and
00081     // create the corresponding BOM.
00082     for (LegStructList_T::const_iterator itLegDate =
00083            iFlightDateStruct._legList.begin();
00084          itLegDate != iFlightDateStruct._legList.end(); ++itLegDate) {
00085       const LegStruct& lCurrentLegDateStruct = *itLegDate;
00086       buildLegDate (*lFlightDate_ptr, lCurrentLegDateStruct);
00087     }
00088 
00089     for (SegmentStructList_T::const_iterator itSegmentDate =
00090            iFlightDateStruct._segmentList.begin();
00091          itSegmentDate != iFlightDateStruct._segmentList.end();
00092          ++itSegmentDate) {
00093       const SegmentStruct& lCurrentSegmentDateStruct = *itSegmentDate;
00094       buildSegmentDate (*lFlightDate_ptr, lCurrentSegmentDateStruct);
00095     }
00096   }
00097 
00098   // ////////////////////////////////////////////////////////////////////
00099   void InventoryBuilder::
00100   buildLegDate (stdair::FlightDate& ioFlightDate,
00101                 const LegStruct& iLegDateStruct) {
00102     // Check that the leg-date object is not already existing. If a
00103     // leg-date object with the same key has already been created,
00104     // then just update it, ifnot, create a leg-date and update it.
00105     stdair::LegDate* lLegDate_ptr = stdair::BomManager::
00106       getObjectPtr<stdair::LegDate>(ioFlightDate, iLegDateStruct._boardingPoint);
00107 
00108     if (lLegDate_ptr == NULL) {
00109       // Instantiate a leg-date object for the given key (boarding point);
00110       stdair::LegDateKey lKey (iLegDateStruct._boardingPoint);
00111       lLegDate_ptr = &stdair::FacBom<stdair::LegDate>::instance().create (lKey);
00112       stdair::FacBomManager::addToListAndMap (ioFlightDate, *lLegDate_ptr);
00113       stdair::FacBomManager::linkWithParent (ioFlightDate, *lLegDate_ptr);
00114     }
00115     assert (lLegDate_ptr != NULL);
00116 
00117     // Update the BOM leg-date with the attributes of the leg-date struct.
00118     iLegDateStruct.fill (*lLegDate_ptr);
00119 
00120     // Browse the list of leg-cabin structs and create the corresponding BOM.
00121     for (LegCabinStructList_T::const_iterator itLegCabin =
00122            iLegDateStruct._cabinList.begin();
00123          itLegCabin != iLegDateStruct._cabinList.end(); ++itLegCabin) {
00124       const LegCabinStruct& lCurrentLegCabinStruct = *itLegCabin;
00125       buildLegCabin (*lLegDate_ptr, lCurrentLegCabinStruct);
00126     }
00127   }
00128 
00129   // ////////////////////////////////////////////////////////////////////
00130   void InventoryBuilder::
00131   buildLegCabin (stdair::LegDate& ioLegDate,
00132                  const LegCabinStruct& iLegCabinStruct) {
00133     // Check that the leg-cabin object is not already existing. If a
00134     // leg-cabin object with the same key has already been created,
00135     // then just update it, ifnot, create a leg-cabin and update it.
00136     stdair::LegCabin* lLegCabin_ptr = stdair::BomManager::
00137       getObjectPtr<stdair::LegCabin> (ioLegDate, iLegCabinStruct._cabinCode);
00138     if (lLegCabin_ptr == NULL) {
00139       // Instantiate a leg-cabin object for the given key (cabin code);
00140       stdair::LegCabinKey lKey (iLegCabinStruct._cabinCode);
00141       lLegCabin_ptr = &stdair::FacBom<stdair::LegCabin>::instance().create(lKey);
00142       stdair::FacBomManager::addToListAndMap (ioLegDate, *lLegCabin_ptr);
00143       stdair::FacBomManager::linkWithParent (ioLegDate, *lLegCabin_ptr);
00144     }
00145     assert (lLegCabin_ptr != NULL);
00146 
00147     // TODO: Update the BOM leg-cabin with the attributes of the
00148     // leg-cabin struct.
00149     iLegCabinStruct.fill (*lLegCabin_ptr);
00150 
00151     // Browse the list of bucket structs and create the corresponding BOM.
00152     for (BucketStructList_T::const_iterator itBucket =
00153            iLegCabinStruct._bucketList.begin();
00154          itBucket != iLegCabinStruct._bucketList.end(); ++itBucket) {
00155       const BucketStruct& lCurrentBucketStruct = *itBucket;
00156       buildBucket (*lLegCabin_ptr, lCurrentBucketStruct);
00157     }
00158   }
00159 
00160   // ////////////////////////////////////////////////////////////////////
00161   void InventoryBuilder::buildBucket (stdair::LegCabin& ioLegCabin,
00162                                       const BucketStruct& iBucketStruct) {
00163     // Create the BucketKey
00164     const stdair::BucketKey lBucketKey (iBucketStruct._seatIndex);
00165 
00166     // Check that the bucket object is not already existing. If a
00167     // bucket object with the same key has already been created,
00168     // then just update it, ifnot, create a bucket and update it.
00169     stdair::Bucket* lBucket_ptr = stdair::BomManager::
00170       getObjectPtr<stdair::Bucket> (ioLegCabin, lBucketKey.toString());
00171     if (lBucket_ptr == NULL) {
00172       // Instantiate a bucket object for the given key (seat index);
00173       stdair::BucketKey lKey (iBucketStruct._seatIndex);
00174       lBucket_ptr = &stdair::FacBom<stdair::Bucket>::instance().create (lKey);
00175       stdair::FacBomManager::addToListAndMap (ioLegCabin, *lBucket_ptr);
00176       stdair::FacBomManager::linkWithParent (ioLegCabin, *lBucket_ptr);
00177     }
00178     assert (lBucket_ptr != NULL);
00179 
00180     //
00181     iBucketStruct.fill (*lBucket_ptr);
00182   }
00183 
00184   // ////////////////////////////////////////////////////////////////////
00185   void InventoryBuilder::
00186   buildSegmentDate (stdair::FlightDate& ioFlightDate,
00187                     const SegmentStruct& iSegmentDateStruct) {
00188     // Check that the segment-date object is not already existing. If a
00189     // segment-date object with the same key has already been created,
00190     // then just update it, ifnot, create a segment-date and update it.
00191     const stdair::SegmentDateKey
00192       lSegmentDateKey (iSegmentDateStruct._boardingPoint,
00193                        iSegmentDateStruct._offPoint);
00194     stdair::SegmentDate* lSegmentDate_ptr = stdair::BomManager::
00195       getObjectPtr<stdair::SegmentDate>(ioFlightDate,lSegmentDateKey.toString());
00196     if (lSegmentDate_ptr == NULL) {
00197       // Instantiate a segment-date object for the given key (boarding
00198       // and off points);
00199       lSegmentDate_ptr =  &stdair::FacBom<stdair::SegmentDate>::
00200         instance().create (lSegmentDateKey);
00201       stdair::FacBomManager::addToListAndMap (ioFlightDate, *lSegmentDate_ptr);
00202       stdair::FacBomManager::linkWithParent (ioFlightDate, *lSegmentDate_ptr);
00203     }
00204     assert (lSegmentDate_ptr != NULL);
00205 
00206     // Update the BOM segment-date with the attributes of the
00207     // segment-date struct.
00208     iSegmentDateStruct.fill (*lSegmentDate_ptr);
00209 
00210     // Browse the list of segment-cabin struct and create the corresponding BOM.
00211     for (SegmentCabinStructList_T::const_iterator itSegmentCabin =
00212            iSegmentDateStruct._cabinList.begin();
00213          itSegmentCabin != iSegmentDateStruct._cabinList.end(); 
00214          ++itSegmentCabin) {
00215       const SegmentCabinStruct& lCurrentSegmentCabinStruct = *itSegmentCabin;
00216       buildSegmentCabin (*lSegmentDate_ptr, lCurrentSegmentCabinStruct);
00217     }
00218   }
00219 
00220   // ////////////////////////////////////////////////////////////////////
00221   void InventoryBuilder::
00222   buildSegmentCabin (stdair::SegmentDate& ioSegmentDate,
00223                      const SegmentCabinStruct& iSegmentCabinStruct) {
00224     // Check that the segment-cabin object is not already existing. If a
00225     // segment-cabin object with the same key has already been created,
00226     // then just update it, ifnot, create a segment-cabin and update it.
00227     stdair::SegmentCabin* lSegmentCabin_ptr = stdair::BomManager::
00228       getObjectPtr<stdair::SegmentCabin> (ioSegmentDate,
00229                                           iSegmentCabinStruct._cabinCode);
00230     if (lSegmentCabin_ptr == NULL) {
00231       // Instantiate a segment-cabin object for the given key (cabin code);
00232       stdair::SegmentCabinKey lKey (iSegmentCabinStruct._cabinCode);
00233       lSegmentCabin_ptr = 
00234         &stdair::FacBom<stdair::SegmentCabin>::instance().create (lKey);
00235 
00236       // Link the segment-cabin to the segment-date
00237       stdair::FacBomManager::addToListAndMap (ioSegmentDate, *lSegmentCabin_ptr);
00238       stdair::FacBomManager::linkWithParent (ioSegmentDate, *lSegmentCabin_ptr);
00239     }
00240     assert (lSegmentCabin_ptr != NULL);
00241 
00242     // TODO: Update the BOM segment-cabin with the attributes of the
00243     // segment-cabin struct.
00244     iSegmentCabinStruct.fill (*lSegmentCabin_ptr);
00245 
00246     // Browse the list of fare family struct and create the corresponding BOM.
00247     for (FareFamilyStructList_T::const_iterator itFareFamily =
00248            iSegmentCabinStruct._fareFamilies.begin();
00249          itFareFamily != iSegmentCabinStruct._fareFamilies.end(); 
00250          ++itFareFamily) {
00251       const FareFamilyStruct& lCurrentFareFamilyStruct = *itFareFamily;
00252       buildFareFamily (*lSegmentCabin_ptr, lCurrentFareFamilyStruct);
00253     }
00254   }
00255 
00256   // ////////////////////////////////////////////////////////////////////
00257   void InventoryBuilder::
00258   buildFareFamily (stdair::SegmentCabin& ioSegmentCabin,
00259                    const FareFamilyStruct& iFareFamilyStruct) {
00260 
00261     // Check that the fare family object is not already existing. If a
00262     // fare family object with the same key has already been created,
00263     // then just update it. If not, create a fare family and update it.
00264     stdair::FareFamily* lFareFamily_ptr = stdair::BomManager::
00265       getObjectPtr<stdair::FareFamily> (ioSegmentCabin,
00266                                         iFareFamilyStruct._familyCode);
00267     if (lFareFamily_ptr == NULL) {
00268       // Instantiate a fare family object for the given key (fare family code);
00269       const stdair::FareFamilyKey lFFKey (iFareFamilyStruct._familyCode);
00270       lFareFamily_ptr = 
00271         &stdair::FacBom<stdair::FareFamily>::instance().create (lFFKey);
00272 
00273       // Link the fare family to the segment-cabin
00274       stdair::FacBomManager::addToListAndMap (ioSegmentCabin, *lFareFamily_ptr);
00275       stdair::FacBomManager::linkWithParent (ioSegmentCabin, *lFareFamily_ptr);
00276     }
00277     assert (lFareFamily_ptr != NULL);
00278 
00279     // TODO: Upcabin the BOM fare family with the attributes of the
00280     // fare family struct.
00281     iFareFamilyStruct.fill (*lFareFamily_ptr);
00282 
00283     // Browse the list of booking-class struct and create the corresponding BOM.
00284     for (BookingClassStructList_T::const_iterator itBookingClass =
00285            iFareFamilyStruct._classList.begin();
00286          itBookingClass != iFareFamilyStruct._classList.end(); 
00287          ++itBookingClass) {
00288       const BookingClassStruct& lCurrentBookingClassStruct = *itBookingClass;
00289       buildBookingClass (*lFareFamily_ptr, lCurrentBookingClassStruct);
00290     }
00291   }
00292 
00293   // ////////////////////////////////////////////////////////////////////
00294   void InventoryBuilder::
00295   buildBookingClass (stdair::FareFamily& ioFareFamily,
00296                      const BookingClassStruct& iBookingClassStruct) {
00297 
00298     // Check that the booking class object is not already existing. If a
00299     // booking-class object with the same key has already been created,
00300     // then just update it. If not, create a booking-class and update it.
00301     stdair::BookingClass* lBookingClass_ptr = stdair::BomManager::
00302       getObjectPtr<stdair::BookingClass> (ioFareFamily,
00303                                           iBookingClassStruct._classCode);
00304     if (lBookingClass_ptr == NULL) {
00305       // Instantiate a booking class object for the given key (class code);
00306       const stdair::BookingClassKey lClassKey (iBookingClassStruct._classCode);
00307       lBookingClass_ptr = 
00308         &stdair::FacBom<stdair::BookingClass>::instance().create (lClassKey);
00309 
00310       // Link the booking-class to the fare family
00311       stdair::FacBomManager::addToListAndMap (ioFareFamily, *lBookingClass_ptr);
00312       stdair::FacBomManager::linkWithParent (ioFareFamily, *lBookingClass_ptr);
00313 
00314       // Link the booking-class to the segment-cabin
00315       stdair::SegmentCabin& lSegmentCabin =
00316         stdair::BomManager::getParent<stdair::SegmentCabin> (ioFareFamily);
00317       stdair::FacBomManager::addToListAndMap (lSegmentCabin, *lBookingClass_ptr);
00318 
00319       // Link the booking-class to the segment-date
00320       stdair::SegmentDate& lSegmentDate =
00321         stdair::BomManager::getParent<stdair::SegmentDate> (lSegmentCabin);
00322       stdair::FacBomManager::addToListAndMap (lSegmentDate, *lBookingClass_ptr);
00323     }
00324     assert (lBookingClass_ptr != NULL);
00325 
00326     // TODO: Upcabin the BOM booking-class with the attributes of the
00327     // booking-class struct.
00328     iBookingClassStruct.fill (*lBookingClass_ptr);
00329   }
00330   
00331 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines