12 #include <boost/date_time/posix_time/posix_time.hpp>
13 #include <boost/date_time/gregorian/gregorian.hpp>
14 #include <boost/program_options.hpp>
15 #include <boost/tokenizer.hpp>
16 #include <boost/lexical_cast.hpp>
24 #include <stdair/config/stdair-paths.hpp>
30 const std::string K_STDAIR_DEFAULT_LOG_FILENAME (
"stdair.log");
35 const std::string K_STDAIR_DEFAULT_INPUT_FILENAME (STDAIR_SAMPLE_DIR
42 const bool K_STDAIR_DEFAULT_BUILT_IN_INPUT =
false;
49 const bool K_STDAIR_DEFAULT_BUILT_FOR_RMOL =
false;
56 const bool K_STDAIR_DEFAULT_BUILT_FOR_CRS =
false;
62 const int K_STDAIR_EARLY_RETURN_STATUS = 99;
66 template<
class T> std::ostream&
operator<< (std::ostream& os,
67 const std::vector<T>& v) {
68 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout,
" "));
73 int readConfiguration (
int argc,
char* argv[],
bool& ioIsBuiltin,
74 bool& ioIsForRMOL,
bool& ioIsForCRS,
76 std::string& ioLogFilename) {
78 ioIsBuiltin = K_STDAIR_DEFAULT_BUILT_IN_INPUT;
81 ioIsForRMOL = K_STDAIR_DEFAULT_BUILT_FOR_RMOL;
84 ioIsForCRS = K_STDAIR_DEFAULT_BUILT_FOR_CRS;
87 boost::program_options::options_description
generic (
"Generic options");
89 (
"prefix",
"print installation prefix")
90 (
"version,v",
"print version string")
91 (
"help,h",
"produce help message");
96 boost::program_options::options_description config (
"Configuration");
99 "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")
101 "Build a sample BOM tree for RMOL (i.e., a dummy flight-date with a single leg-cabin)")
103 "Build a sample BOM tree for CRS")
105 boost::program_options::value< std::string >(&ioInputFilename)->default_value(K_STDAIR_DEFAULT_INPUT_FILENAME),
106 "(CVS) input file for the demand distributions")
108 boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_STDAIR_DEFAULT_LOG_FILENAME),
109 "Filename for the logs")
114 boost::program_options::options_description hidden (
"Hidden options");
117 boost::program_options::value< std::vector<std::string> >(),
118 "Show the copyright (license)");
120 boost::program_options::options_description cmdline_options;
121 cmdline_options.add(
generic).add(config).add(hidden);
123 boost::program_options::options_description config_file_options;
124 config_file_options.add(config).add(hidden);
125 boost::program_options::options_description visible (
"Allowed options");
126 visible.add(
generic).add(config);
128 boost::program_options::positional_options_description p;
129 p.add (
"copyright", -1);
131 boost::program_options::variables_map vm;
132 boost::program_options::
133 store (boost::program_options::command_line_parser (argc, argv).
134 options (cmdline_options).positional(p).run(), vm);
136 std::ifstream ifs (
"stdair.cfg");
137 boost::program_options::store (parse_config_file (ifs, config_file_options),
139 boost::program_options::notify (vm);
141 if (vm.count (
"help")) {
142 std::cout << visible << std::endl;
143 return K_STDAIR_EARLY_RETURN_STATUS;
146 if (vm.count (
"version")) {
147 std::cout << PACKAGE_NAME <<
", version " << PACKAGE_VERSION << std::endl;
148 return K_STDAIR_EARLY_RETURN_STATUS;
151 if (vm.count (
"prefix")) {
152 std::cout <<
"Installation prefix: " << PREFIXDIR << std::endl;
153 return K_STDAIR_EARLY_RETURN_STATUS;
156 if (vm.count (
"builtin")) {
160 if (vm.count (
"rmol")) {
167 if (vm.count (
"crs")) {
174 const std::string isBuiltinStr = (ioIsBuiltin ==
true)?
"yes":
"no";
175 std::cout <<
"The BOM should be built-in? " << isBuiltinStr << std::endl;
177 const std::string isForRMOLStr = (ioIsForRMOL ==
true)?
"yes":
"no";
178 std::cout <<
"The BOM should be built-in for RMOL? " << isForRMOLStr
181 const std::string isForCRSStr = (ioIsForCRS ==
true)?
"yes":
"no";
182 std::cout <<
"The BOM should be built-in for CRS? " << isForCRSStr
185 if (ioIsBuiltin ==
false && ioIsForRMOL ==
false && ioIsForCRS ==
false) {
186 if (vm.count (
"input")) {
187 ioInputFilename = vm[
"input"].as< std::string >();
188 std::cout <<
"Input filename is: " << ioInputFilename << std::endl;
191 std::cerr <<
"Either one among the -b/--builtin, -r/--rmol, -c/--crs "
192 <<
"or -i/--input options must be specified" << std::endl;
196 if (vm.count (
"log")) {
197 ioLogFilename = vm[
"log"].as< std::string >();
198 std::cout <<
"Log filename is: " << ioLogFilename << std::endl;
206 int main (
int argc,
char* argv[]) {
222 std::string lLogFilename;
225 const int lOptionParserStatus =
226 readConfiguration (argc, argv, isBuiltin, isForRMOL, isForCRS,
227 lInputFilename, lLogFilename);
229 if (lOptionParserStatus == K_STDAIR_EARLY_RETURN_STATUS) {
234 std::ofstream logOutputFile;
236 logOutputFile.open (lLogFilename.c_str());
237 logOutputFile.clear();
246 if (isBuiltin ==
true || isForRMOL ==
true || isForCRS ==
true) {
248 if (isForRMOL ==
true) {
250 stdairService.buildDummyInventory (300);
252 }
else if (isForCRS ==
true) {
255 stdairService.buildSampleTravelSolutions (lTravelSolutionList);
259 stdairService.buildSampleBookingRequest();
264 const std::string& lCSVDump =
265 stdairService.csvDisplay (lTravelSolutionList);
269 assert (isBuiltin ==
true);
272 stdairService.buildSampleBom();
281 <<
" and build the corresponding BOM tree.");
285 const std::string& lCSVDump = stdairService.csvDisplay ();
289 logOutputFile.close();