StdAir Logo  1.00.0
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BookingRequestStruct.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // Boost
8 #include <boost/date_time/gregorian/formatters.hpp>
9 #include <boost/date_time/posix_time/posix_time.hpp>
10 // StdAir
14 
15 namespace stdair {
16 
17  // //////////////////////////////////////////////////////////////////////
18  BookingRequestStruct::BookingRequestStruct()
19  : _origin (DEFAULT_ORIGIN), _destination (DEFAULT_DESTINATION),
20  _pos (DEFAULT_POS),
21  _preferredDepartureDate (DEFAULT_PREFERRED_DEPARTURE_DATE),
22  _preferredDepartureTime (DEFAULT_PREFERRED_DEPARTURE_TIME),
23  _requestDateTime (DEFAULT_REQUEST_DATE_TIME),
24  _preferredCabin (DEFAULT_PREFERRED_CABIN),
25  _partySize (DEFAULT_PARTY_SIZE),
26  _channel (DEFAULT_CHANNEL),
27  _tripType (TRIP_TYPE_ONE_WAY),
28  _stayDuration (DEFAULT_STAY_DURATION),
29  _frequentFlyerType (DEFAULT_FF_TIER),
30  _wtp (DEFAULT_WTP),
31  _valueOfTime (DEFAULT_VALUE_OF_TIME),
32  _changeFees (false), _changeFeeDisutility (0.0),
33  _nonRefundable (false), _nonRefundableDisutility (0.0) {
34  assert (false);
35  }
36 
37  // //////////////////////////////////////////////////////////////////////
38  BookingRequestStruct::
39  BookingRequestStruct (const BookingRequestStruct& iBookingRequest)
40  : _generatorKey (iBookingRequest._generatorKey),
41  _origin (iBookingRequest._origin),
42  _destination (iBookingRequest._destination),
43  _pos (iBookingRequest._pos),
44  _preferredDepartureDate (iBookingRequest._preferredDepartureDate),
45  _preferredDepartureTime (iBookingRequest._preferredDepartureTime),
46  _requestDateTime (iBookingRequest._requestDateTime),
47  _preferredCabin (iBookingRequest._preferredCabin),
48  _partySize (iBookingRequest._partySize),
49  _channel (iBookingRequest._channel),
50  _tripType (iBookingRequest._tripType),
51  _stayDuration (iBookingRequest._stayDuration),
52  _frequentFlyerType (iBookingRequest._frequentFlyerType),
53  _wtp (iBookingRequest._wtp),
54  _valueOfTime (iBookingRequest._valueOfTime),
55  _changeFees (iBookingRequest._changeFees),
56  _changeFeeDisutility (iBookingRequest._changeFeeDisutility),
57  _nonRefundable (iBookingRequest._nonRefundable),
58  _nonRefundableDisutility (iBookingRequest._nonRefundableDisutility) {
59  }
60 
61  // //////////////////////////////////////////////////////////////////////
62  BookingRequestStruct::
63  BookingRequestStruct (const DemandGeneratorKey_T& iGeneratorKey,
64  const AirportCode_T& iOrigin,
65  const AirportCode_T& iDestination,
66  const CityCode_T& iPOS,
67  const Date_T& iDepartureDate,
68  const DateTime_T& iRequestDateTime,
69  const CabinCode_T& iPreferredCabin,
70  const NbOfSeats_T& iPartySize,
71  const ChannelLabel_T& iChannel,
72  const TripType_T& iTripType,
73  const DayDuration_T& iStayDuration,
74  const FrequentFlyer_T& iFrequentFlyerType,
75  const Duration_T& iPreferredDepartureTime,
76  const WTP_T& iWTP,
77  const PriceValue_T& iValueOfTime,
78  const ChangeFees_T& iChangeFees,
79  const Disutility_T& iChangeFeeDisutility,
80  const NonRefundable_T& iNonRefundable,
81  const Disutility_T& iNonRefundableDisutility)
82  : _generatorKey (iGeneratorKey), _origin (iOrigin),
83  _destination (iDestination), _pos (iPOS),
84  _preferredDepartureDate (iDepartureDate),
85  _preferredDepartureTime (iPreferredDepartureTime),
86  _requestDateTime (iRequestDateTime),
87  _preferredCabin (iPreferredCabin), _partySize (iPartySize),
88  _channel (iChannel), _tripType (iTripType),
89  _stayDuration (iStayDuration), _frequentFlyerType (iFrequentFlyerType),
90  _wtp (iWTP), _valueOfTime (iValueOfTime),
91  _changeFees (iChangeFees), _changeFeeDisutility (iChangeFeeDisutility),
92  _nonRefundable (iNonRefundable),
93  _nonRefundableDisutility (iNonRefundableDisutility) {
94  }
95 
96  // //////////////////////////////////////////////////////////////////////
97  BookingRequestStruct::
98  BookingRequestStruct (const AirportCode_T& iOrigin,
99  const AirportCode_T& iDestination,
100  const CityCode_T& iPOS,
101  const Date_T& iDepartureDate,
102  const DateTime_T& iRequestDateTime,
103  const CabinCode_T& iPreferredCabin,
104  const NbOfSeats_T& iPartySize,
105  const ChannelLabel_T& iChannel,
106  const TripType_T& iTripType,
107  const DayDuration_T& iStayDuration,
108  const FrequentFlyer_T& iFrequentFlyerType,
109  const Duration_T& iPreferredDepartureTime,
110  const WTP_T& iWTP,
111  const PriceValue_T& iValueOfTime,
112  const ChangeFees_T& iChangeFees,
113  const Disutility_T& iChangeFeeDisutility,
114  const NonRefundable_T& iNonRefundable,
115  const Disutility_T& iNonRefundableDisutility)
116  : _generatorKey (""), _origin (iOrigin),
117  _destination (iDestination), _pos (iPOS),
118  _preferredDepartureDate (iDepartureDate),
119  _preferredDepartureTime (iPreferredDepartureTime),
120  _requestDateTime (iRequestDateTime),
121  _preferredCabin (iPreferredCabin), _partySize (iPartySize),
122  _channel (iChannel), _tripType (iTripType),
123  _stayDuration (iStayDuration), _frequentFlyerType (iFrequentFlyerType),
124  _wtp (iWTP), _valueOfTime (iValueOfTime),
125  _changeFees (iChangeFees), _changeFeeDisutility (iChangeFeeDisutility),
126  _nonRefundable (iNonRefundable),
127  _nonRefundableDisutility (iNonRefundableDisutility) {
128  }
129 
130  // //////////////////////////////////////////////////////////////////////
132  }
133 
134  // //////////////////////////////////////////////////////////////////////
135  void BookingRequestStruct::toStream (std::ostream& ioOut) const {
136  ioOut << describe();
137  }
138 
139  // //////////////////////////////////////////////////////////////////////
140  void BookingRequestStruct::fromStream (std::istream& ioIn) {
141  }
142 
143  // //////////////////////////////////////////////////////////////////////
144  const std::string BookingRequestStruct::describe() const {
145  std::ostringstream oStr;
146  oStr << "At " << _requestDateTime
147  << ", for (" << _pos << ", " << _channel << ")"
148  << " " << _origin << "-" << _destination << " (" << _tripType << ")"
149  << " " << _preferredDepartureDate << " (" << _stayDuration << " days)"
150  << " " << _preferredDepartureTime
151  << " " << _preferredCabin << " " << _partySize
152  << " " << _frequentFlyerType << " " << _wtp << " " << _valueOfTime
153  << " " << _changeFees << " " << _changeFeeDisutility << " "
154  << _nonRefundable << " " << _nonRefundableDisutility;
155  return oStr.str();
156  }
157 
158  // ////////////////////////////////////////////////////////////////////
159  void intDisplay (std::ostream& oStream, const int& iInt) {
160  const int dInt = iInt - static_cast<int> (iInt / 100) * 100;
161  if (dInt < 10) {
162  oStream << "0" << dInt;
163  } else {
164  oStream << dInt;
165  }
166  }
167 
168  // //////////////////////////////////////////////////////////////////////
169  const std::string BookingRequestStruct::display() const {
170  std::ostringstream oStr;
171 
172  // Request date and time
173  const Date_T& lRequestDate = _requestDateTime.date();
174  oStr << boost::gregorian::to_iso_extended_string (lRequestDate);
175 
176  const Duration_T& lRequestTime = _requestDateTime.time_of_day();
177  oStr << ", " << boost::posix_time::to_simple_string (lRequestTime);
178 
179  // POS
180  oStr << ", " << _pos;
181 
182  // Channel
183  oStr << ", " << _channel;
184 
185  // Origin
186  oStr << ", " << _origin;
187 
188  // Destination
189  oStr << ", " << _destination;
190 
191  // Preferred departure date
192  oStr << ", "
193  << boost::gregorian::to_iso_extended_string (_preferredDepartureDate);
194 
195  // Preferred departure time
196  oStr << ", "
197  << boost::posix_time::to_simple_string (_preferredDepartureTime);
198 
199  // MIN & MAX preferred departure time (hardcode)
200  oStr << ", " << "00:00-23:59";
201 
202  // Preferred arrival date (hardcode to the preferred departure date)
203  oStr << ", "
204  << boost::gregorian::to_iso_extended_string (_preferredDepartureDate);
205 
206  // Preferred arrival time (hard-coded to 23:55)
207  oStr << ", " << "23:55";
208 
209  // Preferred cabin
210  oStr << ", " << _preferredCabin;
211 
212  // Trip type
213  oStr << ", " << _tripType;
214 
215  // Duration of stay
216  oStr << ", ";
217  if (_tripType == TRIP_TYPE_ONE_WAY) {
218  oStr << "0";
219  } else {
220  oStr << _stayDuration;
221  }
222 
223  // Frequent flyer tier
224  oStr << ", " << _frequentFlyerType;
225 
226  // Willingness-to-pay
227  oStr << ", " << _wtp;
228 
229  // Disutility per stop (hardcode to 100, expressed as a monetary
230  // unit per hour)
231  oStr << ", " << "100";
232 
233  // Value of time
234  oStr << ", " << _valueOfTime;
235 
236  // Change fees
237  oStr << ", " << _changeFees;
238 
239  // Change fee disutility
240  oStr << ", " << _changeFeeDisutility;
241 
242  // Non refundable
243  oStr << ", " << _nonRefundable;
244 
245  // Non refundable disutility
246  oStr << ", " << _nonRefundableDisutility;
247 
248  return oStr.str();
249  }
250 
251 }