SEvMgr Logo  1.00.9
C++ Simulation-Oriented Discrete Event Management Library
Loading...
Searching...
No Matches
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/BomDisplay.hpp>
19#include <stdair/service/Logger.hpp>
20#include <stdair/bom/BookingRequestStruct.hpp>
21#include <stdair/bom/BookingRequestTypes.hpp>
22#include <stdair/bom/EventStruct.hpp>
23// SEvMgr
25#include <sevmgr/config/sevmgr-paths.hpp>
26
27// //////// Constants //////
29const stdair::Filename_T K_SEVMGR_DEFAULT_LOG_FILENAME ("sevmgr_demo.log");
30
33
34
35// ///////// Parsing of Options & Configuration /////////
37int readConfiguration (int argc, char* argv[],
38 stdair::Filename_T& ioLogFilename) {
39
40 // Declare a group of options that will be allowed only on command line
41 boost::program_options::options_description generic ("Generic options");
42 generic.add_options()
43 ("prefix", "print installation prefix")
44 ("version,v", "print version string")
45 ("help,h", "produce help message");
46
47 // Declare a group of options that will be allowed both on command
48 // line and in config file
49 boost::program_options::options_description config ("Configuration");
50 config.add_options()
51 ("log,l",
52 boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_SEVMGR_DEFAULT_LOG_FILENAME),
53 "Filepath for the logs")
54 ;
55
56 // Hidden options, will be allowed both on command line and
57 // in config file, but will not be shown to the user.
58 boost::program_options::options_description hidden ("Hidden options");
59 hidden.add_options()
60 ("copyright",
61 boost::program_options::value< std::vector<std::string> >(),
62 "Show the copyright (license)");
63
64 boost::program_options::options_description cmdline_options;
65 cmdline_options.add(generic).add(config).add(hidden);
66
67 boost::program_options::options_description config_file_options;
68 config_file_options.add(config).add(hidden);
69
70 boost::program_options::options_description visible ("Allowed options");
71 visible.add(generic).add(config);
72
73 boost::program_options::positional_options_description p;
74 p.add ("copyright", -1);
75
76 boost::program_options::variables_map vm;
77 boost::program_options::
78 store (boost::program_options::command_line_parser (argc, argv).
79 options (cmdline_options).positional(p).run(), vm);
80
81 std::ifstream ifs ("sevmgr.cfg");
82 boost::program_options::store (parse_config_file (ifs, config_file_options),
83 vm);
84 boost::program_options::notify (vm);
85
86 if (vm.count ("help")) {
87 std::cout << visible << std::endl;
89 }
90
91 if (vm.count ("version")) {
92 std::cout << PACKAGE_NAME << ", version " << PACKAGE_VERSION << std::endl;
94 }
95
96 if (vm.count ("prefix")) {
97 std::cout << "Installation prefix: " << PREFIXDIR << std::endl;
99 }
100
101 if (vm.count ("log")) {
102 ioLogFilename = vm["log"].as< std::string >();
103 std::cout << "Log filename is: " << ioLogFilename << std::endl;
104 }
105
106 return 0;
107}
108
109
110// /////////////// M A I N /////////////////
111int main (int argc, char* argv[]) {
112
113 // Output log File
114 stdair::Filename_T lLogFilename;
115
116 // Call the command-line option parser
117 const int lOptionParserStatus = readConfiguration (argc, argv, lLogFilename);
118
119 if (lOptionParserStatus == K_SEVMGR_EARLY_RETURN_STATUS) {
120 return 0;
121 }
122
123 // Set the log parameters
124 std::ofstream logOutputFile;
125 // Open and clean the log outputfile
126 logOutputFile.open (lLogFilename.c_str());
127 logOutputFile.clear();
128
129 // Set up the log parameters
130 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
131
135 SEVMGR::SEVMGR_Service sevmgrService (lLogParams);
136
137 // Build the default sample queue.
138 STDAIR_LOG_DEBUG ("Build the default sample queue.");
139 sevmgrService.buildSampleQueue();
140
147 stdair::Count_T idx = 1;
148 while (sevmgrService.isQueueDone() == false) {
149
150 // Pop the next event out of the event queue
151 stdair::EventStruct lEventStruct;
152 const stdair::ProgressStatusSet lPPS =
153 sevmgrService.popEvent (lEventStruct);
154
155 // DEBUG
156 STDAIR_LOG_DEBUG ("Poped event "<< idx << ": '"
157 << lEventStruct.describe() << "'.");
158 STDAIR_LOG_DEBUG ("Progresss status: " << lPPS.describe());
159
160 // Iterate
161 ++idx;
162 }
163
164 // DEBUG
165 STDAIR_LOG_DEBUG ("End of the simulation");
166
167 // Close the Log outputFile
168 logOutputFile.close();
169
170 /*
171 Note: as that program is not intended to be run on a server in
172 production, it is better not to catch the exceptions. When it
173 happens (that an exception is throwned), that way we get the
174 call stack.
175 */
176
177 return 0;
178}
class holding the services related to Travel Demand Generation.
stdair::ProgressStatusSet popEvent(stdair::EventStruct &) const
int main(int argc, char *argv[])
int readConfiguration(int argc, char *argv[], stdair::Filename_T &ioLogFilename)
const int K_SEVMGR_EARLY_RETURN_STATUS
const stdair::Filename_T K_SEVMGR_DEFAULT_LOG_FILENAME("sevmgr_demo.log")