Go to the documentation of this file.00001
00002
00003
00004
00005 #include <cassert>
00006 #include <sstream>
00007
00008 #include <stdair/basic/BasConst_Period_BOM.hpp>
00009 #include <stdair/service/Logger.hpp>
00010
00011 #include <airinv/AIRINV_Types.hpp>
00012 #include <airinv/bom/FlightPeriodStruct.hpp>
00013
00014 namespace AIRINV {
00015
00016
00017 FlightPeriodStruct::FlightPeriodStruct ()
00018 : _dateRange (stdair::BOOST_DEFAULT_DATE_PERIOD),
00019 _dow (stdair::DEFAULT_DOW_STRING),
00020 _legAlreadyDefined (false), _itSeconds (0) {
00021 }
00022
00023
00024 stdair::Date_T FlightPeriodStruct::getDate() const {
00025 return stdair::Date_T (_itYear, _itMonth, _itDay);
00026 }
00027
00028
00029 stdair::Duration_T FlightPeriodStruct::getTime() const {
00030 return boost::posix_time::hours (_itHours)
00031 + boost::posix_time::minutes (_itMinutes)
00032 + boost::posix_time::seconds (_itSeconds);
00033 }
00034
00035
00036 const std::string FlightPeriodStruct::describe() const {
00037 std::ostringstream ostr;
00038 ostr << _airlineCode << _flightNumber << ", " << _dateRange
00039 << " - " << _dow << std::endl;
00040
00041 for (LegStructList_T::const_iterator itLeg = _legList.begin();
00042 itLeg != _legList.end(); ++itLeg) {
00043 const LegStruct& lLeg = *itLeg;
00044 ostr << lLeg.describe();
00045 }
00046
00047 for (SegmentStructList_T::const_iterator itSegment = _segmentList.begin();
00048 itSegment != _segmentList.end(); ++itSegment) {
00049 const SegmentStruct& lSegment = *itSegment;
00050 ostr << lSegment.describe();
00051 }
00052
00053
00054
00055
00056
00057
00058 return ostr.str();
00059 }
00060
00061
00062 void FlightPeriodStruct::addAirport (const stdair::AirportCode_T& iAirport) {
00063 AirportList_T::const_iterator itAirport = _airportList.find (iAirport);
00064 if (itAirport == _airportList.end()) {
00065
00066 const bool insertSuccessful = _airportList.insert (iAirport).second;
00067
00068 if (insertSuccessful == false) {
00069
00070 }
00071
00072
00073 _airportOrderedList.push_back (iAirport);
00074 }
00075 }
00076
00077
00078 void FlightPeriodStruct::buildSegments () {
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 assert (_airportOrderedList.size() >= 2);
00089
00090 _segmentList.clear();
00091 for (AirportOrderedList_T::const_iterator itAirport_i =
00092 _airportOrderedList.begin();
00093 itAirport_i != _airportOrderedList.end()-1; ++itAirport_i) {
00094 for (AirportOrderedList_T::const_iterator itAirport_j = itAirport_i + 1;
00095 itAirport_j != _airportOrderedList.end(); ++itAirport_j) {
00096 SegmentStruct lSegmentStruct;
00097 lSegmentStruct._boardingPoint = *itAirport_i;
00098 lSegmentStruct._offPoint = *itAirport_j;
00099
00100 _segmentList.push_back (lSegmentStruct);
00101 }
00102 }
00103
00104
00105 _airportList.clear();
00106 _airportOrderedList.clear();
00107 }
00108
00109
00110 void FlightPeriodStruct::
00111 addSegmentCabin (const SegmentStruct& iSegment,
00112 const SegmentCabinStruct& iCabin) {
00113
00114
00115 SegmentStructList_T::iterator itSegment = _segmentList.begin();
00116 for ( ; itSegment != _segmentList.end(); ++itSegment) {
00117 const SegmentStruct& lSegment = *itSegment;
00118
00119 const stdair::AirportCode_T& lBoardingPoint = iSegment._boardingPoint;
00120 const stdair::AirportCode_T& lOffPoint = iSegment._offPoint;
00121 if (lSegment._boardingPoint == lBoardingPoint
00122 && lSegment._offPoint == lOffPoint) {
00123 break;
00124 }
00125 }
00126
00127
00128
00129
00130 if (itSegment == _segmentList.end()) {
00131 STDAIR_LOG_ERROR ("Within the schedule input file, there is a "
00132 << "flight for which the airports of segments "
00133 << "and those of the legs do not correspond.");
00134 throw SegmentDateNotFoundException ("Within the schedule input file, "
00135 "there is a flight for which the "
00136 "airports of segments and those of "
00137 "the legs do not correspond.");
00138 }
00139
00140
00141 assert (itSegment != _segmentList.end());
00142 SegmentStruct& lSegment = *itSegment;
00143 lSegment._cabinList.push_back (iCabin);
00144 }
00145
00146
00147 void FlightPeriodStruct::
00148 addSegmentCabin (const SegmentCabinStruct& iCabin) {
00149
00150
00151 for (SegmentStructList_T::iterator itSegment = _segmentList.begin();
00152 itSegment != _segmentList.end(); ++itSegment) {
00153 SegmentStruct& lSegment = *itSegment;
00154
00155 lSegment._cabinList.push_back (iCabin);
00156 }
00157 }
00158
00159
00160 void FlightPeriodStruct::
00161 addFareFamily (const SegmentStruct& iSegment,
00162 const SegmentCabinStruct& iCabin,
00163 const FareFamilyStruct& iFareFamily) {
00164
00165
00166 SegmentStructList_T::iterator itSegment = _segmentList.begin();
00167 for ( ; itSegment != _segmentList.end(); ++itSegment) {
00168 const SegmentStruct& lSegment = *itSegment;
00169
00170 const stdair::AirportCode_T& lBoardingPoint = iSegment._boardingPoint;
00171 const stdair::AirportCode_T& lOffPoint = iSegment._offPoint;
00172 if (lSegment._boardingPoint == lBoardingPoint
00173 && lSegment._offPoint == lOffPoint) {
00174 break;
00175 }
00176 }
00177
00178
00179
00180
00181 if (itSegment == _segmentList.end()) {
00182 STDAIR_LOG_ERROR ("Within the schedule input file, there is a flight "
00183 << "for which the airports of segments and "
00184 << "those of the legs do not correspond.");
00185 throw SegmentDateNotFoundException ("Within the schedule input file, "
00186 "there is a flight for which the "
00187 "airports of segments and those of "
00188 "the legs do not correspond.");
00189 }
00190
00191
00192 assert (itSegment != _segmentList.end());
00193 SegmentStruct& lSegment = *itSegment;
00194
00195
00196 SegmentCabinStructList_T::iterator itCabin = lSegment._cabinList.begin();
00197 for ( ; itCabin != lSegment._cabinList.end(); ++itCabin) {
00198 const SegmentCabinStruct& lCabin = *itCabin;
00199
00200 const stdair::CabinCode_T& lCabinCode = lCabin._cabinCode;
00201 if (iCabin._cabinCode == lCabinCode) {
00202 break;
00203 }
00204 }
00205
00206
00207
00208
00209 if (itCabin == lSegment._cabinList.end()) {
00210 STDAIR_LOG_ERROR ("Within the schedule input file, there is a flight "
00211 << "for which the cabin code does not exist.");
00212 throw SegmentDateNotFoundException ("Within the schedule input file, "
00213 "there is a flight for which the "
00214 "cabin code does not exist.");
00215 }
00216
00217
00218 assert (itCabin != lSegment._cabinList.end());
00219 SegmentCabinStruct& lCabin = *itCabin;
00220 lCabin._fareFamilies.push_back(iFareFamily);
00221 }
00222
00223
00224 void FlightPeriodStruct::
00225 addFareFamily (const SegmentCabinStruct& iCabin,
00226 const FareFamilyStruct& iFareFamily) {
00227
00228
00229
00230 for (SegmentStructList_T::iterator itSegment = _segmentList.begin();
00231 itSegment != _segmentList.end(); ++itSegment) {
00232 SegmentStruct& lSegment = *itSegment;
00233
00234
00235 SegmentCabinStructList_T::iterator itCabin = lSegment._cabinList.begin();
00236 for ( ; itCabin != lSegment._cabinList.end(); ++itCabin) {
00237 const SegmentCabinStruct& lCabin = *itCabin;
00238
00239 const stdair::CabinCode_T& lCabinCode = lCabin._cabinCode;
00240 if (iCabin._cabinCode == lCabinCode) {
00241 break;
00242 }
00243 }
00244
00245
00246
00247
00248 if (itCabin == lSegment._cabinList.end()) {
00249 STDAIR_LOG_ERROR ("Within the schedule input file, there is a flight"
00250 << " for which the cabin code does not exist.");
00251 throw SegmentDateNotFoundException ("Within the schedule input file, "
00252 "there is a flight for which the "
00253 "cabin code does not exist.");
00254 }
00255
00256
00257 assert (itCabin != lSegment._cabinList.end());
00258 SegmentCabinStruct& lCabin = *itCabin;
00259 lCabin._fareFamilies.push_back(iFareFamily);
00260 }
00261 }
00262
00263 }