1.00.15
C++ Simulated Airline Inventory Management System Library
Toggle main menu visibility
Loading...
Searching...
No Matches
FlightDateStruct.cpp
Go to the documentation of this file.
1
// //////////////////////////////////////////////////////////////////////
2
// Import section
3
// //////////////////////////////////////////////////////////////////////
4
// STL
5
#include <cassert>
6
#include <sstream>
7
// StdAir
8
#include <stdair/basic/BasConst_General.hpp>
9
#include <stdair/service/Logger.hpp>
10
// AIRINV
11
#include <
airinv/AIRINV_Types.hpp
>
12
#include <
airinv/bom/FlightDateStruct.hpp
>
13
14
namespace
AIRINV
{
15
16
// //////////////////////////////////////////////////////////////////////
17
FlightDateStruct::FlightDateStruct
()
18
:
_flightDate
(
stdair
::DEFAULT_DATE),
19
_flightTypeCode
(
FlightTypeCode
::DOMESTIC),
20
_flightVisibilityCode
(
FlightVisibilityCode
::NORMAL),
21
_itSeconds
(0),
_legAlreadyDefined
(false) {
22
}
23
24
// //////////////////////////////////////////////////////////////////////
25
stdair::Date_T
FlightDateStruct::getDate
()
const
{
26
return
stdair::Date_T (
_itYear
+ 2000,
_itMonth
,
_itDay
);
27
}
28
29
// //////////////////////////////////////////////////////////////////////
30
stdair::Duration_T
FlightDateStruct::getTime
()
const
{
31
return
boost::posix_time::hours (
_itHours
)
32
+ boost::posix_time::minutes (
_itMinutes
)
33
+ boost::posix_time::seconds (
_itSeconds
);
34
}
35
36
// //////////////////////////////////////////////////////////////////////
37
const
std::string
FlightDateStruct::describe
()
const
{
38
std::ostringstream ostr;
39
ostr <<
_airlineCode
<<
_flightNumber
<<
", "
<<
_flightDate
40
<<
" ("
<<
_flightTypeCode
;
41
if
(
_flightVisibilityCode
.getCode() !=
FlightVisibilityCode::NORMAL
) {
42
ostr <<
"/"
<<
_flightVisibilityCode
;
43
}
44
ostr <<
")"
<< std::endl;
45
46
for
(LegStructList_T::const_iterator itLeg =
_legList
.begin();
47
itLeg !=
_legList
.end(); ++itLeg) {
48
const
LegStruct
& lLeg = *itLeg;
49
ostr << lLeg.
describe
();
50
}
51
52
for
(SegmentStructList_T::const_iterator itSegment =
_segmentList
.begin();
53
itSegment !=
_segmentList
.end(); ++itSegment) {
54
const
SegmentStruct
& lSegment = *itSegment;
55
ostr << lSegment.
describe
();
56
}
57
58
//ostr << "[Debug] - Staging Leg: ";
59
//ostr << _itLeg.describe();
60
//ostr << "[Debug] - Staging Cabin: ";
61
//ostr << _itCabin.describe();
62
63
return
ostr.str();
64
}
65
66
// //////////////////////////////////////////////////////////////////////
67
void
FlightDateStruct::addAirport
(
const
stdair::AirportCode_T& iAirport) {
68
AirportList_T::const_iterator itAirport =
_airportList
.find (iAirport);
69
if
(itAirport ==
_airportList
.end()) {
70
// Add the airport code to the airport set
71
const
bool
insertSuccessful =
_airportList
.insert (iAirport).second;
72
73
if
(insertSuccessful ==
false
) {
74
// TODO: throw an exception
75
}
76
77
// Add the airport code to the airport vector
78
_airportOrderedList
.push_back (iAirport);
79
}
80
}
81
82
// //////////////////////////////////////////////////////////////////////
83
void
FlightDateStruct::buildSegments
() {
84
// The list of airports encompasses all the airports on which
85
// the flight takes off or lands. Moreover, that list is
86
// time-ordered: the first airport is the initial departure of
87
// the flight, and the last airport is the eventual point of
88
// rest of the flight.
89
// Be l the size of the ordered list of airports.
90
// We want to generate all the segment combinations from the legs
91
// and, hence, from all the possible (time-ordered) airport pairs.
92
// Thus, we both iterator on i=0...l-1 and j=i+1...l
93
assert (
_airportOrderedList
.size() >= 2);
94
95
_segmentList
.clear();
96
for
(AirportOrderedList_T::const_iterator itAirport_i =
97
_airportOrderedList
.begin();
98
itAirport_i !=
_airportOrderedList
.end()-1; ++itAirport_i) {
99
for
(AirportOrderedList_T::const_iterator itAirport_j = itAirport_i + 1;
100
itAirport_j !=
_airportOrderedList
.end(); ++itAirport_j) {
101
SegmentStruct
lSegmentStruct;
102
lSegmentStruct.
_boardingPoint
= *itAirport_i;
103
lSegmentStruct.
_offPoint
= *itAirport_j;
104
105
_segmentList
.push_back (lSegmentStruct);
106
}
107
}
108
109
// Clear the lists of airports, so that it is ready for the next flight
110
_airportList
.clear();
111
_airportOrderedList
.clear();
112
}
113
114
// //////////////////////////////////////////////////////////////////////
115
void
FlightDateStruct::
116
addSegmentCabin
(
const
SegmentStruct
& iSegment,
117
const
SegmentCabinStruct
& iCabin) {
118
// Retrieve the Segment structure corresponding to the (boarding, off) point
119
// pair.
120
SegmentStructList_T::iterator itSegment =
_segmentList
.begin();
121
for
( ; itSegment !=
_segmentList
.end(); ++itSegment) {
122
const
SegmentStruct
& lSegment = *itSegment;
123
124
const
stdair::AirportCode_T& lBoardingPoint = iSegment.
_boardingPoint
;
125
const
stdair::AirportCode_T& lOffPoint = iSegment.
_offPoint
;
126
if
(lSegment.
_boardingPoint
== lBoardingPoint
127
&& lSegment.
_offPoint
== lOffPoint) {
128
break
;
129
}
130
}
131
132
// If the segment key (airport pair) given in the schedule input file
133
// does not correspond to the leg (boarding, off) points, throw an exception
134
// so that the user knows the schedule input file is corrupted.
135
if
(itSegment ==
_segmentList
.end()) {
136
STDAIR_LOG_ERROR (
"Within the inventory input file, there is a "
137
<<
"flight for which the airports of segments "
138
<<
"and those of the legs do not correspond."
);
139
throw
SegmentDateNotFoundException
(
"Within the inventory input file, "
140
"there is a flight for which the "
141
"airports of segments and those of "
142
"the legs do not correspond."
);
143
}
144
145
// Add the Cabin structure to the Segment Cabin structure.
146
assert (itSegment !=
_segmentList
.end());
147
SegmentStruct
& lSegment = *itSegment;
148
lSegment.
_cabinList
.push_back (iCabin);
149
}
150
151
// //////////////////////////////////////////////////////////////////////
152
void
FlightDateStruct::
153
addSegmentCabin
(
const
SegmentCabinStruct
& iCabin) {
154
// Iterate on all the Segment structures (as they get the same cabin
155
// definitions)
156
157
for
(SegmentStructList_T::iterator itSegment =
_segmentList
.begin();
158
itSegment !=
_segmentList
.end(); ++itSegment) {
159
SegmentStruct
& lSegment = *itSegment;
160
161
lSegment.
_cabinList
.push_back (iCabin);
162
}
163
}
164
165
// //////////////////////////////////////////////////////////////////////
166
void
FlightDateStruct::
167
addFareFamily
(
const
SegmentStruct
& iSegment,
168
const
SegmentCabinStruct
& iCabin,
169
const
FareFamilyStruct
& iFareFamily) {
170
// Retrieve the Segment structure corresponding to the (boarding, off) point
171
// pair.
172
SegmentStructList_T::iterator itSegment =
_segmentList
.begin();
173
for
( ; itSegment !=
_segmentList
.end(); ++itSegment) {
174
const
SegmentStruct
& lSegment = *itSegment;
175
176
const
stdair::AirportCode_T& lBoardingPoint = iSegment.
_boardingPoint
;
177
const
stdair::AirportCode_T& lOffPoint = iSegment.
_offPoint
;
178
if
(lSegment.
_boardingPoint
== lBoardingPoint
179
&& lSegment.
_offPoint
== lOffPoint) {
180
break
;
181
}
182
}
183
184
// If the segment key (airport pair) given in the schedule input file
185
// does not correspond to the leg (boarding, off) points, throw an exception
186
// so that the user knows the schedule input file is corrupted.
187
if
(itSegment ==
_segmentList
.end()) {
188
STDAIR_LOG_ERROR (
"Within the schedule input file, there is a flight "
189
<<
"for which the airports of segments and "
190
<<
"those of the legs do not correspond."
);
191
throw
SegmentDateNotFoundException
(
"Within the schedule input file, "
192
"there is a flight for which the "
193
"airports of segments and those of "
194
"the legs do not correspond."
);
195
}
196
197
// Add the Cabin structure to the Segment Cabin structure.
198
assert (itSegment !=
_segmentList
.end());
199
SegmentStruct
& lSegment = *itSegment;
200
201
// Retrieve the Segment cabin structure given the cabin code
202
SegmentCabinStructList_T::iterator itCabin = lSegment.
_cabinList
.begin();
203
for
( ; itCabin != lSegment.
_cabinList
.end(); ++itCabin) {
204
const
SegmentCabinStruct
& lCabin = *itCabin;
205
206
const
stdair::CabinCode_T& lCabinCode = lCabin.
_cabinCode
;
207
if
(iCabin.
_cabinCode
== lCabinCode) {
208
break
;
209
}
210
}
211
212
// If the segmentCabin key (cabin code) given in the schedule input file
213
// does not correspond to the stored cabin codes, throw an exception
214
// so that the user knows the schedule input file is corrupted.
215
if
(itCabin == lSegment.
_cabinList
.end()) {
216
STDAIR_LOG_ERROR (
"Within the schedule input file, there is a flight "
217
<<
"for which the cabin code does not exist."
);
218
throw
SegmentDateNotFoundException
(
"Within the schedule input file, "
219
"there is a flight for which the "
220
"cabin code does not exist."
);
221
}
222
223
// Add the Cabin structure to the Segment Cabin structure.
224
assert (itCabin != lSegment.
_cabinList
.end());
225
SegmentCabinStruct
& lCabin = *itCabin;
226
lCabin.
_fareFamilies
.push_back (iFareFamily);
227
}
228
229
// //////////////////////////////////////////////////////////////////////
230
void
FlightDateStruct::
231
addFareFamily
(
const
SegmentCabinStruct
& iCabin,
232
const
FareFamilyStruct
& iFareFamily) {
233
// Iterate on all the Segment structures (as they get the same cabin
234
// definitions)
235
236
for
(SegmentStructList_T::iterator itSegment =
_segmentList
.begin();
237
itSegment !=
_segmentList
.end(); ++itSegment) {
238
SegmentStruct
& lSegment = *itSegment;
239
240
// Retrieve the Segment cabin structure given the cabin code
241
SegmentCabinStructList_T::iterator itCabin = lSegment.
_cabinList
.begin();
242
for
( ; itCabin != lSegment.
_cabinList
.end(); ++itCabin) {
243
const
SegmentCabinStruct
& lCabin = *itCabin;
244
245
const
stdair::CabinCode_T& lCabinCode = lCabin.
_cabinCode
;
246
if
(iCabin.
_cabinCode
== lCabinCode) {
247
break
;
248
}
249
}
250
251
// If the segmentCabin key (cabin code) given in the schedule input file
252
// does not correspond to the stored cabin codes, throw an exception
253
// so that the user knows the schedule input file is corrupted.
254
if
(itCabin == lSegment.
_cabinList
.end()) {
255
STDAIR_LOG_ERROR (
"Within the schedule input file, there is a flight"
256
<<
" for which the cabin code does not exist."
);
257
throw
SegmentDateNotFoundException
(
"Within the schedule input file, "
258
"there is a flight for which the "
259
"cabin code does not exist."
);
260
}
261
262
// Add the Cabin structure to the Segment Cabin structure.
263
assert (itCabin != lSegment.
_cabinList
.end());
264
SegmentCabinStruct
& lCabin = *itCabin;
265
lCabin.
_fareFamilies
.push_back (iFareFamily);
266
}
267
}
268
269
}
AIRINV_Types.hpp
FlightDateStruct.hpp
AIRINV::SegmentDateNotFoundException
Definition
AIRINV_Types.hpp:94
AIRINV
Definition
AIRINV_Master_Service.hpp:38
stdair
Forward declarations.
Definition
AIRINV_Master_Service.hpp:25
AIRINV::FareFamilyStruct
Utility Structure for the parsing of fare family details.
Definition
FareFamilyStruct.hpp:26
AIRINV::FlightDateStruct::_airportList
AirportList_T _airportList
Definition
FlightDateStruct.hpp:102
AIRINV::FlightDateStruct::addFareFamily
void addFareFamily(const SegmentStruct &, const SegmentCabinStruct &, const FareFamilyStruct &)
Definition
FlightDateStruct.cpp:167
AIRINV::FlightDateStruct::addSegmentCabin
void addSegmentCabin(const SegmentStruct &, const SegmentCabinStruct &)
Definition
FlightDateStruct.cpp:116
AIRINV::FlightDateStruct::_itHours
long _itHours
Definition
FlightDateStruct.hpp:96
AIRINV::FlightDateStruct::addAirport
void addAirport(const stdair::AirportCode_T &)
Definition
FlightDateStruct.cpp:67
AIRINV::FlightDateStruct::_itMinutes
long _itMinutes
Definition
FlightDateStruct.hpp:97
AIRINV::FlightDateStruct::_segmentList
SegmentStructList_T _segmentList
Definition
FlightDateStruct.hpp:87
AIRINV::FlightDateStruct::describe
const std::string describe() const
Definition
FlightDateStruct.cpp:37
AIRINV::FlightDateStruct::_flightTypeCode
FlightTypeCode _flightTypeCode
Definition
FlightDateStruct.hpp:84
AIRINV::FlightDateStruct::_itYear
unsigned int _itYear
Definition
FlightDateStruct.hpp:90
AIRINV::FlightDateStruct::FlightDateStruct
FlightDateStruct()
Definition
FlightDateStruct.cpp:17
AIRINV::FlightDateStruct::_flightNumber
stdair::FlightNumber_T _flightNumber
Definition
FlightDateStruct.hpp:82
AIRINV::FlightDateStruct::_itMonth
unsigned int _itMonth
Definition
FlightDateStruct.hpp:91
AIRINV::FlightDateStruct::_legList
LegStructList_T _legList
Definition
FlightDateStruct.hpp:86
AIRINV::FlightDateStruct::_itDay
unsigned int _itDay
Definition
FlightDateStruct.hpp:92
AIRINV::FlightDateStruct::_airportOrderedList
AirportOrderedList_T _airportOrderedList
Definition
FlightDateStruct.hpp:103
AIRINV::FlightDateStruct::getTime
stdair::Duration_T getTime() const
Definition
FlightDateStruct.cpp:30
AIRINV::FlightDateStruct::buildSegments
void buildSegments()
Definition
FlightDateStruct.cpp:83
AIRINV::FlightDateStruct::_flightVisibilityCode
FlightVisibilityCode _flightVisibilityCode
Definition
FlightDateStruct.hpp:85
AIRINV::FlightDateStruct::getDate
stdair::Date_T getDate() const
Definition
FlightDateStruct.cpp:25
AIRINV::FlightDateStruct::_flightDate
stdair::Date_T _flightDate
Definition
FlightDateStruct.hpp:83
AIRINV::FlightDateStruct::_airlineCode
stdair::AirlineCode_T _airlineCode
Definition
FlightDateStruct.hpp:81
AIRINV::FlightDateStruct::_itSeconds
long _itSeconds
Definition
FlightDateStruct.hpp:98
AIRINV::FlightDateStruct::_legAlreadyDefined
bool _legAlreadyDefined
Definition
FlightDateStruct.hpp:107
AIRINV::FlightTypeCode
Definition
FlightTypeCode.hpp:15
AIRINV::FlightVisibilityCode
Definition
FlightVisibilityCode.hpp:15
AIRINV::FlightVisibilityCode::NORMAL
@ NORMAL
Definition
FlightVisibilityCode.hpp:18
AIRINV::LegStruct
Definition
LegStruct.hpp:24
AIRINV::LegStruct::describe
const std::string describe() const
Definition
LegStruct.cpp:21
AIRINV::SegmentCabinStruct
Utility Structure for the parsing of SegmentCabin details.
Definition
SegmentCabinStruct.hpp:26
AIRINV::SegmentCabinStruct::_cabinCode
stdair::CabinCode_T _cabinCode
Definition
SegmentCabinStruct.hpp:28
AIRINV::SegmentCabinStruct::_fareFamilies
FareFamilyStructList_T _fareFamilies
Definition
SegmentCabinStruct.hpp:31
AIRINV::SegmentStruct
Definition
SegmentStruct.hpp:23
AIRINV::SegmentStruct::_offPoint
stdair::AirportCode_T _offPoint
Definition
SegmentStruct.hpp:26
AIRINV::SegmentStruct::_cabinList
SegmentCabinStructList_T _cabinList
Definition
SegmentStruct.hpp:32
AIRINV::SegmentStruct::_boardingPoint
stdair::AirportCode_T _boardingPoint
Definition
SegmentStruct.hpp:25
AIRINV::SegmentStruct::describe
const std::string describe() const
Definition
SegmentStruct.cpp:14
Generated on
for AirInv by
1.17.0