9 #include <boost/date_time/posix_time/posix_time.hpp> 
   10 #include <boost/date_time/gregorian/gregorian.hpp> 
   11 #include <boost/tokenizer.hpp> 
   12 #include <boost/program_options.hpp> 
   14 #include <stdair/stdair_basic_types.hpp> 
   15 #include <stdair/basic/BasConst_General.hpp> 
   16 #include <stdair/basic/BasDBParams.hpp> 
   17 #include <stdair/basic/BasLogParams.hpp> 
   20 #include <trademgen/config/trademgen-paths.hpp> 
   49   stdair::DEFAULT_RANDOM_SEED;
 
   73   typedef boost::tokenizer<boost::char_separator<char> > Tokeniser_T;
 
   76   const boost::char_separator<char> lSepatorList(
" .,;:|+-*/_=!@#$%`~^&(){}[]?'<>\"");
 
   79   Tokeniser_T lTokens (iPhrase, lSepatorList);
 
   80   for (Tokeniser_T::const_iterator tok_iter = lTokens.begin();
 
   81        tok_iter != lTokens.end(); ++tok_iter) {
 
   82     const std::string& lTerm = *tok_iter;
 
   83     ioWordList.push_back (lTerm);
 
   90   std::ostringstream oStr;
 
   92   unsigned short idx = iWordList.size();
 
   93   for (WordList_T::const_iterator itWord = iWordList.begin();
 
   94        itWord != iWordList.end(); ++itWord, --idx) {
 
   95     const std::string& lWord = *itWord;
 
  108 template<
class T> std::ostream& 
operator<< (std::ostream& os,
 
  109                                             const std::vector<T>& v) {
 
  110   std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout, 
" ")); 
 
  119                        stdair::RandomSeed_T& ioRandomSeed, 
 
  120                        std::string& ioQueryString,
 
  121                        stdair::Filename_T& ioInputFilename,
 
  122                        std::string& ioLogFilename,
 
  123                        std::string& ioDBUser, std::string& ioDBPasswd,
 
  124                        std::string& ioDBHost, std::string& ioDBPort,
 
  125                        std::string& ioDBDBName) {
 
  131   if (ioQueryString.empty() == 
true) {
 
  140   boost::program_options::options_description 
generic (
"Generic options");
 
  141   generic.add_options()
 
  142     (
"prefix", 
"print installation prefix")
 
  143     (
"version,v", 
"print version string")
 
  144     (
"help,h", 
"produce help message");
 
  148   boost::program_options::options_description config (
"Configuration");
 
  151      "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")
 
  154      "Seed for the random generation")
 
  157      "(CVS) input file for the demand distributions")
 
  160      "Filepath for the logs")
 
  163      "SQL database user (e.g., dsim)")
 
  166      "SQL database password (e.g., dsim)")
 
  169      "SQL database hostname (e.g., localhost)")
 
  172      "SQL database port (e.g., 3306)")
 
  175      "SQL database name (e.g., sim_dsim)")
 
  177      boost::program_options::value< WordList_T >(&lWordList)->multitoken(),
 
  183   boost::program_options::options_description hidden (
"Hidden options");
 
  186      boost::program_options::value< std::vector<std::string> >(),
 
  187      "Show the copyright (license)");
 
  189   boost::program_options::options_description cmdline_options;
 
  190   cmdline_options.add(
generic).add(config).add(hidden);
 
  192   boost::program_options::options_description config_file_options;
 
  193   config_file_options.add(config).add(hidden);
 
  195   boost::program_options::options_description visible (
"Allowed options");
 
  196   visible.add(
generic).add(config);
 
  198   boost::program_options::positional_options_description p;
 
  199   p.add (
"copyright", -1);
 
  201   boost::program_options::variables_map vm;
 
  202   boost::program_options::
 
  203     store (boost::program_options::command_line_parser (argc, argv).
 
  204            options (cmdline_options).positional(p).run(), vm);
 
  206   std::ifstream ifs (
"trademgen_with_db.cfg");
 
  207   boost::program_options::store (parse_config_file (ifs, config_file_options),
 
  209   boost::program_options::notify (vm);
 
  211   if (vm.count (
"help")) {
 
  212     std::cout << visible << std::endl;
 
  216   if (vm.count (
"version")) {
 
  217     std::cout << PACKAGE_NAME << 
", version " << PACKAGE_VERSION << std::endl;
 
  221   if (vm.count (
"prefix")) {
 
  222     std::cout << 
"Installation prefix: " << PREFIXDIR << std::endl;
 
  226   if (vm.count (
"builtin")) {
 
  229   const std::string isBuiltinStr = (ioIsBuiltin == 
true)?
"yes":
"no";
 
  230   std::cout << 
"The BOM should be built-in? " << isBuiltinStr << std::endl;
 
  232   if (ioIsBuiltin == 
false) {
 
  235     if (vm.count (
"input")) {
 
  236       ioInputFilename = vm[
"input"].as< std::string >();
 
  237       std::cout << 
"Input filename is: " << ioInputFilename << std::endl;
 
  242       std::cerr << 
"Either one among the -b/--builtin and -i/--input " 
  243                 << 
"options must be specified" << std::endl;
 
  247   if (vm.count (
"log")) {
 
  248     ioLogFilename = vm[
"log"].as< std::string >();
 
  249     std::cout << 
"Log filename is: " << ioLogFilename << std::endl;
 
  252   if (vm.count (
"user")) {
 
  253     ioDBUser = vm[
"user"].as< std::string >();
 
  254     std::cout << 
"SQL database user name is: " << ioDBUser << std::endl;
 
  257   if (vm.count (
"passwd")) {
 
  258     ioDBPasswd = vm[
"passwd"].as< std::string >();
 
  262   if (vm.count (
"host")) {
 
  263     ioDBHost = vm[
"host"].as< std::string >();
 
  264     std::cout << 
"SQL database host name is: " << ioDBHost << std::endl;
 
  267   if (vm.count (
"port")) {
 
  268     ioDBPort = vm[
"port"].as< std::string >();
 
  269     std::cout << 
"SQL database port number is: " << ioDBPort << std::endl;
 
  272   if (vm.count (
"dbname")) {
 
  273     ioDBDBName = vm[
"dbname"].as< std::string >();
 
  274     std::cout << 
"SQL database name is: " << ioDBDBName << std::endl;
 
  278   std::cout << 
"The random generation seed is: " << ioRandomSeed << std::endl;
 
  281   std::cout << 
"The query string is: " << ioQueryString << std::endl;
 
  288 int main (
int argc, 
char* argv[]) {
 
  294   stdair::RandomSeed_T lRandomSeed;
 
  300   stdair::Filename_T lInputFilename;
 
  303   std::string lLogFilename;
 
  307   std::string lDBPasswd;
 
  310   std::string lDBDBName;
 
  313   const stdair::AirlineCode_T lAirlineCode (
"BA");
 
  316   const int lOptionParserStatus = 
 
  318                        lInputFilename, lLogFilename,
 
  319                        lDBUser, lDBPasswd, lDBHost, lDBPort, lDBDBName);
 
  326   stdair::BasDBParams lDBParams (lDBUser, lDBPasswd, lDBHost, lDBPort,
 
  330   std::ofstream logOutputFile;
 
  332   logOutputFile.open (lLogFilename.c_str());
 
  333   logOutputFile.clear();
 
  336   const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
 
  343   if (isBuiltin == 
true) {
 
  357   logOutputFile.close();