Go to the documentation of this file.00001
00005
00006 #include <cassert>
00007 #include <iostream>
00008 #include <sstream>
00009 #include <fstream>
00010 #include <string>
00011
00012 #include <boost/program_options.hpp>
00013
00014 #include <stdair/basic/BasLogParams.hpp>
00015 #include <stdair/basic/BasDBParams.hpp>
00016 #include <stdair/bom/BookingRequestStruct.hpp>
00017 #include <stdair/bom/TravelSolutionStruct.hpp>
00018 #include <stdair/service/Logger.hpp>
00019
00020 #include <travelccm/TRAVELCCM_Service.hpp>
00021 #include <travelccm/config/travelccm-paths.hpp>
00022
00023
00025 const std::string K_TRAVELCCM_DEFAULT_LOG_FILENAME ("travelccm.log");
00026
00028 const std::string K_TRAVELCCM_DEFAULT_INPUT_FILENAME (STDAIR_SAMPLE_DIR
00029 "/ccm_01.csv");
00030
00031
00032
00033
00034 template<class T> std::ostream& operator<< (std::ostream& os,
00035 const std::vector<T>& v) {
00036 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout, " "));
00037 return os;
00038 }
00039
00041 const int K_TRAVELCCM_EARLY_RETURN_STATUS = 99;
00042
00044 int readConfiguration (int argc, char* argv[], std::string& lInputFilename,
00045 std::string& lLogFilename) {
00046
00047
00048
00049 boost::program_options::options_description generic ("Generic options");
00050 generic.add_options()
00051 ("prefix", "print installation prefix")
00052 ("version,v", "print version string")
00053 ("help,h", "produce help message");
00054
00055
00056
00057 boost::program_options::options_description config ("Configuration");
00058 config.add_options()
00059 ("input,i",
00060 boost::program_options::value< std::string >(&lInputFilename)->default_value(K_TRAVELCCM_DEFAULT_INPUT_FILENAME),
00061 "(CVS) input file for customer choice")
00062 ("log,l",
00063 boost::program_options::value< std::string >(&lLogFilename)->default_value(K_TRAVELCCM_DEFAULT_LOG_FILENAME),
00064 "Filename for the logs")
00065 ;
00066
00067
00068
00069 boost::program_options::options_description hidden ("Hidden options");
00070 hidden.add_options()
00071 ("copyright",
00072 boost::program_options::value< std::vector<std::string> >(),
00073 "Show the copyright (license)");
00074
00075 boost::program_options::options_description cmdline_options;
00076 cmdline_options.add(generic).add(config).add(hidden);
00077
00078 boost::program_options::options_description config_file_options;
00079 config_file_options.add(config).add(hidden);
00080
00081 boost::program_options::options_description visible ("Allowed options");
00082 visible.add(generic).add(config);
00083
00084 boost::program_options::positional_options_description p;
00085 p.add ("copyright", -1);
00086
00087 boost::program_options::variables_map vm;
00088 boost::program_options::
00089 store (boost::program_options::command_line_parser (argc, argv).
00090 options (cmdline_options).positional(p).run(), vm);
00091
00092 std::ifstream ifs ("travelccm.cfg");
00093 boost::program_options::store (parse_config_file (ifs, config_file_options),
00094 vm);
00095 boost::program_options::notify (vm);
00096
00097 if (vm.count ("help")) {
00098 std::cout << visible << std::endl;
00099 return K_TRAVELCCM_EARLY_RETURN_STATUS;
00100 }
00101
00102 if (vm.count ("version")) {
00103 std::cout << PACKAGE_NAME << ", version " << PACKAGE_VERSION << std::endl;
00104 return K_TRAVELCCM_EARLY_RETURN_STATUS;
00105 }
00106
00107 if (vm.count ("prefix")) {
00108 std::cout << "Installation prefix: " << PREFIXDIR << std::endl;
00109 return K_TRAVELCCM_EARLY_RETURN_STATUS;
00110 }
00111
00112 if (vm.count ("input")) {
00113 lInputFilename = vm["input"].as< std::string >();
00114 std::cout << "Input filename is: " << lInputFilename << std::endl;
00115 }
00116
00117 if (vm.count ("log")) {
00118 lLogFilename = vm["log"].as< std::string >();
00119 std::cout << "Log filename is: " << lLogFilename << std::endl;
00120 }
00121
00122 return 0;
00123 }
00124
00125
00126
00127 int main (int argc, char* argv[]) {
00128
00129
00130 std::string lInputFilename;
00131
00132
00133 std::string lLogFilename;
00134
00135
00136 const int lOptionParserStatus =
00137 readConfiguration (argc, argv, lInputFilename, lLogFilename);
00138
00139 if (lOptionParserStatus == K_TRAVELCCM_EARLY_RETURN_STATUS) {
00140 return 0;
00141 }
00142
00143
00144 std::ofstream logOutputFile;
00145
00146 logOutputFile.open (lLogFilename.c_str());
00147 logOutputFile.clear();
00148
00149
00150 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
00151
00152
00153 TRAVELCCM::TRAVELCCM_Service travelccmService (lLogParams);
00154
00155
00156 STDAIR_LOG_DEBUG ("Welcome to TravelCCM");
00157
00158
00159 const stdair::BookingRequestStruct& lBookingRequest =
00160 travelccmService.buildSampleBookingRequest();
00161
00162
00163 STDAIR_LOG_DEBUG ("Booking request: " << lBookingRequest.display());
00164
00165
00166 stdair::TravelSolutionList_T lTSList;
00167 travelccmService.buildSampleTravelSolutions (lTSList);
00168
00169
00170 const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
00171 STDAIR_LOG_DEBUG (lCSVDump);
00172
00173
00174 const stdair::TravelSolutionStruct* lTS_ptr =
00175 travelccmService.chooseTravelSolution (lTSList, lBookingRequest);
00176
00177 if (lTS_ptr != NULL) {
00178
00179 STDAIR_LOG_DEBUG ("Chosen travel solution: " << lTS_ptr->display());
00180
00181 } else {
00182
00183 STDAIR_LOG_DEBUG ("No travel solution can be found for "
00184 << lBookingRequest.display()
00185 << " within the following list of travel solutions");
00186 STDAIR_LOG_DEBUG (lCSVDump);
00187 }
00188
00189
00190 logOutputFile.close();
00191
00192
00193
00194
00195
00196
00197
00198
00199 return 0;
00200 }