StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  assert (false);
33  }
34 
35  // //////////////////////////////////////////////////////////////////////
36  BookingRequestStruct::
37  BookingRequestStruct (const BookingRequestStruct& iBookingRequest)
38  : _generatorKey (iBookingRequest._generatorKey),
39  _origin (iBookingRequest._origin),
40  _destination (iBookingRequest._destination),
41  _pos (iBookingRequest._pos),
42  _preferredDepartureDate (iBookingRequest._preferredDepartureDate),
43  _preferredDepartureTime (iBookingRequest._preferredDepartureTime),
44  _requestDateTime (iBookingRequest._requestDateTime),
45  _preferredCabin (iBookingRequest._preferredCabin),
46  _partySize (iBookingRequest._partySize),
47  _channel (iBookingRequest._channel),
48  _tripType (iBookingRequest._tripType),
49  _stayDuration (iBookingRequest._stayDuration),
50  _frequentFlyerType (iBookingRequest._frequentFlyerType),
51  _wtp (iBookingRequest._wtp),
52  _valueOfTime (iBookingRequest._valueOfTime) {
53  }
54 
55  // //////////////////////////////////////////////////////////////////////
56  BookingRequestStruct::
57  BookingRequestStruct (const DemandGeneratorKey_T& iGeneratorKey,
58  const AirportCode_T& iOrigin,
59  const AirportCode_T& iDestination,
60  const CityCode_T& iPOS,
61  const Date_T& iDepartureDate,
62  const DateTime_T& iRequestDateTime,
63  const CabinCode_T& iPreferredCabin,
64  const NbOfSeats_T& iPartySize,
65  const ChannelLabel_T& iChannel,
66  const TripType_T& iTripType,
67  const DayDuration_T& iStayDuration,
68  const FrequentFlyer_T& iFrequentFlyerType,
69  const Duration_T& iPreferredDepartureTime,
70  const WTP_T& iWTP,
71  const PriceValue_T& iValueOfTime)
72  : _generatorKey (iGeneratorKey), _origin (iOrigin),
73  _destination (iDestination), _pos (iPOS),
74  _preferredDepartureDate (iDepartureDate),
75  _preferredDepartureTime (iPreferredDepartureTime),
76  _requestDateTime (iRequestDateTime),
77  _preferredCabin (iPreferredCabin), _partySize (iPartySize),
78  _channel (iChannel), _tripType (iTripType),
79  _stayDuration (iStayDuration), _frequentFlyerType (iFrequentFlyerType),
80  _wtp (iWTP), _valueOfTime (iValueOfTime) {
81  }
82 
83  // //////////////////////////////////////////////////////////////////////
84  BookingRequestStruct::
85  BookingRequestStruct (const AirportCode_T& iOrigin,
86  const AirportCode_T& iDestination,
87  const CityCode_T& iPOS,
88  const Date_T& iDepartureDate,
89  const DateTime_T& iRequestDateTime,
90  const CabinCode_T& iPreferredCabin,
91  const NbOfSeats_T& iPartySize,
92  const ChannelLabel_T& iChannel,
93  const TripType_T& iTripType,
94  const DayDuration_T& iStayDuration,
95  const FrequentFlyer_T& iFrequentFlyerType,
96  const Duration_T& iPreferredDepartureTime,
97  const WTP_T& iWTP,
98  const PriceValue_T& iValueOfTime)
99  : _generatorKey (""), _origin (iOrigin),
100  _destination (iDestination), _pos (iPOS),
101  _preferredDepartureDate (iDepartureDate),
102  _preferredDepartureTime (iPreferredDepartureTime),
103  _requestDateTime (iRequestDateTime),
104  _preferredCabin (iPreferredCabin), _partySize (iPartySize),
105  _channel (iChannel), _tripType (iTripType),
106  _stayDuration (iStayDuration), _frequentFlyerType (iFrequentFlyerType),
107  _wtp (iWTP), _valueOfTime (iValueOfTime) {
108  }
109 
110  // //////////////////////////////////////////////////////////////////////
112  }
113 
114  // //////////////////////////////////////////////////////////////////////
115  void BookingRequestStruct::toStream (std::ostream& ioOut) const {
116  ioOut << describe();
117  }
118 
119  // //////////////////////////////////////////////////////////////////////
120  void BookingRequestStruct::fromStream (std::istream& ioIn) {
121  }
122 
123  // //////////////////////////////////////////////////////////////////////
124  const std::string BookingRequestStruct::describe() const {
125  std::ostringstream oStr;
126  oStr << "At " << _requestDateTime
127  << ", for (" << _pos << ", " << _channel << ")"
128  << " " << _origin << "-" << _destination << " (" << _tripType << ")"
129  << " " << _preferredDepartureDate << " (" << _stayDuration << " days)"
130  << " " << _preferredDepartureTime
131  << " " << _preferredCabin << " " << _partySize
132  << " " << _frequentFlyerType << " " << _wtp << " " << _valueOfTime;
133  return oStr.str();
134  }
135 
136  // ////////////////////////////////////////////////////////////////////
137  void intDisplay (std::ostream& oStream, const int& iInt) {
138  const int dInt = iInt - static_cast<int> (iInt / 100) * 100;
139  if (dInt < 10) {
140  oStream << "0" << dInt;
141  } else {
142  oStream << dInt;
143  }
144  }
145 
146  // //////////////////////////////////////////////////////////////////////
147  const std::string BookingRequestStruct::display() const {
148  std::ostringstream oStr;
149 
150  // Request date and time
151  const Date_T& lRequestDate = _requestDateTime.date();
152  oStr << boost::gregorian::to_iso_extended_string (lRequestDate);
153 
154  const Duration_T& lRequestTime = _requestDateTime.time_of_day();
155  oStr << ", " << boost::posix_time::to_simple_string (lRequestTime);
156 
157  // POS
158  oStr << ", " << _pos;
159 
160  // Channel
161  oStr << ", " << _channel;
162 
163  // Origin
164  oStr << ", " << _origin;
165 
166  // Destination
167  oStr << ", " << _destination;
168 
169  // Preferred departure date
170  oStr << ", "
171  << boost::gregorian::to_iso_extended_string (_preferredDepartureDate);
172 
173  // Preferred departure time
174  oStr << ", "
175  << boost::posix_time::to_simple_string (_preferredDepartureTime);
176 
177  // MIN & MAX preferred departure time (hardcode)
178  oStr << ", " << "00:00-23:59";
179 
180  // Preferred arrival date (hardcode to the preferred departure date)
181  oStr << ", "
182  << boost::gregorian::to_iso_extended_string (_preferredDepartureDate);
183 
184  // Preferred arrival time (hard-coded to 23:55)
185  oStr << ", " << "23:55";
186 
187  // Preferred cabin
188  oStr << ", " << _preferredCabin;
189 
190  // Trip type
191  oStr << ", " << _tripType;
192 
193  // Duration of stay
194  oStr << ", ";
195  if (_tripType == TRIP_TYPE_ONE_WAY) {
196  oStr << "0";
197  } else {
198  oStr << _stayDuration;
199  }
200 
201  // Frequent flyer tier
202  oStr << ", " << _frequentFlyerType;
203 
204  // Willingness-to-pay
205  oStr << ", " << _wtp;
206 
207  // Disutility per stop (hardcode to 100, expressed as a monetary
208  // unit per hour)
209  oStr << ", " << "100";
210 
211  // Value of time
212  oStr << ", " << _valueOfTime;
213 
214  return oStr.str();
215  }
216 
217 }