AirTSP Logo  1.01.7
C++ Simulated Airline Travel Solution Provider (TSP) Library
TravelSolutionParser.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <sstream>
6 #include <fstream>
7 #include <cassert>
8 // StdAir
9 #include <stdair/stdair_exceptions.hpp>
10 #include <stdair/basic/BasConst_TravelSolution.hpp>
11 #include <stdair/basic/BasFileMgr.hpp>
12 #include <stdair/bom/BomRoot.hpp>
13 #include <stdair/service/Logger.hpp>
14 // AirTSP
16 
17 namespace AIRTSP {
18 
19  // ////////////////////////////////////////////////////////////////////
21  parseInputFileAndBuildBom (const std::string& iInputFileName) {
22  bool hasReadBeenSuccessful = false;
23 
24  // Check that the file path given as input corresponds to an actual file
25  const bool doesExistAndIsReadable =
26  stdair::BasFileMgr::doesExistAndIsReadable (iInputFileName);
27  if (doesExistAndIsReadable == false) {
28  std::ostringstream oMessage;
29  oMessage << "The input file, '" << iInputFileName
30  << "', can not be retrieved on the file-system";
31  throw stdair::FileNotFoundException (oMessage.str());
32  }
33 
34  // Open the input file
35  std::ifstream inputFile (iInputFileName.c_str());
36  if (! inputFile) {
37  STDAIR_LOG_ERROR ("Can not open input file '" << iInputFileName << "'");
38  throw new stdair::FileNotFoundException ("Can not open input file '"
39  + iInputFileName + "'");
40  }
41 
42  char buffer[80];
43  double dval = 0.0;
44  std::string dvalStr;
45  short i = 1;
46  bool hasAllPArams = true;
47 
48  stdair::AirportCode_T dAirport;
49  stdair::AirportCode_T aAirport;
50  stdair::Date_T depDate;
51  stdair::Duration_T depTime;
52  stdair::Duration_T arTime;
53  stdair::Duration_T dur;
54  //bool Ref;
55  stdair::AirlineCode_T airline;
56  stdair::CabinCode_T cabin;
57  //stdair::FlightNumber_T flightNum;
58  //stdair::Fare_T fare;
59  //int lagsNum;
60  //bool SNS;
61  //bool change;
62 
63  while (inputFile.getline (buffer, sizeof (buffer), ';')) {
64  std::istringstream iStringStr (buffer);
65 
66  if (i>=1 && i<=14) {
67  iStringStr >> dvalStr;
68  }
69 
70  if (i == 15) {
71  iStringStr >> dval;
72  }
73 
74  if (i == 1) {
75  hasAllPArams = true;
76  dAirport = dvalStr;
77 
78  } else if (i == 2) {
79  aAirport = dvalStr;
80  // std::cout << "City Pair = '" << dAiport
81  // << "-" << aAirport << "'" << std::endl;
82 
83  } else if (i == 3) {
84  depDate = boost::gregorian::from_simple_string (dvalStr);
85  // std::cout << "Date = '" << depDate << "'" << std::endl;
86 
87  } else if (i == 4) {
88  depTime = boost::posix_time::duration_from_string (dvalStr);
89 
90  } else if (i == 5) {
91  arTime = boost::posix_time::duration_from_string (dvalStr);
92 
93  } else if (i == 6) {
94  dur = boost::posix_time::duration_from_string (dvalStr);
95 
96  } else if (i == 7) {
97  //if (dvalStr == "refundable fare")
98  // Ref = true;
99  //else Ref = false;
100 
101  } else if (i == 8) {
102  airline = dvalStr;
103 
104  } else if (i == 9) {
105  cabin = dvalStr;
106 
107  } else if (i == 10) {
108  //flightNum = dval;
109 
110  } else if (i == 11) {
111  //fare = dval;
112 
113  } else if (i == 12) {
114  //lagsNum = dval;
115 
116  } else if (i == 13) {
117  //if (dvalStr == "Saturday Nigth Stay mandatory")
118  // SNS = true;
119  //else SNS = false;
120 
121  } else if (i == 14) {
122  //if (dvalStr == "changeable fare")
123  // change = true;
124  //else change = false;
125  i = 0;
126  }
127 
128  //
129  ++i;
130  }
131 
132  if (hasAllPArams && i == 1) {
133  STDAIR_LOG_DEBUG ("Successfully read");
134  }
135 
136  //
137  if (!inputFile.eof()) {
138  STDAIR_LOG_ERROR ("Problem when reading input file '" << iInputFileName
139  << "'");
140  return hasReadBeenSuccessful;
141  }
142 
143  //
144  hasReadBeenSuccessful = true;
145  return hasReadBeenSuccessful;
146  }
147 
148 }
AIRTSP
Definition: AIRTSP_Service.hpp:23
AIRTSP::TravelSolutionParser::parseInputFileAndBuildBom
static bool parseInputFileAndBuildBom(const stdair::Filename_T &)
Definition: TravelSolutionParser.cpp:21
TravelSolutionParser.hpp