/
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/program_options.hpp>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <stdair/config/stdair-paths.hpp>
const std::string K_STDAIR_DEFAULT_LOG_FILENAME ("stdair.log");
const std::string K_STDAIR_DEFAULT_INPUT_FILENAME (STDAIR_SAMPLE_DIR
"/schedule01.csv");
const bool K_STDAIR_DEFAULT_BUILT_IN_INPUT = false;
const bool K_STDAIR_DEFAULT_BUILT_FOR_RMOL = false;
const bool K_STDAIR_DEFAULT_BUILT_FOR_CRS = false;
const int K_STDAIR_EARLY_RETURN_STATUS = 99;
template<
class T> std::ostream&
operator<< (std::ostream& os,
const std::vector<T>& v) {
std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout, " "));
return os;
}
int readConfiguration (int argc, char* argv[], bool& ioIsBuiltin,
bool& ioIsForRMOL, bool& ioIsForCRS,
std::string& ioLogFilename) {
ioIsBuiltin = K_STDAIR_DEFAULT_BUILT_IN_INPUT;
ioIsForRMOL = K_STDAIR_DEFAULT_BUILT_FOR_RMOL;
ioIsForCRS = K_STDAIR_DEFAULT_BUILT_FOR_CRS;
boost::program_options::options_description generic ("Generic options");
generic.add_options()
("prefix", "print installation prefix")
("version,v", "print version string")
("help,h", "produce help message");
boost::program_options::options_description config ("Configuration");
config.add_options()
("builtin,b",
"The sample BOM tree can be either built-in or parsed from an input file. That latter must then be given with the -i/--input option")
("rmol,r",
"Build a sample BOM tree for RMOL (i.e., a dummy flight-date with a single leg-cabin)")
("crs,c",
"Build a sample BOM tree for CRS")
("input,i",
boost::program_options::value< std::string >(&ioInputFilename)->default_value(K_STDAIR_DEFAULT_INPUT_FILENAME),
"(CVS) input file for the demand distributions")
("log,l",
boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_STDAIR_DEFAULT_LOG_FILENAME),
"Filename for the logs")
;
boost::program_options::options_description hidden ("Hidden options");
hidden.add_options()
("copyright",
boost::program_options::value< std::vector<std::string> >(),
"Show the copyright (license)");
boost::program_options::options_description cmdline_options;
cmdline_options.add(generic).add(config).add(hidden);
boost::program_options::options_description config_file_options;
config_file_options.add(config).add(hidden);
boost::program_options::options_description visible ("Allowed options");
visible.add(generic).add(config);
boost::program_options::positional_options_description p;
p.add ("copyright", -1);
boost::program_options::variables_map vm;
boost::program_options::
store (boost::program_options::command_line_parser (argc, argv).
options (cmdline_options).positional(p).run(), vm);
std::ifstream ifs ("stdair.cfg");
boost::program_options::store (parse_config_file (ifs, config_file_options),
vm);
boost::program_options::notify (vm);
if (vm.count ("help")) {
std::cout << visible << std::endl;
return K_STDAIR_EARLY_RETURN_STATUS;
}
if (vm.count ("version")) {
std::cout << PACKAGE_NAME << ", version " << PACKAGE_VERSION << std::endl;
return K_STDAIR_EARLY_RETURN_STATUS;
}
if (vm.count ("prefix")) {
std::cout << "Installation prefix: " << PREFIXDIR << std::endl;
return K_STDAIR_EARLY_RETURN_STATUS;
}
if (vm.count ("builtin")) {
ioIsBuiltin = true;
}
if (vm.count ("rmol")) {
ioIsForRMOL = true;
ioIsBuiltin = false;
}
if (vm.count ("crs")) {
ioIsForCRS = true;
ioIsBuiltin = false;
}
const std::string isBuiltinStr = (ioIsBuiltin == true)?"yes":"no";
std::cout << "The BOM should be built-in? " << isBuiltinStr << std::endl;
const std::string isForRMOLStr = (ioIsForRMOL == true)?"yes":"no";
std::cout << "The BOM should be built-in for RMOL? " << isForRMOLStr
<< std::endl;
const std::string isForCRSStr = (ioIsForCRS == true)?"yes":"no";
std::cout << "The BOM should be built-in for CRS? " << isForCRSStr
<< std::endl;
if (ioIsBuiltin == false && ioIsForRMOL == false && ioIsForCRS == false) {
if (vm.count ("input")) {
ioInputFilename = vm["input"].as< std::string >();
std::cout << "Input filename is: " << ioInputFilename << std::endl;
} else {
std::cerr << "Either one among the -b/--builtin, -r/--rmol, -c/--crs "
<< "or -i/--input options must be specified" << std::endl;
}
}
if (vm.count ("log")) {
ioLogFilename = vm["log"].as< std::string >();
std::cout << "Log filename is: " << ioLogFilename << std::endl;
}
return 0;
}
int main (int argc, char* argv[]) {
bool isBuiltin;
bool isForRMOL;
bool isForCRS;
std::string lLogFilename;
const int lOptionParserStatus =
readConfiguration (argc, argv, isBuiltin, isForRMOL, isForCRS,
lInputFilename, lLogFilename);
if (lOptionParserStatus == K_STDAIR_EARLY_RETURN_STATUS) {
return 0;
}
std::ofstream logOutputFile;
logOutputFile.open (lLogFilename.c_str());
logOutputFile.clear();
if (isBuiltin == true || isForRMOL == true || isForCRS == true) {
if (isForRMOL == true) {
stdairService.buildDummyInventory (300);
} else if (isForCRS == true) {
stdairService.buildSampleTravelSolutions (lTravelSolutionList);
stdairService.buildSampleBookingRequest();
const std::string& lCSVDump =
stdairService.csvDisplay (lTravelSolutionList);
} else {
assert (isBuiltin == true);
stdairService.buildSampleBom();
}
} else {
<< " and build the corresponding BOM tree.");
}
const std::string& lCSVDump = stdairService.csvDisplay ();
logOutputFile.close();
return 0;
}