Go to the documentation of this file.00001
00002
00003
00004
00005 #include <sstream>
00006 #include <fstream>
00007 #include <cassert>
00008
00009 #include <stdair/stdair_exceptions.hpp>
00010 #include <stdair/basic/BasConst_TravelSolution.hpp>
00011 #include <stdair/basic/BasFileMgr.hpp>
00012 #include <stdair/bom/BomRoot.hpp>
00013 #include <stdair/service/Logger.hpp>
00014
00015 #include <airsched/command/TravelSolutionParser.hpp>
00016
00017 namespace AIRSCHED {
00018
00019
00020 bool TravelSolutionParser::
00021 parseInputFileAndBuildBom (const std::string& iInputFileName) {
00022 bool hasReadBeenSuccessful = false;
00023
00024
00025 const bool doesExistAndIsReadable =
00026 stdair::BasFileMgr::doesExistAndIsReadable (iInputFileName);
00027 if (doesExistAndIsReadable == false) {
00028 std::ostringstream oMessage;
00029 oMessage << "The input file, '" << iInputFileName
00030 << "', can not be retrieved on the file-system";
00031 throw stdair::FileNotFoundException (oMessage.str());
00032 }
00033
00034
00035 std::ifstream inputFile (iInputFileName.c_str());
00036 if (! inputFile) {
00037 STDAIR_LOG_ERROR ("Can not open input file '" << iInputFileName << "'");
00038 throw new stdair::FileNotFoundException ("Can not open input file '"
00039 + iInputFileName + "'");
00040 }
00041
00042 char buffer[80];
00043 double dval = 0.0;
00044 std::string dvalStr;
00045 short i = 1;
00046 bool hasAllPArams = true;
00047
00048 stdair::AirportCode_T dAirport;
00049 stdair::AirportCode_T aAirport;
00050 stdair::Date_T depDate;
00051 stdair::Duration_T depTime;
00052 stdair::Duration_T arTime;
00053 stdair::Duration_T dur;
00054
00055 stdair::AirlineCode_T airline;
00056 stdair::CabinCode_T cabin;
00057
00058
00059
00060
00061
00062
00063 while (inputFile.getline (buffer, sizeof (buffer), ';')) {
00064 std::istringstream iStringStr (buffer);
00065
00066 bool hasRead = false;
00067
00068 if (i == 1) {
00069 hasAllPArams = true;
00070 }
00071
00072 if (i>=1 && i<=14) {
00073 hasRead = (iStringStr >> dvalStr);
00074 }
00075
00076 if (i == 15) {
00077 hasRead = (iStringStr >> dval);
00078 }
00079
00080 if (hasRead) {
00081 if (i == 1) {
00082 dAirport = dvalStr;
00083
00084 } else if (i == 2) {
00085 aAirport = dvalStr;
00086
00087
00088
00089 } else if (i == 3) {
00090 depDate = boost::gregorian::from_simple_string (dvalStr);
00091
00092
00093 } else if (i == 4) {
00094 depTime = boost::posix_time::duration_from_string (dvalStr);
00095
00096 } else if (i == 5) {
00097 arTime = boost::posix_time::duration_from_string (dvalStr);
00098
00099 } else if (i == 6) {
00100 dur = boost::posix_time::duration_from_string (dvalStr);
00101
00102 } else if (i == 7) {
00103
00104
00105
00106
00107 } else if (i == 8) {
00108 airline = dvalStr;
00109
00110 } else if (i == 9) {
00111 cabin = dvalStr;
00112
00113 } else if (i == 10) {
00114
00115
00116 } else if (i == 11) {
00117
00118
00119 } else if (i == 12) {
00120
00121
00122 } else if (i == 13) {
00123
00124
00125
00126
00127 } else if (i == 14) {
00128
00129
00130
00131 i = 0;
00132 }
00133
00134
00135 ++i;
00136
00137 } else {
00138 hasAllPArams = false;
00139 }
00140 }
00141
00142 if (hasAllPArams && i == 1) {
00143 STDAIR_LOG_DEBUG ("Successfully read");
00144 }
00145
00146
00147 if (!inputFile.eof()) {
00148 STDAIR_LOG_ERROR ("Problem when reading input file '" << iInputFileName
00149 << "'");
00150 return hasReadBeenSuccessful;
00151 }
00152
00153
00154 hasReadBeenSuccessful = true;
00155 return hasReadBeenSuccessful;
00156 }
00157
00158 }