6 #include <boost/program_options.hpp>
8 #include <stdair/stdair_basic_types.hpp>
9 #include <stdair/basic/BasLogParams.hpp>
10 #include <stdair/basic/BasDBParams.hpp>
11 #include <stdair/basic/BasFileMgr.hpp>
12 #include <stdair/bom/TravelSolutionStruct.hpp>
13 #include <stdair/bom/BookingRequestStruct.hpp>
14 #include <stdair/service/Logger.hpp>
16 #include <simfqt/SIMFQT_Types.hpp>
69 template<
class T> std::ostream&
operator<< (std::ostream& os,
70 const std::vector<T>& v) {
71 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout,
" "));
81 stdair::Filename_T& ioScheduleInputFilename,
82 stdair::Filename_T& ioOnDInputFilename,
83 stdair::Filename_T& ioYieldInputFilename,
84 stdair::Filename_T& ioFareInputFilename,
85 stdair::Filename_T& ioLogFilename,
86 std::string& ioDBUser, std::string& ioDBPasswd,
87 std::string& ioDBHost, std::string& ioDBPort,
88 std::string& ioDBDBName) {
93 boost::program_options::options_description
generic (
"Generic options");
95 (
"prefix",
"print installation prefix")
96 (
"version,v",
"print version string")
97 (
"help,h",
"produce help message");
101 boost::program_options::options_description config (
"Configuration");
104 "The sample BOM tree can be either built-in or parsed from input files. In that latter case, the input files must be specified as well (e.g., -s/--schedule, -o/--ond, -f/--fare, -y/--yield)")
107 "(CVS) input file for the schedules")
110 "(CVS) input file for the O&D definitions")
113 "(CVS) input file for the yields")
116 "(CVS) input file for the fares")
119 "Filepath for the logs")
122 "SQL database username")
125 "SQL database password")
128 "SQL database hostname")
139 boost::program_options::options_description hidden (
"Hidden options");
142 boost::program_options::value< std::vector<std::string> >(),
143 "Show the copyright (license)");
145 boost::program_options::options_description cmdline_options;
146 cmdline_options.add(
generic).add(config).add(hidden);
148 boost::program_options::options_description config_file_options;
149 config_file_options.add(config).add(hidden);
151 boost::program_options::options_description visible (
"Allowed options");
152 visible.add(
generic).add(config);
154 boost::program_options::positional_options_description p;
155 p.add (
"copyright", -1);
157 boost::program_options::variables_map vm;
158 boost::program_options::
159 store (boost::program_options::command_line_parser (argc, argv).
160 options (cmdline_options).positional(p).run(), vm);
162 std::ifstream ifs (
"simcrs.cfg");
163 boost::program_options::store (parse_config_file (ifs, config_file_options),
165 boost::program_options::notify (vm);
167 if (vm.count (
"help")) {
168 std::cout << visible << std::endl;
172 if (vm.count (
"version")) {
177 if (vm.count (
"prefix")) {
178 std::cout <<
"Installation prefix: " <<
PREFIXDIR << std::endl;
182 if (vm.count (
"builtin")) {
185 const std::string isBuiltinStr = (ioIsBuiltin ==
true)?
"yes":
"no";
186 std::cout <<
"The BOM should be built-in? " << isBuiltinStr << std::endl;
189 std::ostringstream oErrorMessageStr;
190 oErrorMessageStr <<
"Either the -b/--builtin option, or the combination of "
191 <<
"the -s/--schedule, -o/--ond, -f/--fare and -y/--yield "
192 <<
"options must be specified";
194 if (ioIsBuiltin ==
false) {
195 if (vm.count (
"schedule")) {
196 ioScheduleInputFilename = vm[
"schedule"].as< std::string >();
197 std::cout <<
"Schedule input filename is: " << ioScheduleInputFilename
203 std::cerr << oErrorMessageStr.str() << std::endl;
206 if (vm.count (
"ond")) {
207 ioOnDInputFilename = vm[
"ond"].as< std::string >();
208 std::cout <<
"O&D input filename is: " << ioOnDInputFilename << std::endl;
213 std::cerr << oErrorMessageStr.str() << std::endl;
216 if (vm.count (
"yield")) {
217 ioYieldInputFilename = vm[
"yield"].as< std::string >();
218 std::cout <<
"Yield input filename is: " << ioYieldInputFilename
224 std::cerr << oErrorMessageStr.str() << std::endl;
227 if (vm.count (
"fare")) {
228 ioFareInputFilename = vm[
"fare"].as< std::string >();
229 std::cout <<
"Fare input filename is: " << ioFareInputFilename
235 std::cerr << oErrorMessageStr.str() << std::endl;
239 if (vm.count (
"log")) {
240 ioLogFilename = vm[
"log"].as< std::string >();
241 std::cout <<
"Log filename is: " << ioLogFilename << std::endl;
244 if (vm.count (
"user")) {
245 ioDBUser = vm[
"user"].as< std::string >();
246 std::cout <<
"SQL database user name is: " << ioDBUser << std::endl;
249 if (vm.count (
"passwd")) {
250 ioDBPasswd = vm[
"passwd"].as< std::string >();
254 if (vm.count (
"host")) {
255 ioDBHost = vm[
"host"].as< std::string >();
256 std::cout <<
"SQL database host name is: " << ioDBHost << std::endl;
259 if (vm.count (
"port")) {
260 ioDBPort = vm[
"port"].as< std::string >();
261 std::cout <<
"SQL database port number is: " << ioDBPort << std::endl;
264 if (vm.count (
"dbname")) {
265 ioDBDBName = vm[
"dbname"].as< std::string >();
266 std::cout <<
"SQL database name is: " << ioDBDBName << std::endl;
273 int main (
int argc,
char* argv[]) {
280 stdair::Filename_T lScheduleInputFilename;
283 stdair::Filename_T lOnDInputFilename;
286 stdair::Filename_T lYieldInputFilename;
289 stdair::Filename_T lFareInputFilename;
292 stdair::Filename_T lLogFilename;
296 std::string lDBPasswd;
299 std::string lDBDBName;
305 const int lOptionParserStatus =
307 lScheduleInputFilename, lOnDInputFilename,
308 lYieldInputFilename, lFareInputFilename, lLogFilename,
309 lDBUser, lDBPasswd, lDBHost, lDBPort, lDBDBName);
316 const stdair::BasDBParams lDBParams (lDBUser, lDBPasswd, lDBHost, lDBPort,
320 std::ofstream logOutputFile;
322 logOutputFile.open (lLogFilename.c_str());
323 logOutputFile.clear();
326 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
330 if (isBuiltin ==
true) {
337 const SIMFQT::FareFilePath lFareFilePath (lFareInputFilename);
338 const AIRRAC::YieldFilePath lYieldFilePath (lYieldInputFilename);
339 simcrsService.
parseAndLoad (lScheduleInputFilename, lOnDInputFilename,
340 lYieldFilePath, lFareFilePath);
346 const bool isForCRS =
true;
347 const stdair::BookingRequestStruct& lBookingRequest =
351 stdair::TravelSolutionList_T lTravelSolutionList =
355 if (lTravelSolutionList.empty() ==
true) {
356 STDAIR_LOG_ERROR (
"No travel solution has been found for: "
357 << lBookingRequest.display());
362 simcrsService.
fareQuote (lBookingRequest, lTravelSolutionList);
365 stdair::TravelSolutionStruct& lChosenTravelSolution =
366 lTravelSolutionList.front();
369 const stdair::KeyList_T& lsegmentDateKeyList =
370 lChosenTravelSolution.getSegmentPath();
372 const stdair::FareOptionList_T& lFareOptionList =
373 lChosenTravelSolution.getFareOptionList();
376 if (lFareOptionList.empty() ==
true) {
377 STDAIR_LOG_ERROR (
"No fare option for the chosen travel solution: "
378 << lChosenTravelSolution.display());
383 const stdair::FareOptionStruct& lFareOption = lFareOptionList.front();
384 lChosenTravelSolution.setChosenFareOption (lFareOption);
387 const std::string& lSegmentDateKey = lsegmentDateKeyList.front();
388 STDAIR_LOG_DEBUG (
"The chosen travel solution is: " << lSegmentDateKey
389 <<
", the fare is: " << lFareOption.getFare() <<
" Euros.");
392 const stdair::PartySize_T lPartySize (3);
393 const bool isSellSuccessful =
394 simcrsService.
sell (lChosenTravelSolution, lPartySize);
397 STDAIR_LOG_DEBUG (
"Sale ('" << lBookingRequest <<
"'): "
398 <<
" successful? " << isSellSuccessful);
401 const std::string& lCSVDump = simcrsService.
csvDisplay();
402 STDAIR_LOG_DEBUG (lCSVDump);
405 logOutputFile.close();