StdAir Logo  0.45.0
C++ Standard Airline IT Object Library
FareFeatures.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // StdAir
00008 #include <stdair/basic/BasConst_DefaultObject.hpp>
00009 #include <stdair/basic/BasConst_Request.hpp>
00010 #include <stdair/service/Logger.hpp>
00011 #include <stdair/bom/FareFeatures.hpp>
00012 
00013 namespace stdair {
00014 
00015   // ////////////////////////////////////////////////////////////////////
00016   FareFeatures::FareFeatures()
00017     : _key (TRIP_TYPE_ONE_WAY,
00018             NO_ADVANCE_PURCHASE,
00019             SATURDAY_STAY,
00020             CHANGE_FEES,
00021             NON_REFUNDABLE,
00022             NO_STAY_DURATION),
00023       _parent (NULL)  {
00024     // That constructor is used by the serialisation process
00025   }
00026 
00027   // ////////////////////////////////////////////////////////////////////
00028   FareFeatures::FareFeatures (const FareFeatures& iFeatures)
00029     : _key (iFeatures.getKey()), _parent (NULL)  {
00030     assert (false);
00031   }
00032 
00033   // ////////////////////////////////////////////////////////////////////
00034   FareFeatures::FareFeatures (const Key_T& iKey)
00035     : _key (iKey), _parent (NULL)  {
00036   }
00037 
00038   // ////////////////////////////////////////////////////////////////////
00039   FareFeatures::~FareFeatures () {
00040   }
00041   
00042   // ////////////////////////////////////////////////////////////////////
00043   std::string FareFeatures::toString() const {
00044     std::ostringstream oStr;
00045     oStr << describeKey();
00046     return oStr.str();
00047   }
00048 
00049   // ////////////////////////////////////////////////////////////////////
00050   bool FareFeatures::
00051   isTripTypeValid (const TripType_T& iBookingRequestTripType) const {
00052     bool oIsTripTypeValidFlag = true;
00053 
00054     const TripType_T& lFareTripType = getTripType();
00055     // Check whether the fare trip type is the same as the booking request
00056     // trip type
00057     if (iBookingRequestTripType == lFareTripType) {
00058       // One way case
00059       return oIsTripTypeValidFlag;
00060     }
00061 
00062     if (iBookingRequestTripType == TRIP_TYPE_INBOUND
00063         || iBookingRequestTripType == TRIP_TYPE_OUTBOUND) {
00064       // Round trip case
00065       if (lFareTripType == TRIP_TYPE_ROUND_TRIP) {
00066         return oIsTripTypeValidFlag;
00067       }
00068     }
00069 
00070     oIsTripTypeValidFlag = false;
00071     return oIsTripTypeValidFlag;
00072   }
00073 
00074   // ////////////////////////////////////////////////////////////////////
00075   bool FareFeatures::
00076   isStayDurationValid (const DayDuration_T& iStayDuration) const {
00077 
00078     // Check if the stay duration is lower or equal to the minimum one.
00079     const DayDuration_T& lMinimumDayDuration = getMinimumStay();
00080     if (lMinimumDayDuration > iStayDuration) {
00081       return false;
00082     }
00083 
00084     return true;
00085   }
00086 
00087   // ////////////////////////////////////////////////////////////////////
00088   bool FareFeatures::
00089   isAdvancePurchaseValid (const DateTime_T& iBookingRequestDateTime,
00090                           const DateTime_T& iFlightDateTime) const {
00091     bool oIsAdvancePurchaseValidFlag = true;
00092 
00093     // Check whether the departure date is within the date range.
00094     const DayDuration_T& lAdvancedPurchase = getAdvancePurchase();
00095     const DateOffset_T lMinimumAdvancedPurchase (lAdvancedPurchase);
00096     const DateTime_T lCriticalDate = iFlightDateTime - lMinimumAdvancedPurchase;
00097       
00098     if (lCriticalDate < iBookingRequestDateTime) {
00099       oIsAdvancePurchaseValidFlag = false;
00100       return oIsAdvancePurchaseValidFlag;
00101     }
00102 
00103     return true;
00104   }
00105   
00106 }
00107