Go to the documentation of this file.00001
00002 #include <cassert>
00003 #include <iostream>
00004 #include <sstream>
00005 #include <fstream>
00006 #include <vector>
00007 #include <list>
00008 #include <string>
00009
00010 #include <boost/date_time/posix_time/posix_time.hpp>
00011 #include <boost/date_time/gregorian/gregorian.hpp>
00012 #include <boost/tokenizer.hpp>
00013 #include <boost/program_options.hpp>
00014
00015 #include <stdair/STDAIR_Service.hpp>
00016 #include <stdair/bom/TravelSolutionStruct.hpp>
00017 #include <stdair/service/Logger.hpp>
00018
00019 #include <airrac/AIRRAC_Service.hpp>
00020 #include <airrac/config/airrac-paths.hpp>
00021
00022
00023 typedef std::vector<std::string> WordList_T;
00024
00025
00026
00028 const std::string K_AIRRAC_DEFAULT_LOG_FILENAME ("airrac.log");
00029
00031 const std::string K_AIRRAC_DEFAULT_YIELD_INPUT_FILENAME (STDAIR_SAMPLE_DIR
00032 "/yieldstore01.csv");
00033
00036 const bool K_AIRRAC_DEFAULT_BUILT_IN_INPUT = false;
00037
00039 const int K_AIRRAC_EARLY_RETURN_STATUS = 99;
00040
00041
00042
00043 template<class T> std::ostream& operator<< (std::ostream& os,
00044 const std::vector<T>& v) {
00045 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout, " "));
00046 return os;
00047 }
00048
00050 int readConfiguration (int argc, char* argv[], bool& ioIsBuiltin,
00051 stdair::Filename_T& ioYieldInputFilename,
00052 std::string& ioLogFilename) {
00053
00054
00055 ioIsBuiltin = K_AIRRAC_DEFAULT_BUILT_IN_INPUT;
00056
00057
00058 boost::program_options::options_description generic ("Generic options");
00059 generic.add_options()
00060 ("prefix", "print installation prefix")
00061 ("version,v", "print version string")
00062 ("help,h", "produce help message");
00063
00064
00065
00066 boost::program_options::options_description config ("Configuration");
00067 config.add_options()
00068 ("builtin,b",
00069 "The sample BOM tree can be either built-in or parsed from an input file. That latter must then be given with the -y/--yield option")
00070 ("yield,y",
00071 boost::program_options::value< std::string >(&ioYieldInputFilename)->default_value(K_AIRRAC_DEFAULT_YIELD_INPUT_FILENAME),
00072 "(CSV) input file for the yield rules")
00073 ("log,l",
00074 boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_AIRRAC_DEFAULT_LOG_FILENAME),
00075 "Filename for the logs")
00076 ;
00077
00078
00079
00080 boost::program_options::options_description hidden ("Hidden options");
00081 hidden.add_options()
00082 ("copyright",
00083 boost::program_options::value< std::vector<std::string> >(),
00084 "Show the copyright (license)");
00085
00086 boost::program_options::options_description cmdline_options;
00087 cmdline_options.add(generic).add(config).add(hidden);
00088
00089 boost::program_options::options_description config_file_options;
00090 config_file_options.add(config).add(hidden);
00091
00092 boost::program_options::options_description visible ("Allowed options");
00093 visible.add(generic).add(config);
00094
00095 boost::program_options::positional_options_description p;
00096 p.add ("copyright", -1);
00097
00098 boost::program_options::variables_map vm;
00099 boost::program_options::
00100 store (boost::program_options::command_line_parser (argc, argv).
00101 options (cmdline_options).positional(p).run(), vm);
00102
00103 std::ifstream ifs ("airrac.cfg");
00104 boost::program_options::store (parse_config_file (ifs, config_file_options),
00105 vm);
00106 boost::program_options::notify (vm); if (vm.count ("help")) {
00107 std::cout << visible << std::endl;
00108 return K_AIRRAC_EARLY_RETURN_STATUS;
00109 }
00110
00111 if (vm.count ("version")) {
00112 std::cout << PACKAGE_NAME << ", version " << PACKAGE_VERSION << std::endl;
00113 return K_AIRRAC_EARLY_RETURN_STATUS;
00114 }
00115
00116 if (vm.count ("prefix")) {
00117 std::cout << "Installation prefix: " << PREFIXDIR << std::endl;
00118 return K_AIRRAC_EARLY_RETURN_STATUS;
00119 }
00120
00121 if (vm.count ("builtin")) {
00122 ioIsBuiltin = true;
00123 }
00124 const std::string isBuiltinStr = (ioIsBuiltin == true)?"yes":"no";
00125 std::cout << "The BOM should be built-in? " << isBuiltinStr << std::endl;
00126
00127 if (ioIsBuiltin == false) {
00128
00129
00130 if (vm.count ("yield")) {
00131 ioYieldInputFilename = vm["yield"].as< std::string >();
00132 std::cout << "Input yield filename is: " << ioYieldInputFilename
00133 << std::endl;
00134
00135 } else {
00136
00137
00138 std::cerr << "Either one among the -b/--builtin and -y/--yield "
00139 << "options must be specified" << std::endl;
00140 }
00141 }
00142
00143 if (vm.count ("log")) {
00144 ioLogFilename = vm["log"].as< std::string >();
00145 std::cout << "Log filename is: " << ioLogFilename << std::endl;
00146 }
00147
00148 return 0;
00149 }
00150
00151
00152
00153 int main (int argc, char* argv[]) {
00154
00155
00156 bool isBuiltin;
00157
00158
00159 stdair::Filename_T lYieldInputFilename;
00160
00161
00162 stdair::Filename_T lLogFilename;
00163
00164
00165 const int lOptionParserStatus =
00166 readConfiguration (argc, argv, isBuiltin, lYieldInputFilename, lLogFilename);
00167
00168 if (lOptionParserStatus == K_AIRRAC_EARLY_RETURN_STATUS) {
00169 return 0;
00170 }
00171
00172
00173 std::ofstream logOutputFile;
00174
00175 logOutputFile.open (lLogFilename.c_str());
00176 logOutputFile.clear();
00177
00178
00179 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00180
00181 AIRRAC::AIRRAC_Service airracService (lLogParams);
00182
00183
00184 STDAIR_LOG_DEBUG ("Welcome to AirRAC");
00185
00186
00187 stdair::TravelSolutionList_T lTravelSolutionList;
00188 airracService.buildSampleTravelSolutions (lTravelSolutionList);
00189
00190
00191 if (isBuiltin == true) {
00192
00193
00194 airracService.buildSampleBom();
00195
00196 } else {
00197
00198
00199 airracService.parseAndLoad (lYieldInputFilename);
00200
00201 }
00202
00203
00204 const std::string& lBOMCSVDump = airracService.csvDisplay();
00205 STDAIR_LOG_DEBUG ("BOM tree: " << lBOMCSVDump);
00206
00207
00208 const std::string& lTSCSVDump =
00209 airracService.csvDisplay (lTravelSolutionList);
00210 STDAIR_LOG_DEBUG (lTSCSVDump);
00211
00212
00213 logOutputFile.close();
00214
00215
00216
00217
00218
00219
00220
00221
00222 return 0;
00223 }