12 #include <boost/program_options.hpp>
14 #include <stdair/basic/BasLogParams.hpp>
15 #include <stdair/basic/BasDBParams.hpp>
16 #include <stdair/bom/BookingRequestStruct.hpp>
17 #include <stdair/bom/TravelSolutionStruct.hpp>
18 #include <stdair/service/Logger.hpp>
21 #include <travelccm/config/travelccm-paths.hpp>
27 const std::string K_TRAVELCCM_DEFAULT_LOG_FILENAME (
"travelccm.log");
39 const bool K_TRAVELCCM_DEFAULT_BUILT_IN_INPUT =
false;
44 const int K_TRAVELCCM_EARLY_RETURN_STATUS = 99;
49 template<
class T> std::ostream& operator<< (std::ostream& os,
50 const std::vector<T>& v) {
51 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout,
" "));
58 int readConfiguration (
int argc,
char* argv[],
bool& ioIsBuiltin,
59 stdair::Filename_T& lInputFilename,
60 stdair::Filename_T& lLogFilename) {
63 ioIsBuiltin = K_TRAVELCCM_DEFAULT_BUILT_IN_INPUT;
66 boost::program_options::options_description
generic (
"Generic options");
68 (
"prefix",
"print installation prefix")
69 (
"version,v",
"print version string")
70 (
"help,h",
"produce help message");
74 boost::program_options::options_description config (
"Configuration");
77 "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")
79 boost::program_options::value< std::string >(&lInputFilename)->default_value(K_TRAVELCCM_DEFAULT_INPUT_FILENAME),
80 "(CSV) input file for the customer choice rule sets")
82 boost::program_options::value< std::string >(&lLogFilename)->default_value(K_TRAVELCCM_DEFAULT_LOG_FILENAME),
83 "Filename for the logs")
88 boost::program_options::options_description hidden (
"Hidden options");
91 boost::program_options::value< std::vector<std::string> >(),
92 "Show the copyright (license)");
94 boost::program_options::options_description cmdline_options;
95 cmdline_options.add(
generic).add(config).add(hidden);
97 boost::program_options::options_description config_file_options;
98 config_file_options.add(config).add(hidden);
100 boost::program_options::options_description visible (
"Allowed options");
101 visible.add(
generic).add(config);
103 boost::program_options::positional_options_description p;
104 p.add (
"copyright", -1);
106 boost::program_options::variables_map vm;
107 boost::program_options::
108 store (boost::program_options::command_line_parser (argc, argv).
109 options (cmdline_options).positional(p).run(), vm);
111 std::ifstream ifs (
"travelccm.cfg");
112 boost::program_options::store (parse_config_file (ifs, config_file_options),
114 boost::program_options::notify (vm);
116 if (vm.count (
"help")) {
117 std::cout << visible << std::endl;
118 return K_TRAVELCCM_EARLY_RETURN_STATUS;
121 if (vm.count (
"version")) {
123 return K_TRAVELCCM_EARLY_RETURN_STATUS;
126 if (vm.count (
"prefix")) {
127 std::cout <<
"Installation prefix: " <<
PREFIXDIR << std::endl;
128 return K_TRAVELCCM_EARLY_RETURN_STATUS;
131 if (vm.count (
"builtin")) {
134 const std::string isBuiltinStr = (ioIsBuiltin ==
true)?
"yes":
"no";
135 std::cout <<
"The BOM should be built-in? " << isBuiltinStr << std::endl;
137 if (ioIsBuiltin ==
false) {
140 if (vm.count (
"input")) {
141 lInputFilename = vm[
"input"].as< std::string >();
142 std::cout <<
"Input filename is: " << lInputFilename << std::endl;
147 std::cerr <<
"Either one among the -b/--builtin and -i/--input "
148 <<
"options must be specified" << std::endl;
152 if (vm.count (
"log")) {
153 lLogFilename = vm[
"log"].as< std::string >();
154 std::cout <<
"Log filename is: " << lLogFilename << std::endl;
162 int main (
int argc,
char* argv[]) {
168 stdair::Filename_T lInputFilename;
171 stdair::Filename_T lLogFilename;
174 const int lOptionParserStatus =
175 readConfiguration (argc, argv, isBuiltin, lInputFilename, lLogFilename);
177 if (lOptionParserStatus == K_TRAVELCCM_EARLY_RETURN_STATUS) {
182 std::ofstream logOutputFile;
184 logOutputFile.open (lLogFilename.c_str());
185 logOutputFile.clear();
188 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
194 STDAIR_LOG_DEBUG (
"Welcome to TravelCCM");
197 if (isBuiltin ==
true) {
200 travelccmService.buildSampleBom();
213 const stdair::BookingRequestStruct& lBookingRequest =
214 travelccmService.buildSampleBookingRequest();
217 STDAIR_LOG_DEBUG (
"Booking request: " << lBookingRequest.display());
220 stdair::TravelSolutionList_T lTSList;
221 travelccmService.buildSampleTravelSolutions (lTSList);
224 const std::string& lCSVDump = travelccmService.csvDisplay (lTSList);
225 STDAIR_LOG_DEBUG (lCSVDump);
228 const stdair::TravelSolutionStruct* lTS_ptr =
229 travelccmService.chooseTravelSolution (lTSList, lBookingRequest);
231 if (lTS_ptr != NULL) {
233 STDAIR_LOG_DEBUG (
"Chosen travel solution: " << lTS_ptr->display());
237 STDAIR_LOG_DEBUG (
"No travel solution can be found for "
238 << lBookingRequest.display()
239 <<
" within the following list of travel solutions");
240 STDAIR_LOG_DEBUG (lCSVDump);
244 logOutputFile.close();