7 #include <boost/date_time/posix_time/posix_time.hpp>
8 #include <boost/date_time/gregorian/gregorian.hpp>
9 #include <boost/program_options.hpp>
10 #include <boost/tokenizer.hpp>
11 #include <boost/lexical_cast.hpp>
13 #include <stdair/STDAIR_Service.hpp>
14 #include <stdair/bom/BomDisplay.hpp>
15 #include <stdair/bom/BookingRequestStruct.hpp>
16 #include <stdair/bom/TravelSolutionStruct.hpp>
17 #include <stdair/service/Logger.hpp>
21 #include <airtsp/config/airtsp-paths.hpp>
60 std::ostringstream oStr;
62 unsigned short idx = iWordList.size();
63 for (WordList_T::const_iterator itWord = iWordList.begin();
64 itWord != iWordList.end(); ++itWord, --idx) {
65 const std::string& lWord = *itWord;
77 template<
class T> std::ostream&
operator<< (std::ostream& os,
78 const std::vector<T>& v) {
79 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout,
" "));
88 bool& ioIsBuiltin,
bool& ioReadBookingRequestFromCmdLine,
89 stdair::Filename_T& ioInputFilename,
90 std::string& ioLogFilename,
91 std::string& ioBookingRequestString) {
103 boost::program_options::options_description
generic (
"Generic options");
104 generic.add_options()
105 (
"prefix",
"print installation prefix")
106 (
"version,v",
"print version string")
107 (
"help,h",
"produce help message");
111 boost::program_options::options_description config (
"Configuration");
114 "The sample BOM tree can be either built-in or parsed from input files. In that latter case, the -i/--input option must be specified as well")
117 "(CSV) input file specifying the schedule (flight-period) entries")
120 "Filename for the logs")
121 (
"read_booking_request,r",
122 "Indicates that a booking request is given as a command-line option. That latter must then be given with the -b/--bkg_req option")
124 boost::program_options::value< WordList_T >(&lWordList)->multitoken(),
125 "Booking request word list (e.g. 'NCE BKK NCE 2007-04-21 2007-04-21 10:00:00 C 1 DF RO 5 NONE 10:0:0 2000.0 20.0'), which should be located at the end of the command line (otherwise, the other options would be interpreted as part of that booking request word list)")
130 boost::program_options::options_description hidden (
"Hidden options");
133 boost::program_options::value< std::vector<std::string> >(),
134 "Show the copyright (license)");
136 boost::program_options::options_description cmdline_options;
137 cmdline_options.add(
generic).add(config).add(hidden);
139 boost::program_options::options_description config_file_options;
140 config_file_options.add(config).add(hidden);
142 boost::program_options::options_description visible (
"Allowed options");
143 visible.add(
generic).add(config);
145 boost::program_options::positional_options_description p;
146 p.add (
"copyright", -1);
148 boost::program_options::variables_map vm;
149 boost::program_options::
150 store (boost::program_options::command_line_parser (argc, argv).
151 options (cmdline_options).positional(p).run(), vm);
153 std::ifstream ifs (
"airtsp.cfg");
154 boost::program_options::store (parse_config_file (ifs, config_file_options),
156 boost::program_options::notify (vm);
158 if (vm.count (
"help")) {
159 std::cout << visible << std::endl;
163 if (vm.count (
"version")) {
164 std::cout << PACKAGE_NAME <<
", version " << PACKAGE_VERSION << std::endl;
168 if (vm.count (
"prefix")) {
169 std::cout <<
"Installation prefix: " << PREFIXDIR << std::endl;
173 if (vm.count (
"builtin")) {
176 const std::string isBuiltinStr = (ioIsBuiltin ==
true)?
"yes":
"no";
177 std::cout <<
"The BOM should be built-in? " << isBuiltinStr << std::endl;
180 std::ostringstream oErrorMessageStr;
181 oErrorMessageStr <<
"Either the -b/--builtin option, or the -i/--input option"
182 <<
" must be specified";
184 if (ioIsBuiltin ==
false) {
185 if (vm.count (
"input")) {
186 ioInputFilename = vm[
"input"].as< std::string >();
187 std::cout <<
"Input filename is: " << ioInputFilename << std::endl;
192 std::cerr << oErrorMessageStr.str() << std::endl;
197 if (vm.count (
"read_booking_request")) {
198 ioReadBookingRequestFromCmdLine =
true;
200 const std::string readBookingRequestFromCmdLineStr =
201 (ioReadBookingRequestFromCmdLine ==
true)?
"yes":
"no";
202 std::cout <<
"A booking request is to be given as command-line option? "
203 << readBookingRequestFromCmdLineStr << std::endl;
205 if (ioReadBookingRequestFromCmdLine ==
true) {
207 if (lWordList.empty() ==
true) {
208 std::cerr <<
"When the --read_booking_request/-r option is given, "
209 <<
"a query must also be provided (with the --bkg_req/-b "
210 <<
"option at the end of the command-line)" << std::endl;
216 std::cout <<
"The booking request string is: " << ioBookingRequestString
220 if (vm.count (
"log")) {
221 ioLogFilename = vm[
"log"].as< std::string >();
222 std::cout <<
"Log filename is: " << ioLogFilename << std::endl;
229 stdair::BookingRequestStruct
231 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
232 boost::char_separator<char> sep(
" -:");
234 tokenizer tokens (iRequestOption, sep);
237 tokenizer::iterator tok_iter = tokens.begin();
238 assert (tok_iter != tokens.end());
239 const stdair::AirportCode_T iOrigin (*tok_iter);
242 ++tok_iter; assert (tok_iter != tokens.end());
243 const stdair::AirportCode_T iDestination (*tok_iter);
246 ++tok_iter; assert (tok_iter != tokens.end());
247 const stdair::AirportCode_T iPOS (*tok_iter);
250 ++tok_iter; assert (tok_iter != tokens.end());
251 const short lDepDateYear = boost::lexical_cast<
short> (*tok_iter);
252 ++tok_iter; assert (tok_iter != tokens.end());
253 const short lDepDateMonth = boost::lexical_cast<
short> (*tok_iter);
254 ++tok_iter; assert (tok_iter != tokens.end());
255 const short lDepDateDay = boost::lexical_cast<
short> (*tok_iter);
256 const stdair::Date_T iDepartureDate(lDepDateYear, lDepDateMonth, lDepDateDay);
259 ++tok_iter; assert (tok_iter != tokens.end());
260 const short lReqDateYear = boost::lexical_cast<
short> (*tok_iter);
261 ++tok_iter; assert (tok_iter != tokens.end());
262 const short lReqDateMonth = boost::lexical_cast<
short> (*tok_iter);
263 ++tok_iter; assert (tok_iter != tokens.end());
264 const short lReqDateDay = boost::lexical_cast<
short> (*tok_iter);
265 const stdair::Date_T iRequestDate (lReqDateYear, lReqDateMonth, lReqDateDay);
268 ++tok_iter; assert (tok_iter != tokens.end());
269 const short lReqTimeHours = boost::lexical_cast<
short> (*tok_iter);
270 ++tok_iter; assert (tok_iter != tokens.end());
271 const short lReqTimeMinutes = boost::lexical_cast<
short> (*tok_iter);
272 ++tok_iter; assert (tok_iter != tokens.end());
273 const short lReqTimeSeconds = boost::lexical_cast<
short> (*tok_iter);
274 const stdair::Duration_T iRequestTime (lReqTimeHours, lReqTimeMinutes,
278 const stdair::DateTime_T iRequestDateTime (iRequestDate, iRequestTime);
281 ++tok_iter; assert (tok_iter != tokens.end());
282 const stdair::CabinCode_T iPreferredCabin (*tok_iter);
285 ++tok_iter; assert (tok_iter != tokens.end());
286 const stdair::NbOfSeats_T iPartySize = 1;
289 ++tok_iter; assert (tok_iter != tokens.end());
290 const stdair::ChannelLabel_T iChannel (*tok_iter);
293 ++tok_iter; assert (tok_iter != tokens.end());
294 const stdair::TripType_T iTripType (*tok_iter);
297 ++tok_iter; assert (tok_iter != tokens.end());
298 const stdair::DayDuration_T iStayDuration = 5;
301 ++tok_iter; assert (tok_iter != tokens.end());
302 const stdair::FrequentFlyer_T iFrequentFlyerType (
"NONE");
305 ++tok_iter; assert (tok_iter != tokens.end());
306 const short lPrefTimeHours = boost::lexical_cast<
short> (*tok_iter);
307 ++tok_iter; assert (tok_iter != tokens.end());
308 const short lPrefTimeMinutes = boost::lexical_cast<
short> (*tok_iter);
309 ++tok_iter; assert (tok_iter != tokens.end());
310 const short lPrefTimeSeconds = boost::lexical_cast<
short> (*tok_iter);
311 const stdair::Duration_T iPreferredDepartureTime (lPrefTimeHours,
316 ++tok_iter; assert (tok_iter != tokens.end());
317 const stdair::WTP_T iWTP = 2000.0;
320 ++tok_iter; assert (tok_iter != tokens.end());
321 const stdair::PriceValue_T iValueOfTime = 20.0;
325 const stdair::ChangeFees_T iChangeFees =
true;
326 const stdair::Disutility_T iChangeFeeDisutility = 50;
330 const stdair::NonRefundable_T iNonRefundable =
true;
331 const stdair::Disutility_T iNonRefundableDisutility = 50;
334 return stdair::BookingRequestStruct (iOrigin,
336 iDepartureDate, iRequestDateTime,
337 iPreferredCabin, iPartySize,
338 iChannel, iTripType, iStayDuration,
340 iPreferredDepartureTime, iWTP,
341 iValueOfTime, iChangeFees,
342 iChangeFeeDisutility, iNonRefundable,
343 iNonRefundableDisutility);
347 int main (
int argc,
char* argv[]) {
354 bool readBookingRequestFromCmdLine;
357 stdair::Filename_T lInputFilename;
360 stdair::Filename_T lLogFilename;
363 std::string lBookingRequestString;
366 const int lOptionParserStatus =
368 lInputFilename, lLogFilename, lBookingRequestString);
375 std::ofstream logOutputFile;
377 logOutputFile.open (lLogFilename.c_str());
378 logOutputFile.clear();
381 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
385 if (isBuiltin ==
true) {
392 const stdair::ScheduleFilePath lScheduleFilePath (lInputFilename);
397 if (readBookingRequestFromCmdLine ==
false) {
402 STDAIR_LOG_DEBUG(
"Booking request string: '" << lBookingRequestString <<
"'");
405 const stdair::BookingRequestStruct& lBookingRequest =
409 stdair::TravelSolutionList_T lTravelSolutionList;
413 STDAIR_LOG_DEBUG (
"Parsed booking request: " << lBookingRequest);
416 std::ostringstream oStream;
417 stdair::BomDisplay::csvDisplay (oStream, lTravelSolutionList);
418 STDAIR_LOG_DEBUG (oStream.str());
421 logOutputFile.close();