1.01.17
C++ Simulated Airline Travel Solution Provider (TSP) 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
// AirTSP
11
#include <
airtsp/AIRTSP_Types.hpp
>
12
#include <
airtsp/bom/FlightPeriodStruct.hpp
>
13
14
namespace
AIRTSP
{
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
132
if
(itSegment ==
_segmentList
.end()) {
133
std::ostringstream oStr;
134
oStr <<
"Within the schedule input file, there is a flight, for which "
135
<<
"the airports of segments and those of the legs "
136
<<
"do not correspond"
;
137
STDAIR_LOG_ERROR (oStr.str());
138
throw
SegmentDateNotFoundException
(oStr.str());
139
}
140
141
// Add the Cabin structure to the Segment Cabin structure.
142
assert (itSegment !=
_segmentList
.end());
143
SegmentStruct
& lSegment = *itSegment;
144
lSegment.
_cabinList
.push_back (iCabin);
145
}
146
147
// ////////////////////////////////////////////////////////////////////
148
void
FlightPeriodStruct::
149
addSegmentCabin
(
const
SegmentCabinStruct
& iCabin) {
150
// Iterate on all the Segment structures (as they get the same cabin
151
// definitions)
152
for
(SegmentStructList_T::iterator itSegment =
_segmentList
.begin();
153
itSegment !=
_segmentList
.end(); ++itSegment) {
154
SegmentStruct
& lSegment = *itSegment;
155
156
lSegment.
_cabinList
.push_back (iCabin);
157
}
158
}
159
160
// ////////////////////////////////////////////////////////////////////
161
void
FlightPeriodStruct::
162
addFareFamily
(
const
SegmentStruct
& iSegment,
163
const
SegmentCabinStruct
& iCabin,
164
const
FareFamilyStruct
& iFareFamily) {
165
// Retrieve the Segment structure corresponding to the (boarding, off) point
166
// pair.
167
SegmentStructList_T::iterator itSegment =
_segmentList
.begin();
168
for
( ; itSegment !=
_segmentList
.end(); ++itSegment) {
169
const
SegmentStruct
& lSegment = *itSegment;
170
171
const
stdair::AirportCode_T& lBoardingPoint = iSegment.
_boardingPoint
;
172
const
stdair::AirportCode_T& lOffPoint = iSegment.
_offPoint
;
173
if
(lSegment.
_boardingPoint
== lBoardingPoint
174
&& lSegment.
_offPoint
== lOffPoint) {
175
break
;
176
}
177
}
178
184
if
(itSegment ==
_segmentList
.end()) {
185
std::ostringstream oStr;
186
oStr <<
"Within the schedule input file, there is a flight, for which "
187
<<
"the airports of segments and those of the legs "
188
<<
"do not correspond"
;
189
STDAIR_LOG_ERROR (oStr.str());
190
throw
SegmentDateNotFoundException
(oStr.str());
191
}
192
193
// Add the Cabin structure to the Segment Cabin structure.
194
assert (itSegment !=
_segmentList
.end());
195
SegmentStruct
& lSegment = *itSegment;
196
197
// Retrieve the Segment cabin structure given the cabin code
198
SegmentCabinStructList_T::iterator itCabin = lSegment.
_cabinList
.begin();
199
for
( ; itCabin != lSegment.
_cabinList
.end(); ++itCabin) {
200
const
SegmentCabinStruct
& lCabin = *itCabin;
201
202
const
stdair::CabinCode_T& lCabinCode = lCabin.
_cabinCode
;
203
if
(iCabin.
_cabinCode
== lCabinCode) {
204
break
;
205
}
206
}
207
213
if
(itCabin == lSegment.
_cabinList
.end()) {
214
std::ostringstream oStr;
215
oStr <<
"Within the schedule input file, there is a flight "
216
<<
"for which the cabin code does not exist."
;
217
STDAIR_LOG_ERROR (oStr.str());
218
throw
SegmentDateNotFoundException
(oStr.str());
219
}
220
221
// Add the Cabin structure to the Segment Cabin structure.
222
assert (itCabin != lSegment.
_cabinList
.end());
223
SegmentCabinStruct
& lCabin = *itCabin;
224
lCabin.
_fareFamilies
.push_back(iFareFamily);
225
}
226
227
// ////////////////////////////////////////////////////////////////////
228
void
FlightPeriodStruct::
229
addFareFamily
(
const
SegmentCabinStruct
& iCabin,
230
const
FareFamilyStruct
& iFareFamily) {
231
// Iterate on all the Segment structures (as they get the same cabin
232
// definitions)
233
234
for
(SegmentStructList_T::iterator itSegment =
_segmentList
.begin();
235
itSegment !=
_segmentList
.end(); ++itSegment) {
236
SegmentStruct
& lSegment = *itSegment;
237
238
// Retrieve the Segment cabin structure given the cabin code
239
SegmentCabinStructList_T::iterator itCabin = lSegment.
_cabinList
.begin();
240
for
( ; itCabin != lSegment.
_cabinList
.end(); ++itCabin) {
241
const
SegmentCabinStruct
& lCabin = *itCabin;
242
243
const
stdair::CabinCode_T& lCabinCode = lCabin.
_cabinCode
;
244
if
(iCabin.
_cabinCode
== lCabinCode) {
245
break
;
246
}
247
}
248
254
if
(itCabin == lSegment.
_cabinList
.end()) {
255
std::ostringstream oStr;
256
oStr <<
"Within the schedule input file, there is a flight "
257
<<
"for which the cabin code does not exist."
;
258
STDAIR_LOG_ERROR (oStr.str());
259
throw
SegmentDateNotFoundException
(oStr.str());
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
}
AIRTSP_Types.hpp
FlightPeriodStruct.hpp
AIRTSP::SegmentDateNotFoundException
Definition
AIRTSP_Types.hpp:23
AIRTSP
Definition
AIRTSP_Service.hpp:23
stdair
Forward declarations.
Definition
AIRTSP_Service.hpp:14
AIRTSP::FareFamilyStruct
Definition
FareFamilyStruct.hpp:17
AIRTSP::FlightPeriodStruct::_itSeconds
long _itSeconds
Definition
FlightPeriodStruct.hpp:108
AIRTSP::FlightPeriodStruct::_flightNumber
stdair::FlightNumber_T _flightNumber
Definition
FlightPeriodStruct.hpp:85
AIRTSP::FlightPeriodStruct::_itMonth
unsigned int _itMonth
Definition
FlightPeriodStruct.hpp:101
AIRTSP::FlightPeriodStruct::_airportList
AirportList_T _airportList
Definition
FlightPeriodStruct.hpp:112
AIRTSP::FlightPeriodStruct::_airportOrderedList
AirportOrderedList_T _airportOrderedList
Definition
FlightPeriodStruct.hpp:113
AIRTSP::FlightPeriodStruct::addSegmentCabin
void addSegmentCabin(const SegmentStruct &, const SegmentCabinStruct &)
Definition
FlightPeriodStruct.cpp:111
AIRTSP::FlightPeriodStruct::FlightPeriodStruct
FlightPeriodStruct()
Definition
FlightPeriodStruct.cpp:17
AIRTSP::FlightPeriodStruct::addAirport
void addAirport(const stdair::AirportCode_T &)
Definition
FlightPeriodStruct.cpp:62
AIRTSP::FlightPeriodStruct::_legList
LegStructList_T _legList
Definition
FlightPeriodStruct.hpp:88
AIRTSP::FlightPeriodStruct::getDate
stdair::Date_T getDate() const
Definition
FlightPeriodStruct.cpp:24
AIRTSP::FlightPeriodStruct::_dateRange
stdair::DatePeriod_T _dateRange
Definition
FlightPeriodStruct.hpp:86
AIRTSP::FlightPeriodStruct::addFareFamily
void addFareFamily(const SegmentStruct &, const SegmentCabinStruct &, const FareFamilyStruct &)
Definition
FlightPeriodStruct.cpp:162
AIRTSP::FlightPeriodStruct::describe
const std::string describe() const
Definition
FlightPeriodStruct.cpp:36
AIRTSP::FlightPeriodStruct::_airlineCode
stdair::AirlineCode_T _airlineCode
Definition
FlightPeriodStruct.hpp:84
AIRTSP::FlightPeriodStruct::_itHours
long _itHours
Definition
FlightPeriodStruct.hpp:106
AIRTSP::FlightPeriodStruct::_legAlreadyDefined
bool _legAlreadyDefined
Definition
FlightPeriodStruct.hpp:93
AIRTSP::FlightPeriodStruct::_dow
stdair::DoWStruct _dow
Definition
FlightPeriodStruct.hpp:87
AIRTSP::FlightPeriodStruct::_itYear
unsigned int _itYear
Definition
FlightPeriodStruct.hpp:100
AIRTSP::FlightPeriodStruct::_itDay
unsigned int _itDay
Definition
FlightPeriodStruct.hpp:102
AIRTSP::FlightPeriodStruct::_itMinutes
long _itMinutes
Definition
FlightPeriodStruct.hpp:107
AIRTSP::FlightPeriodStruct::getTime
stdair::Duration_T getTime() const
Definition
FlightPeriodStruct.cpp:29
AIRTSP::FlightPeriodStruct::_segmentList
SegmentStructList_T _segmentList
Definition
FlightPeriodStruct.hpp:89
AIRTSP::FlightPeriodStruct::buildSegments
void buildSegments()
Definition
FlightPeriodStruct.cpp:78
AIRTSP::LegStruct
Definition
LegStruct.hpp:24
AIRTSP::LegStruct::describe
const std::string describe() const
Definition
LegStruct.cpp:22
AIRTSP::SegmentCabinStruct
Definition
SegmentCabinStruct.hpp:24
AIRTSP::SegmentCabinStruct::_cabinCode
stdair::CabinCode_T _cabinCode
Definition
SegmentCabinStruct.hpp:26
AIRTSP::SegmentCabinStruct::_fareFamilies
FareFamilyStructList_T _fareFamilies
Definition
SegmentCabinStruct.hpp:31
AIRTSP::SegmentStruct
Definition
SegmentStruct.hpp:24
AIRTSP::SegmentStruct::describe
const std::string describe() const
Definition
SegmentStruct.cpp:15
AIRTSP::SegmentStruct::_offPoint
stdair::AirportCode_T _offPoint
Definition
SegmentStruct.hpp:29
AIRTSP::SegmentStruct::_cabinList
SegmentCabinStructList_T _cabinList
Definition
SegmentStruct.hpp:33
AIRTSP::SegmentStruct::_boardingPoint
stdair::AirportCode_T _boardingPoint
Definition
SegmentStruct.hpp:26
Generated on
for AirTSP by
1.17.0