AirInv Logo  1.00.9
C++ Simulated Airline Inventory Management System 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// AIRINV
13
14namespace AIRINV {
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
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 // ////////////////////////////////////////////////////////////////////
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 // ////////////////////////////////////////////////////////////////////
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 // ////////////////////////////////////////////////////////////////////
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}
Forward declarations.
Utility Structure for the parsing of fare family details.
stdair::FlightNumber_T _flightNumber
stdair::Duration_T getTime() const
AirportOrderedList_T _airportOrderedList
void addFareFamily(const SegmentStruct &, const SegmentCabinStruct &, const FareFamilyStruct &)
const std::string describe() const
void addAirport(const stdair::AirportCode_T &)
void addSegmentCabin(const SegmentStruct &, const SegmentCabinStruct &)
stdair::AirlineCode_T _airlineCode
stdair::Date_T getDate() const
stdair::DatePeriod_T _dateRange
const std::string describe() const
Definition LegStruct.cpp:21
Utility Structure for the parsing of SegmentCabin details.
FareFamilyStructList_T _fareFamilies
stdair::AirportCode_T _offPoint
SegmentCabinStructList_T _cabinList
stdair::AirportCode_T _boardingPoint
const std::string describe() const