AirTSP Logo  1.01.11
C++ Simulated Airline Travel Solution Provider (TSP) Library
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
13
14namespace AIRTSP {
15
16 // ////////////////////////////////////////////////////////////////////
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 // ////////////////////////////////////////////////////////////////////
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 // ////////////////////////////////////////////////////////////////////
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 // ////////////////////////////////////////////////////////////////////
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 // ////////////////////////////////////////////////////////////////////
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 // ////////////////////////////////////////////////////////////////////
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}
Forward declarations.
stdair::FlightNumber_T _flightNumber
AirportOrderedList_T _airportOrderedList
void addSegmentCabin(const SegmentStruct &, const SegmentCabinStruct &)
void addAirport(const stdair::AirportCode_T &)
stdair::Date_T getDate() const
stdair::DatePeriod_T _dateRange
void addFareFamily(const SegmentStruct &, const SegmentCabinStruct &, const FareFamilyStruct &)
const std::string describe() const
stdair::AirlineCode_T _airlineCode
stdair::Duration_T getTime() const
const std::string describe() const
Definition LegStruct.cpp:22
FareFamilyStructList_T _fareFamilies
const std::string describe() const
stdair::AirportCode_T _offPoint
SegmentCabinStructList_T _cabinList
stdair::AirportCode_T _boardingPoint