$treeview $search $mathjax
SimFQT Logo  1.00.1
$projectbrief
$projectbrief
$searchbox

FareRuleGenerator.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // StdAir
00007 #include <stdair/bom/BomManager.hpp>
00008 #include <stdair/bom/BomRoot.hpp>
00009 #include <stdair/factory/FacBomManager.hpp>
00010 #include <stdair/service/Logger.hpp>
00011 #include <stdair/bom/AirportPair.hpp>
00012 #include <stdair/bom/PosChannel.hpp>
00013 #include <stdair/bom/DatePeriod.hpp>
00014 #include <stdair/bom/TimePeriod.hpp>
00015 #include <stdair/bom/FareFeatures.hpp>
00016 #include <stdair/bom/AirlineClassList.hpp>
00017 // SimFQT
00018 #include <simfqt/bom/FareRuleStruct.hpp>
00019 #include <simfqt/command/FareRuleGenerator.hpp>
00020 
00021 namespace SIMFQT {
00022 
00023   // //////////////////////////////////////////////////////////////////////
00024   void FareRuleGenerator::
00025   createAirportPair (stdair::BomRoot& ioBomRoot,
00026                      const FareRuleStruct& iFareRuleStruct) {
00027 
00028     // Create the airport-pair primary key.
00029     const stdair::AirportCode_T& lBoardPoint = iFareRuleStruct.getOrigin ();
00030     const stdair::AirportCode_T& lOffPoint =
00031       iFareRuleStruct.getDestination ();
00032     const stdair::AirportPairKey lAirportPairKey (lBoardPoint, lOffPoint);
00033 
00034     // Check that the airport-pair object is not already existing. If an
00035     // airport-pair object with the same key has not already been created,
00036     // create it and link it to the ioBomRoot object.
00037     stdair::AirportPair* lAirportPair_ptr = stdair::BomManager::
00038       getObjectPtr<stdair::AirportPair> (ioBomRoot, lAirportPairKey.toString());
00039     if (lAirportPair_ptr == NULL) {
00040       lAirportPair_ptr =
00041         &stdair::FacBom<stdair::AirportPair>::instance().
00042         create (lAirportPairKey);
00043       stdair::FacBomManager::addToListAndMap (ioBomRoot, *lAirportPair_ptr);
00044       stdair::FacBomManager::linkWithParent (ioBomRoot, *lAirportPair_ptr);
00045     }
00046     // Sanity check.
00047     assert (lAirportPair_ptr != NULL);
00048 
00049     stdair::AirportPair& lAirportPair = *lAirportPair_ptr;
00050     // Generate the date-period object corresponding to the given
00051     // fareRule.  
00052     createDateRange (lAirportPair, iFareRuleStruct);
00053 
00054   }
00055 
00056   // //////////////////////////////////////////////////////////////////////
00057   void FareRuleGenerator::
00058   createDateRange (stdair::AirportPair& iAirportPair,
00059                    const FareRuleStruct& iFareRuleStruct) {
00060 
00061     // Create the fare date-period primary key.
00062     const stdair::Date_T& lDateRangeStart =
00063       iFareRuleStruct.getDateRangeStart ();
00064     const stdair::Date_T& lDateRangeEnd =
00065       iFareRuleStruct.getDateRangeEnd ();
00066     const stdair::DatePeriod_T lDatePeriod (lDateRangeStart, lDateRangeEnd); 
00067     const stdair::DatePeriodKey lFareDatePeriodKey (lDatePeriod);
00068 
00069     // Check that the date-period object is not already existing.
00070     // If a date-period object with the same key has not already been
00071     // created, create it and link it to the airport-pair object.         
00072     stdair::DatePeriod* lFareDatePeriod_ptr = stdair::BomManager::
00073       getObjectPtr<stdair::DatePeriod> (iAirportPair, 
00074                                         lFareDatePeriodKey.toString());
00075     if (lFareDatePeriod_ptr == NULL) {
00076       lFareDatePeriod_ptr = &stdair::FacBom<stdair::DatePeriod>::instance().
00077         create (lFareDatePeriodKey);
00078       stdair::FacBomManager::addToListAndMap (iAirportPair,
00079                                               *lFareDatePeriod_ptr);
00080       stdair::FacBomManager::linkWithParent (iAirportPair,
00081                                              *lFareDatePeriod_ptr);
00082     }
00083     // Sanity check.
00084     assert (lFareDatePeriod_ptr != NULL);
00085 
00086     stdair::DatePeriod& lDateRange = *lFareDatePeriod_ptr;
00087     // Generate the point_of_sale-channel object corresponding to
00088     // the given fareRule.
00089     createPOSChannel (lDateRange, iFareRuleStruct);
00090 
00091   }
00092 
00093   // //////////////////////////////////////////////////////////////////////
00094   void FareRuleGenerator::
00095   createPOSChannel (stdair::DatePeriod& iDatePeriod,
00096                     const FareRuleStruct& iFareRuleStruct) {
00097 
00098     // Create the point-of-sale-channel primary key.
00099     const stdair::CityCode_T& lPosition = iFareRuleStruct.getPOS ();
00100     const stdair::ChannelLabel_T& lChannel =
00101         iFareRuleStruct.getChannel ();
00102     const stdair::PosChannelKey lFarePosChannelKey (lPosition, lChannel);
00103 
00104     // Check that the point_of_sale-channel object is not already existing.
00105     // If a point_of_sale-channel object with the same key has not already
00106     // been created, create it and link it to the date-period object.     
00107     stdair::PosChannel* lFarePosChannel_ptr = stdair::BomManager::
00108       getObjectPtr<stdair::PosChannel> (iDatePeriod,
00109                                         lFarePosChannelKey.toString());
00110     if (lFarePosChannel_ptr == NULL) {
00111       lFarePosChannel_ptr = &stdair::FacBom<stdair::PosChannel>::instance().
00112         create (lFarePosChannelKey);
00113       stdair::FacBomManager::addToListAndMap (iDatePeriod,
00114                                               *lFarePosChannel_ptr);
00115       stdair::FacBomManager::linkWithParent (iDatePeriod,
00116                                              *lFarePosChannel_ptr);
00117     }
00118     // Sanity check.
00119     assert (lFarePosChannel_ptr != NULL);
00120 
00121     stdair::PosChannel& lPosChannel = *lFarePosChannel_ptr;
00122     // Generate the time-period object corresponding to the given
00123     // fareRule.
00124     createTimeRange (lPosChannel, iFareRuleStruct);
00125 
00126   }
00127 
00128 
00129   // //////////////////////////////////////////////////////////////////////
00130   void FareRuleGenerator::
00131   createTimeRange (stdair::PosChannel& iPosChannel,
00132                    const FareRuleStruct& iFareRuleStruct) {
00133     
00134     // Create the fare time-period primary key.
00135     const stdair::Time_T& lTimeRangeStart =
00136       iFareRuleStruct.getTimeRangeStart ();
00137     const stdair::Time_T& lTimeRangeEnd =
00138       iFareRuleStruct.getTimeRangeEnd ();
00139     const stdair::TimePeriodKey lFareTimePeriodKey (lTimeRangeStart,
00140                                                     lTimeRangeEnd);
00141 
00142     // Check that the time-period object is not already existing.
00143     // If a time-period object with the same key has not already been
00144     // created, create it and link it to the point_of_sale-channel object.       
00145     stdair::TimePeriod* lFareTimePeriod_ptr = stdair::BomManager::
00146       getObjectPtr<stdair::TimePeriod> (iPosChannel,
00147                                         lFareTimePeriodKey.toString());
00148     if (lFareTimePeriod_ptr == NULL) {
00149       lFareTimePeriod_ptr = &stdair::FacBom<stdair::TimePeriod>::instance().
00150         create (lFareTimePeriodKey);
00151       stdair::FacBomManager::addToListAndMap (iPosChannel,
00152                                               *lFareTimePeriod_ptr);
00153       stdair::FacBomManager::linkWithParent (iPosChannel,
00154                                              *lFareTimePeriod_ptr);
00155     }
00156     // Sanity check.
00157     assert (lFareTimePeriod_ptr != NULL);
00158 
00159     stdair::TimePeriod& lTimeRange = *lFareTimePeriod_ptr;
00160     // Generate the fare-features object corresponding to the given
00161     // fareRule.
00162     createFareFeatures (lTimeRange, iFareRuleStruct);
00163 
00164   }
00165 
00166   // //////////////////////////////////////////////////////////////////////
00167   void FareRuleGenerator::
00168   createFareFeatures (stdair::TimePeriod& iTimePeriod,
00169                       const FareRuleStruct& iFareRuleStruct) {
00170 
00171     // Create the fare-features primary key.
00172     const stdair::TripType_T& lTripType =
00173       iFareRuleStruct.getTripType ();
00174     const stdair::DayDuration_T& lAdvancePurchase =
00175       iFareRuleStruct.getAdvancePurchase ();
00176     const stdair::SaturdayStay_T& lSaturdayStay =
00177       iFareRuleStruct.getSaturdayStay ();
00178     const stdair::ChangeFees_T& lChangeFees =
00179       iFareRuleStruct.getChangeFees ();
00180     const stdair::NonRefundable_T& lNonRefundable =
00181       iFareRuleStruct.getNonRefundable ();
00182     const stdair::DayDuration_T& lMinimumStay =
00183       iFareRuleStruct.getMinimumStay ();
00184     const stdair::FareFeaturesKey
00185       lFareFeaturesKey (lTripType, lAdvancePurchase, lSaturdayStay,
00186                         lChangeFees, lNonRefundable, lMinimumStay);
00187 
00188     // Check that the fare features object is not already existing.
00189     // If a fare features object with the same key has not already been
00190     // created, create it and link it to the time-period object.        
00191     stdair::FareFeatures* lFareFeatures_ptr = stdair::BomManager::
00192       getObjectPtr<stdair::FareFeatures> (iTimePeriod,
00193                                           lFareFeaturesKey.toString());
00194     if (lFareFeatures_ptr == NULL) {
00195       lFareFeatures_ptr = &stdair::FacBom<stdair::FareFeatures>::instance().
00196         create (lFareFeaturesKey);
00197       assert(lFareFeatures_ptr != NULL); 
00198       stdair::FacBomManager::addToListAndMap (iTimePeriod,
00199                                               *lFareFeatures_ptr);
00200       stdair::FacBomManager::linkWithParent (iTimePeriod,
00201                                              *lFareFeatures_ptr);  
00202     }
00203     // Sanity check.
00204     assert(lFareFeatures_ptr != NULL);
00205     
00206     stdair::FareFeatures& lFareFeatures = *lFareFeatures_ptr;
00207     // Generate the airline-class list object corresponding to the
00208     // given fareRule
00209     createAirlineClassList (lFareFeatures, iFareRuleStruct);
00210 
00211   }
00212 
00213   // //////////////////////////////////////////////////////////////////////
00214   void FareRuleGenerator::
00215   createAirlineClassList (stdair::FareFeatures& iFareFeatures,
00216                           const FareRuleStruct& iFareRuleStruct) {
00217 
00218     // Create the AirlineClassList primary key.
00219     const unsigned int lAirlineListSize =
00220       iFareRuleStruct.getAirlineListSize();
00221     const unsigned int lClassCodeListSize =
00222       iFareRuleStruct.getClassCodeListSize();
00223     assert (lAirlineListSize == lClassCodeListSize);
00224     const stdair::AirlineClassListKey
00225       lAirlineClassListKey (iFareRuleStruct.getAirlineList(),
00226                             iFareRuleStruct.getClassCodeList());
00227     const stdair::Fare_T& lFare = iFareRuleStruct.getFare ();
00228     
00229     // Create the airline class list object and link it to the fare features
00230     // object.        
00231     stdair::AirlineClassList* lAirlineClassList_ptr =
00232       &stdair::FacBom<stdair::AirlineClassList>::instance().
00233       create (lAirlineClassListKey);
00234     lAirlineClassList_ptr->setFare(lFare);
00235     stdair::FacBomManager::addToListAndMap (iFareFeatures,
00236                                             *lAirlineClassList_ptr); 
00237     stdair::FacBomManager::linkWithParent(iFareFeatures,
00238                                           *lAirlineClassList_ptr);
00239   }
00240         
00241 }
00242