SEvMgr Logo  0.2.0
C++ Simulation-Oriented Discrete Event Management Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
sevmgr_demo.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 #include <fstream>
8 #include <vector>
9 #include <list>
10 #include <string>
11 // //// Boost (Extended STL) ////
12 // Boost Program Options
13 #include <boost/program_options.hpp>
14 // StdAir
15 #include <stdair/stdair_basic_types.hpp>
16 #include <stdair/basic/ProgressStatusSet.hpp>
17 #include <stdair/bom/EventStruct.hpp>
18 #include <stdair/bom/EventQueue.hpp>
19 #include <stdair/bom/BomDisplay.hpp>
20 #include <stdair/service/Logger.hpp>
21 // SEvMgr
24 
25 // //////// Constants //////
27 const stdair::Filename_T K_SEVMGR_DEFAULT_LOG_FILENAME ("sevmgr_demo.log");
28 
31 
32 
33 // ///////// Parsing of Options & Configuration /////////
35 int readConfiguration (int argc, char* argv[],
36  stdair::Filename_T& ioLogFilename) {
37 
38  // Declare a group of options that will be allowed only on command line
39  boost::program_options::options_description generic ("Generic options");
40  generic.add_options()
41  ("prefix", "print installation prefix")
42  ("version,v", "print version string")
43  ("help,h", "produce help message");
44 
45  // Declare a group of options that will be allowed both on command
46  // line and in config file
47  boost::program_options::options_description config ("Configuration");
48  config.add_options()
49  ("log,l",
50  boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_SEVMGR_DEFAULT_LOG_FILENAME),
51  "Filepath for the logs")
52  ;
53 
54  // Hidden options, will be allowed both on command line and
55  // in config file, but will not be shown to the user.
56  boost::program_options::options_description hidden ("Hidden options");
57  hidden.add_options()
58  ("copyright",
59  boost::program_options::value< std::vector<std::string> >(),
60  "Show the copyright (license)");
61 
62  boost::program_options::options_description cmdline_options;
63  cmdline_options.add(generic).add(config).add(hidden);
64 
65  boost::program_options::options_description config_file_options;
66  config_file_options.add(config).add(hidden);
67 
68  boost::program_options::options_description visible ("Allowed options");
69  visible.add(generic).add(config);
70 
71  boost::program_options::positional_options_description p;
72  p.add ("copyright", -1);
73 
74  boost::program_options::variables_map vm;
75  boost::program_options::
76  store (boost::program_options::command_line_parser (argc, argv).
77  options (cmdline_options).positional(p).run(), vm);
78 
79  std::ifstream ifs ("sevmgr.cfg");
80  boost::program_options::store (parse_config_file (ifs, config_file_options),
81  vm);
82  boost::program_options::notify (vm);
83 
84  if (vm.count ("help")) {
85  std::cout << visible << std::endl;
87  }
88 
89  if (vm.count ("version")) {
90  std::cout << PACKAGE_NAME << ", version " << PACKAGE_VERSION << std::endl;
92  }
93 
94  if (vm.count ("prefix")) {
95  std::cout << "Installation prefix: " << PREFIXDIR << std::endl;
97  }
98 
99  if (vm.count ("log")) {
100  ioLogFilename = vm["log"].as< std::string >();
101  std::cout << "Log filename is: " << ioLogFilename << std::endl;
102  }
103 
104  return 0;
105 }
106 
107 
108 // /////////////// M A I N /////////////////
109 int main (int argc, char* argv[]) {
110 
111  // Output log File
112  stdair::Filename_T lLogFilename;
113 
114  // Call the command-line option parser
115  const int lOptionParserStatus = readConfiguration (argc, argv, lLogFilename);
116 
117  if (lOptionParserStatus == K_SEVMGR_EARLY_RETURN_STATUS) {
118  return 0;
119  }
120 
121  // Set the log parameters
122  std::ofstream logOutputFile;
123  // Open and clean the log outputfile
124  logOutputFile.open (lLogFilename.c_str());
125  logOutputFile.clear();
126 
127  // Set up the log parameters
128  const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
129 
133  SEVMGR::SEVMGR_Service sevmgrService (lLogParams);
134 
135  // Build a sample BOM tree (empty for now)
136  sevmgrService.buildSampleBom();
137 
138  // Close the Log outputFile
139  logOutputFile.close();
140 
141  /*
142  Note: as that program is not intended to be run on a server in
143  production, it is better not to catch the exceptions. When it
144  happens (that an exception is throwned), that way we get the
145  call stack.
146  */
147 
148  return 0;
149 }