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