AirRAC Logo  1.00.7
C++ Simulated Revenue Accounting (RAC) System Library
Loading...
Searching...
No Matches
airrac.cpp
Go to the documentation of this file.
1// STL
2#include <cassert>
3#include <iostream>
4#include <sstream>
5#include <fstream>
6#include <vector>
7#include <list>
8#include <string>
9// Boost (Extended STL)
10#include <boost/date_time/posix_time/posix_time.hpp>
11#include <boost/date_time/gregorian/gregorian.hpp>
12#include <boost/tokenizer.hpp>
13#include <boost/program_options.hpp>
14// StdAir
15#include <stdair/STDAIR_Service.hpp>
16#include <stdair/bom/TravelSolutionStruct.hpp>
17#include <stdair/service/Logger.hpp>
18// Airrac
20#include <airrac/config/airrac-paths.hpp>
21
22// //////// Type definitions ///////
23typedef std::vector<std::string> WordList_T;
24
25
26// //////// Constants //////
28const std::string K_AIRRAC_DEFAULT_LOG_FILENAME ("airrac.log");
29
31const std::string K_AIRRAC_DEFAULT_YIELD_INPUT_FILENAME (STDAIR_SAMPLE_DIR
32 "/yieldstore01.csv");
33
37
40
41// ///////// Parsing of Options & Configuration /////////
42// A helper function to simplify the main part.
43template<class T> std::ostream& operator<< (std::ostream& os,
44 const std::vector<T>& v) {
45 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout, " "));
46 return os;
47}
48
50int readConfiguration (int argc, char* argv[], bool& ioIsBuiltin,
51 stdair::Filename_T& ioYieldInputFilename,
52 std::string& ioLogFilename) {
53
54 // Default for the built-in input
56
57 // Declare a group of options that will be allowed only on command line
58 boost::program_options::options_description generic ("Generic options");
59 generic.add_options()
60 ("prefix", "print installation prefix")
61 ("version,v", "print version string")
62 ("help,h", "produce help message");
63
64 // Declare a group of options that will be allowed both on command
65 // line and in config file
66 boost::program_options::options_description config ("Configuration");
67 config.add_options()
68 ("builtin,b",
69 "The sample BOM tree can be either built-in or parsed from an input file. That latter must then be given with the -y/--yield option")
70 ("yield,y",
71 boost::program_options::value< std::string >(&ioYieldInputFilename)->default_value(K_AIRRAC_DEFAULT_YIELD_INPUT_FILENAME),
72 "(CSV) input file for the yield rules")
73 ("log,l",
74 boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_AIRRAC_DEFAULT_LOG_FILENAME),
75 "Filename for the logs")
76 ;
77
78 // Hidden options, will be allowed both on command line and
79 // in config file, but will not be shown to the user.
80 boost::program_options::options_description hidden ("Hidden options");
81 hidden.add_options()
82 ("copyright",
83 boost::program_options::value< std::vector<std::string> >(),
84 "Show the copyright (license)");
85
86 boost::program_options::options_description cmdline_options;
87 cmdline_options.add(generic).add(config).add(hidden);
88
89 boost::program_options::options_description config_file_options;
90 config_file_options.add(config).add(hidden);
91
92 boost::program_options::options_description visible ("Allowed options");
93 visible.add(generic).add(config);
94
95 boost::program_options::positional_options_description p;
96 p.add ("copyright", -1);
97
98 boost::program_options::variables_map vm;
99 boost::program_options::
100 store (boost::program_options::command_line_parser (argc, argv).
101 options (cmdline_options).positional(p).run(), vm);
102
103 std::ifstream ifs ("airrac.cfg");
104 boost::program_options::store (parse_config_file (ifs, config_file_options),
105 vm);
106 boost::program_options::notify (vm); if (vm.count ("help")) {
107 std::cout << visible << std::endl;
109 }
110
111 if (vm.count ("version")) {
112 std::cout << PACKAGE_NAME << ", version " << PACKAGE_VERSION << std::endl;
114 }
115
116 if (vm.count ("prefix")) {
117 std::cout << "Installation prefix: " << PREFIXDIR << std::endl;
119 }
120
121 if (vm.count ("builtin")) {
122 ioIsBuiltin = true;
123 }
124 const std::string isBuiltinStr = (ioIsBuiltin == true)?"yes":"no";
125 std::cout << "The BOM should be built-in? " << isBuiltinStr << std::endl;
126
127 if (ioIsBuiltin == false) {
128
129 // The BOM tree should be built from parsing a yield (and O&D) file
130 if (vm.count ("yield")) {
131 ioYieldInputFilename = vm["yield"].as< std::string >();
132 std::cout << "Input yield filename is: " << ioYieldInputFilename
133 << std::endl;
134
135 } else {
136 // The built-in option is not selected. However, no yield file
137 // is specified
138 std::cerr << "Either one among the -b/--builtin and -y/--yield "
139 << "options must be specified" << std::endl;
140 }
141 }
142
143 if (vm.count ("log")) {
144 ioLogFilename = vm["log"].as< std::string >();
145 std::cout << "Log filename is: " << ioLogFilename << std::endl;
146 }
147
148 return 0;
149}
150
151
152// /////////////// M A I N /////////////////
153int main (int argc, char* argv[]) {
154
155 // State whether the BOM tree should be built-in or parsed from an input file
156 bool isBuiltin;
157
158 // Yield input filename
159 stdair::Filename_T lYieldInputFilename;
160
161 // Output log File
162 stdair::Filename_T lLogFilename;
163
164 // Call the command-line option parser
165 const int lOptionParserStatus =
166 readConfiguration (argc, argv, isBuiltin, lYieldInputFilename, lLogFilename);
167
168 if (lOptionParserStatus == K_AIRRAC_EARLY_RETURN_STATUS) {
169 return 0;
170 }
171
172 // Set the log parameters
173 std::ofstream logOutputFile;
174 // Open and clean the log outputfile
175 logOutputFile.open (lLogFilename.c_str());
176 logOutputFile.clear();
177
178 // Initialise the AirRAC service object
179 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
180
181 AIRRAC::AIRRAC_Service airracService (lLogParams);
182
183 // DEBUG
184 STDAIR_LOG_DEBUG ("Welcome to AirRAC");
185
186 // Build a sample list of travel solutions
187 stdair::TravelSolutionList_T lTravelSolutionList;
188 airracService.buildSampleTravelSolutions (lTravelSolutionList);
189
190 // Check wether or not a (CSV) input file should be read
191 if (isBuiltin == true) {
192
193 // Build the sample BOM tree (filled with yields) for AirRAC
194 airracService.buildSampleBom();
195
196 } else {
197
198 // Build the BOM tree from parsing a yield file
199 AIRRAC::YieldFilePath lYieldFilePath (lYieldInputFilename);
200 airracService.parseAndLoad (lYieldFilePath);
201
202 }
203
204 // DEBUG: Display the whole BOM tree
205 const std::string& lBOMCSVDump = airracService.csvDisplay();
206 STDAIR_LOG_DEBUG ("BOM tree: " << lBOMCSVDump);
207
208 // DEBUG: Display the travel solutions
209 const std::string& lTSCSVDump =
210 airracService.csvDisplay (lTravelSolutionList);
211 STDAIR_LOG_DEBUG (lTSCSVDump);
212
213 // Close the Log outputFile
214 logOutputFile.close();
215
216 /*
217 Note: as that program is not intended to be run on a server in
218 production, it is better not to catch the exceptions. When it
219 happens (that an exception is throwned), that way we get the
220 call stack.
221 */
222
223 return 0;
224}
int main(int argc, char *argv[])
Definition airrac.cpp:153
int readConfiguration(int argc, char *argv[], bool &ioIsBuiltin, stdair::Filename_T &ioYieldInputFilename, std::string &ioLogFilename)
Definition airrac.cpp:50
const std::string K_AIRRAC_DEFAULT_LOG_FILENAME("airrac.log")
std::vector< std::string > WordList_T
Definition airrac.cpp:23
const std::string K_AIRRAC_DEFAULT_YIELD_INPUT_FILENAME(STDAIR_SAMPLE_DIR "/yieldstore01.csv")
const int K_AIRRAC_EARLY_RETURN_STATUS
Definition airrac.cpp:39
std::ostream & operator<<(std::ostream &os, const std::vector< T > &v)
Definition airrac.cpp:43
const bool K_AIRRAC_DEFAULT_BUILT_IN_INPUT
Definition airrac.cpp:36
Interface for the AIRRAC Services.
std::string csvDisplay() const
void buildSampleTravelSolutions(stdair::TravelSolutionList_T &)
void parseAndLoad(const YieldFilePath &iYieldFilename)