12 #include <boost/program_options.hpp> 
   13 #include <boost/tokenizer.hpp> 
   15 #include <stdair/basic/BasLogParams.hpp> 
   16 #include <stdair/basic/BasDBParams.hpp> 
   17 #include <stdair/service/Logger.hpp> 
   20 #include <airinv/config/airinv-paths.hpp> 
   26 const std::string K_AIRINV_DEFAULT_LOG_FILENAME (
"airinv_parseInventory.log");
 
   51 const std::string K_AIRINV_DEFAULT_FF_DISUTILITY_INPUT_FILENAME (
STDAIR_SAMPLE_DIR 
   63 const std::string K_AIRINV_DEFAULT_SEGMENT_DATE_KEY (
"SV,5,2010-03-11,KBP,JFK");
 
   68 const stdair::ClassCode_T K_AIRINV_DEFAULT_CLASS_CODE (
"Y");
 
   73 const stdair::PartySize_T K_AIRINV_DEFAULT_PARTY_SIZE (2);
 
   79 const bool K_AIRINV_DEFAULT_BUILT_IN_INPUT = 
false;
 
   85 const bool K_AIRINV_DEFAULT_FOR_SCHEDULE = 
false;
 
   90 const int K_AIRINV_EARLY_RETURN_STATUS = 99;
 
   94 template<
class T> std::ostream& 
operator<< (std::ostream& os,
 
   95                                             const std::vector<T>& v) {
 
   96   std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout, 
" ")); 
 
  103 int readConfiguration (
int argc, 
char* argv[],
 
  104                        bool& ioIsBuiltin, 
bool& ioIsForSchedule,
 
  105                        stdair::Filename_T& ioInventoryFilename,
 
  106                        stdair::Filename_T& ioScheduleInputFilename,
 
  107                        stdair::Filename_T& ioODInputFilename,
 
  108                        stdair::Filename_T& ioFRAT5Filename,
 
  109                        stdair::Filename_T& ioFFDisutilityFilename,
 
  110                        stdair::Filename_T& ioYieldInputFilename,
 
  111                        std::string& ioSegmentDateKey,
 
  112                        stdair::ClassCode_T& ioClassCode,
 
  113                        stdair::PartySize_T& ioPartySize,
 
  114                        std::string& ioLogFilename) {
 
  116   ioIsBuiltin = K_AIRINV_DEFAULT_BUILT_IN_INPUT;
 
  119   ioIsForSchedule = K_AIRINV_DEFAULT_FOR_SCHEDULE;
 
  122   boost::program_options::options_description 
generic (
"Generic options");
 
  123   generic.add_options()
 
  124     (
"prefix", 
"print installation prefix")
 
  125     (
"version,v", 
"print version string")
 
  126     (
"help,h", 
"produce help message");
 
  131   boost::program_options::options_description config (
"Configuration");
 
  134      "The sample BOM tree can be either built-in or parsed from an input file. That latter must then be given with the -i/--inventory or -s/--schedule option")
 
  136      "The BOM tree should be built from a schedule file (instead of from an inventory dump)")
 
  138      boost::program_options::value< std::string >(&ioInventoryFilename)->default_value(K_AIRINV_DEFAULT_INVENTORY_FILENAME),
 
  139      "(CSV) input file for the inventory")
 
  141      boost::program_options::value< std::string >(&ioScheduleInputFilename)->default_value(K_AIRINV_DEFAULT_SCHEDULE_FILENAME),
 
  142      "(CSV) input file for the schedule")
 
  144      boost::program_options::value< std::string >(&ioODInputFilename)->default_value(K_AIRINV_DEFAULT_OND_FILENAME),
 
  145      "(CSV) input file for the O&D")
 
  147      boost::program_options::value< std::string >(&ioFRAT5Filename)->default_value(K_AIRINV_DEFAULT_FRAT5_INPUT_FILENAME),
 
  148      "(CSV) input file for the FRAT5 Curve")
 
  150      boost::program_options::value< std::string >(&ioFFDisutilityFilename)->default_value(K_AIRINV_DEFAULT_FF_DISUTILITY_INPUT_FILENAME),
 
  151      "(CSV) input file for the FF disutility Curve")
 
  153      boost::program_options::value< std::string >(&ioYieldInputFilename)->default_value(K_AIRINV_DEFAULT_YIELD_FILENAME),
 
  154      "(CSV) input file for the yield")
 
  155     (
"segment_date_key,k",
 
  156      boost::program_options::value< std::string >(&ioSegmentDateKey)->default_value(K_AIRINV_DEFAULT_SEGMENT_DATE_KEY),
 
  159      boost::program_options::value< stdair::ClassCode_T >(&ioClassCode)->default_value(K_AIRINV_DEFAULT_CLASS_CODE),
 
  162      boost::program_options::value< stdair::PartySize_T >(&ioPartySize)->default_value(K_AIRINV_DEFAULT_PARTY_SIZE),
 
  165      boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_AIRINV_DEFAULT_LOG_FILENAME),
 
  166      "Filename for the logs")
 
  171   boost::program_options::options_description hidden (
"Hidden options");
 
  174      boost::program_options::value< std::vector<std::string> >(),
 
  175      "Show the copyright (license)");
 
  177   boost::program_options::options_description cmdline_options;
 
  178   cmdline_options.add(
generic).add(config).add(hidden);
 
  180   boost::program_options::options_description config_file_options;
 
  181   config_file_options.add(config).add(hidden);
 
  182   boost::program_options::options_description visible (
"Allowed options");
 
  183   visible.add(
generic).add(config);
 
  185   boost::program_options::positional_options_description p;
 
  186   p.add (
"copyright", -1);
 
  188   boost::program_options::variables_map vm;
 
  189   boost::program_options::
 
  190     store (boost::program_options::command_line_parser (argc, argv).
 
  191            options (cmdline_options).positional(p).run(), vm);
 
  193   std::ifstream ifs (
"airinv.cfg");
 
  194   boost::program_options::store (parse_config_file (ifs, config_file_options),
 
  196   boost::program_options::notify (vm);
 
  198   if (vm.count (
"help")) {
 
  199     std::cout << visible << std::endl;
 
  200     return K_AIRINV_EARLY_RETURN_STATUS;
 
  203   if (vm.count (
"version")) {
 
  205     return K_AIRINV_EARLY_RETURN_STATUS;
 
  208   if (vm.count (
"prefix")) {
 
  209     std::cout << 
"Installation prefix: " << 
PREFIXDIR << std::endl;
 
  210     return K_AIRINV_EARLY_RETURN_STATUS;
 
  213   if (vm.count (
"builtin")) {
 
  216   const std::string isBuiltinStr = (ioIsBuiltin == 
true)?
"yes":
"no";
 
  217   std::cout << 
"The BOM should be built-in? " << isBuiltinStr << std::endl;
 
  219   if (vm.count (
"for_schedule")) {
 
  220     ioIsForSchedule = 
true;
 
  222   const std::string isForScheduleStr = (ioIsForSchedule == 
true)?
"yes":
"no";
 
  223   std::cout << 
"The BOM should be built from schedule? " << isForScheduleStr
 
  226   if (ioIsBuiltin == 
false) {
 
  228     if (ioIsForSchedule == 
false) {
 
  230       if (vm.count (
"inventory")) {
 
  231         ioInventoryFilename = vm[
"inventory"].as< std::string >();
 
  232         std::cout << 
"Input inventory filename is: " << ioInventoryFilename
 
  238         std::cerr << 
"Either one among the -b/--builtin, -i/--inventory or " 
  239                   << 
" -f/--for_schedule and -s/--schedule options " 
  240                   << 
"must be specified" << std::endl;
 
  245       if (vm.count (
"schedule")) {
 
  246         ioScheduleInputFilename = vm[
"schedule"].as< std::string >();
 
  247         std::cout << 
"Input schedule filename is: " << ioScheduleInputFilename
 
  253         std::cerr << 
"Either one among the -b/--builtin, -i/--inventory or " 
  254                   << 
" -f/--for_schedule and -s/--schedule options " 
  255                   << 
"must be specified" << std::endl;
 
  258       if (vm.count (
"ond")) {
 
  259         ioODInputFilename = vm[
"ond"].as< std::string >();
 
  260         std::cout << 
"Input O&D filename is: " << ioODInputFilename << std::endl;
 
  263       if (vm.count (
"frat5")) {
 
  264         ioFRAT5Filename = vm[
"frat5"].as< std::string >();
 
  265         std::cout << 
"FRAT5 input filename is: " << ioFRAT5Filename << std::endl;
 
  269       if (vm.count (
"ff_disutility")) {
 
  270         ioFFDisutilityFilename = vm[
"ff_disutility"].as< std::string >();
 
  271         std::cout << 
"FF disutility input filename is: " 
  272                   << ioFFDisutilityFilename << std::endl;
 
  276       if (vm.count (
"yield")) {
 
  277         ioYieldInputFilename = vm[
"yield"].as< std::string >();
 
  278         std::cout << 
"Input yield filename is: " 
  279                   << ioYieldInputFilename << std::endl;
 
  284   if (vm.count (
"log")) {
 
  285     ioLogFilename = vm[
"log"].as< std::string >();
 
  286     std::cout << 
"Log filename is: " << ioLogFilename << std::endl;
 
  294 int main (
int argc, 
char* argv[]) {
 
  302   stdair::Filename_T lInventoryFilename;
 
  303   stdair::Filename_T lScheduleInputFilename;
 
  304   stdair::Filename_T lODInputFilename;
 
  305   stdair::Filename_T lFRAT5InputFilename;
 
  306   stdair::Filename_T lFFDisutilityInputFilename;
 
  307   stdair::Filename_T lYieldInputFilename;
 
  310   std::string lSegmentDateKey;
 
  311   stdair::ClassCode_T lClassCode;
 
  312   stdair::PartySize_T lPartySize;
 
  315   stdair::Filename_T lLogFilename;
 
  318   const int lOptionParserStatus =
 
  319     readConfiguration (argc, argv, isBuiltin, isForSchedule, lInventoryFilename,
 
  320                        lScheduleInputFilename, lODInputFilename,
 
  321                        lFRAT5InputFilename, lFFDisutilityInputFilename,
 
  322                        lYieldInputFilename, lSegmentDateKey, lClassCode,
 
  323                        lPartySize, lLogFilename);
 
  325   if (lOptionParserStatus == K_AIRINV_EARLY_RETURN_STATUS) {
 
  330   std::ofstream logOutputFile;
 
  332   logOutputFile.open (lLogFilename.c_str());
 
  333   logOutputFile.clear();
 
  336   const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
 
  340   STDAIR_LOG_DEBUG (
"Welcome to AirInv");
 
  343   if (isBuiltin == 
true) {
 
  346     airinvService.buildSampleBom();
 
  349     lSegmentDateKey = 
"BA,9,2011-06-10,LHR,SYD";
 
  352     if (isForSchedule == 
true) {
 
  354       stdair::ScheduleFilePath lScheduleFilePath (lScheduleInputFilename);
 
  355       stdair::ODFilePath lODFilePath (lODInputFilename);
 
  356       stdair::FRAT5FilePath lFRAT5FilePath (lFRAT5InputFilename);
 
  357       stdair::FFDisutilityFilePath lFFDisutilityFilePath (lFFDisutilityInputFilename);
 
  358       AIRRAC::YieldFilePath lYieldFilePath (lYieldInputFilename);
 
  359       airinvService.parseAndLoad (lScheduleFilePath, lODFilePath,
 
  360                                   lFRAT5FilePath, lFFDisutilityFilePath,
 
  363       if (lSegmentDateKey == K_AIRINV_DEFAULT_SEGMENT_DATE_KEY) {
 
  365         lSegmentDateKey = 
"SQ,11,2010-01-15,SIN,BKK";
 
  371       airinvService.parseAndLoad (lInventoryFilePath);
 
  376   const bool isSellSuccessful =
 
  377     airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
 
  380   STDAIR_LOG_DEBUG (
"Sale ('" << lSegmentDateKey << 
"', " << lClassCode << 
": " 
  381                     << lPartySize << 
") successful? " << isSellSuccessful);
 
  384   const std::string& lCSVDump = airinvService.csvDisplay();
 
  385   STDAIR_LOG_DEBUG (lCSVDump);
 
  388   logOutputFile.close();