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