StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FareFeatures.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // StdAir
12 
13 namespace stdair {
14 
15  // ////////////////////////////////////////////////////////////////////
16  FareFeatures::FareFeatures()
17  : _key (TRIP_TYPE_ONE_WAY,
23  _parent (NULL) {
24  // That constructor is used by the serialisation process
25  }
26 
27  // ////////////////////////////////////////////////////////////////////
28  FareFeatures::FareFeatures (const FareFeatures& iFeatures)
29  : _key (iFeatures.getKey()), _parent (NULL) {
30  assert (false);
31  }
32 
33  // ////////////////////////////////////////////////////////////////////
34  FareFeatures::FareFeatures (const Key_T& iKey)
35  : _key (iKey), _parent (NULL) {
36  }
37 
38  // ////////////////////////////////////////////////////////////////////
40  }
41 
42  // ////////////////////////////////////////////////////////////////////
43  std::string FareFeatures::toString() const {
44  std::ostringstream oStr;
45  oStr << describeKey();
46  return oStr.str();
47  }
48 
49  // ////////////////////////////////////////////////////////////////////
50  bool FareFeatures::
51  isTripTypeValid (const TripType_T& iBookingRequestTripType) const {
52  bool oIsTripTypeValidFlag = true;
53 
54  const TripType_T& lFareTripType = getTripType();
55  // Check whether the fare trip type is the same as the booking request
56  // trip type
57  if (iBookingRequestTripType == lFareTripType) {
58  // One way case
59  return oIsTripTypeValidFlag;
60  }
61 
62  if (iBookingRequestTripType == TRIP_TYPE_INBOUND
63  || iBookingRequestTripType == TRIP_TYPE_OUTBOUND) {
64  // Round trip case
65  if (lFareTripType == TRIP_TYPE_ROUND_TRIP) {
66  return oIsTripTypeValidFlag;
67  }
68  }
69 
70  oIsTripTypeValidFlag = false;
71  return oIsTripTypeValidFlag;
72  }
73 
74  // ////////////////////////////////////////////////////////////////////
75  bool FareFeatures::
76  isStayDurationValid (const DayDuration_T& iStayDuration) const {
77 
78  // Check if the stay duration is lower or equal to the minimum one.
79  const DayDuration_T& lMinimumDayDuration = getMinimumStay();
80  if (lMinimumDayDuration > iStayDuration) {
81  return false;
82  }
83 
84  return true;
85  }
86 
87  // ////////////////////////////////////////////////////////////////////
88  bool FareFeatures::
89  isAdvancePurchaseValid (const DateTime_T& iBookingRequestDateTime,
90  const DateTime_T& iFlightDateTime) const {
91  bool oIsAdvancePurchaseValidFlag = true;
92 
93  // Check whether the departure date is within the date range.
94  const DayDuration_T& lAdvancedPurchase = getAdvancePurchase();
95  const DateOffset_T lMinimumAdvancedPurchase (lAdvancedPurchase);
96  const DateTime_T lCriticalDate = iFlightDateTime - lMinimumAdvancedPurchase;
97 
98  if (lCriticalDate < iBookingRequestDateTime) {
99  oIsAdvancePurchaseValidFlag = false;
100  return oIsAdvancePurchaseValidFlag;
101  }
102 
103  return true;
104  }
105 
106 }
107