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 (
"parseInventory.log");
53 const std::string K_AIRINV_DEFAULT_SEGMENT_DATE_KEY (
"SV,5,2010-03-11,KBP,JFK");
58 const stdair::ClassCode_T K_AIRINV_DEFAULT_CLASS_CODE (
"Y");
63 const stdair::PartySize_T K_AIRINV_DEFAULT_PARTY_SIZE (2);
69 const bool K_AIRINV_DEFAULT_BUILT_IN_INPUT =
false;
75 const bool K_AIRINV_DEFAULT_FOR_SCHEDULE =
false;
80 const int K_AIRINV_EARLY_RETURN_STATUS = 99;
84 template<
class T> std::ostream&
operator<< (std::ostream& os,
85 const std::vector<T>& v) {
86 std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout,
" "));
93 int readConfiguration (
int argc,
char* argv[],
94 bool& ioIsBuiltin,
bool& ioIsForSchedule,
95 stdair::Filename_T& ioInventoryFilename,
96 stdair::Filename_T& ioScheduleInputFilename,
97 stdair::Filename_T& ioODInputFilename,
98 stdair::Filename_T& ioYieldInputFilename,
99 std::string& ioSegmentDateKey,
100 stdair::ClassCode_T& ioClassCode,
101 stdair::PartySize_T& ioPartySize,
102 std::string& ioLogFilename) {
104 ioIsBuiltin = K_AIRINV_DEFAULT_BUILT_IN_INPUT;
107 ioIsForSchedule = K_AIRINV_DEFAULT_FOR_SCHEDULE;
110 boost::program_options::options_description
generic (
"Generic options");
111 generic.add_options()
112 (
"prefix",
"print installation prefix")
113 (
"version,v",
"print version string")
114 (
"help,h",
"produce help message");
119 boost::program_options::options_description config (
"Configuration");
122 "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")
124 "The BOM tree should be built from a schedule file (instead of from an inventory dump)")
126 boost::program_options::value< std::string >(&ioInventoryFilename)->default_value(K_AIRINV_DEFAULT_INVENTORY_FILENAME),
127 "(CSV) input file for the inventory")
129 boost::program_options::value< std::string >(&ioScheduleInputFilename)->default_value(K_AIRINV_DEFAULT_SCHEDULE_FILENAME),
130 "(CSV) input file for the schedule")
132 boost::program_options::value< std::string >(&ioODInputFilename)->default_value(K_AIRINV_DEFAULT_OND_FILENAME),
133 "(CSV) input file for the O&D")
135 boost::program_options::value< std::string >(&ioYieldInputFilename)->default_value(K_AIRINV_DEFAULT_YIELD_FILENAME),
136 "(CSV) input file for the yield")
137 (
"segment_date_key,k",
138 boost::program_options::value< std::string >(&ioSegmentDateKey)->default_value(K_AIRINV_DEFAULT_SEGMENT_DATE_KEY),
141 boost::program_options::value< stdair::ClassCode_T >(&ioClassCode)->default_value(K_AIRINV_DEFAULT_CLASS_CODE),
144 boost::program_options::value< stdair::PartySize_T >(&ioPartySize)->default_value(K_AIRINV_DEFAULT_PARTY_SIZE),
147 boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_AIRINV_DEFAULT_LOG_FILENAME),
148 "Filename for the logs")
153 boost::program_options::options_description hidden (
"Hidden options");
156 boost::program_options::value< std::vector<std::string> >(),
157 "Show the copyright (license)");
159 boost::program_options::options_description cmdline_options;
160 cmdline_options.add(
generic).add(config).add(hidden);
162 boost::program_options::options_description config_file_options;
163 config_file_options.add(config).add(hidden);
164 boost::program_options::options_description visible (
"Allowed options");
165 visible.add(
generic).add(config);
167 boost::program_options::positional_options_description p;
168 p.add (
"copyright", -1);
170 boost::program_options::variables_map vm;
171 boost::program_options::
172 store (boost::program_options::command_line_parser (argc, argv).
173 options (cmdline_options).positional(p).run(), vm);
175 std::ifstream ifs (
"airinv.cfg");
176 boost::program_options::store (parse_config_file (ifs, config_file_options),
178 boost::program_options::notify (vm);
180 if (vm.count (
"help")) {
181 std::cout << visible << std::endl;
182 return K_AIRINV_EARLY_RETURN_STATUS;
185 if (vm.count (
"version")) {
187 return K_AIRINV_EARLY_RETURN_STATUS;
190 if (vm.count (
"prefix")) {
191 std::cout <<
"Installation prefix: " <<
PREFIXDIR << std::endl;
192 return K_AIRINV_EARLY_RETURN_STATUS;
195 if (vm.count (
"builtin")) {
198 const std::string isBuiltinStr = (ioIsBuiltin ==
true)?
"yes":
"no";
199 std::cout <<
"The BOM should be built-in? " << isBuiltinStr << std::endl;
201 if (vm.count (
"for_schedule")) {
202 ioIsForSchedule =
true;
204 const std::string isForScheduleStr = (ioIsForSchedule ==
true)?
"yes":
"no";
205 std::cout <<
"The BOM should be built from schedule? " << isForScheduleStr
208 if (ioIsBuiltin ==
false) {
210 if (ioIsForSchedule ==
false) {
212 if (vm.count (
"inventory")) {
213 ioInventoryFilename = vm[
"inventory"].as< std::string >();
214 std::cout <<
"Input inventory filename is: " << ioInventoryFilename
220 std::cerr <<
"Either one among the -b/--builtin, -i/--inventory or "
221 <<
" -f/--for_schedule and -s/--schedule options "
222 <<
"must be specified" << std::endl;
227 if (vm.count (
"schedule")) {
228 ioScheduleInputFilename = vm[
"schedule"].as< std::string >();
229 std::cout <<
"Input schedule filename is: " << ioScheduleInputFilename
235 std::cerr <<
"Either one among the -b/--builtin, -i/--inventory or "
236 <<
" -f/--for_schedule and -s/--schedule options "
237 <<
"must be specified" << std::endl;
240 if (vm.count (
"ond")) {
241 ioODInputFilename = vm[
"ond"].as< std::string >();
242 std::cout <<
"Input O&D filename is: " << ioODInputFilename << std::endl;
245 if (vm.count (
"yield")) {
246 ioYieldInputFilename = vm[
"yield"].as< std::string >();
247 std::cout <<
"Input yield filename is: "
248 << ioYieldInputFilename << std::endl;
253 if (vm.count (
"log")) {
254 ioLogFilename = vm[
"log"].as< std::string >();
255 std::cout <<
"Log filename is: " << ioLogFilename << std::endl;
263 int main (
int argc,
char* argv[]) {
271 stdair::Filename_T lInventoryFilename;
272 stdair::Filename_T lScheduleInputFilename;
273 stdair::Filename_T lODInputFilename;
274 stdair::Filename_T lYieldInputFilename;
277 std::string lSegmentDateKey;
278 stdair::ClassCode_T lClassCode;
279 stdair::PartySize_T lPartySize;
282 stdair::Filename_T lLogFilename;
285 const int lOptionParserStatus =
286 readConfiguration (argc, argv, isBuiltin, isForSchedule, lInventoryFilename,
287 lScheduleInputFilename, lODInputFilename,
288 lYieldInputFilename, lSegmentDateKey, lClassCode,
289 lPartySize, lLogFilename);
291 if (lOptionParserStatus == K_AIRINV_EARLY_RETURN_STATUS) {
296 std::ofstream logOutputFile;
298 logOutputFile.open (lLogFilename.c_str());
299 logOutputFile.clear();
302 const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
306 STDAIR_LOG_DEBUG (
"Welcome to AirInv");
309 if (isBuiltin ==
true) {
312 airinvService.buildSampleBom();
316 lSegmentDateKey =
"SQ,11,2010-02-08,SIN,BKK";
319 if (isForSchedule ==
true) {
321 stdair::ScheduleFilePath lScheduleFilePath (lScheduleInputFilename);
322 stdair::ODFilePath lODFilePath (lODInputFilename);
323 AIRRAC::YieldFilePath lYieldFilePath (lYieldInputFilename);
324 airinvService.parseAndLoad (lScheduleFilePath, lODFilePath,
327 if (lSegmentDateKey == K_AIRINV_DEFAULT_SEGMENT_DATE_KEY) {
329 lSegmentDateKey =
"SQ,11,2010-01-15,SIN,BKK";
335 airinvService.parseAndLoad (lInventoryFilePath);
340 const bool isSellSuccessful =
341 airinvService.sell (lSegmentDateKey, lClassCode, lPartySize);
344 STDAIR_LOG_DEBUG (
"Sale ('" << lSegmentDateKey <<
"', " << lClassCode <<
": "
345 << lPartySize <<
") successful? " << isSellSuccessful);
348 const std::string& lCSVDump = airinvService.csvDisplay();
349 STDAIR_LOG_DEBUG (lCSVDump);
352 logOutputFile.close();