Changeset 1301 in SHVCSoftware
- Timestamp:
- 21 Jul 2015, 00:19:48 (9 years ago)
- Location:
- branches/SHM-dev/source
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.cpp
r1273 r1301 83 83 string cfg_TargetDecLayerIdSetFile; 84 84 string outputColourSpaceConvert; 85 Int warnUnknowParameter = 0; 85 86 86 87 po::Options opts; … … 107 108 "YUV writing is skipped if omitted") 108 109 #endif 109 110 ("WarnUnknowParameter,w", warnUnknowParameter, 0, "warn for unknown configuration parameters instead of failing") 110 111 ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access") 111 112 ("OutputBitDepth,d", m_outputBitDepth[CHANNEL_TYPE_LUMA], 0, "bit depth of YUV output luma component (default: use 0 for native depth)") … … 131 132 132 133 po::setDefaults(opts); 133 const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv); 134 po::ErrorReporter err; 135 const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv, err); 134 136 135 137 for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++) … … 142 144 po::doHelp(cout, opts); 143 145 return false; 146 } 147 148 if (err.is_errored) 149 { 150 if (!warnUnknowParameter) 151 { 152 /* errors have already been reported to stderr */ 153 return false; 154 } 144 155 } 145 156 -
branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp
r1298 r1301 1024 1024 SMultiValueInput<Int> cfg_timeCodeSeiTimeOffsetLength (0, 31, 0, MAX_TIMECODE_SEI_SETS); 1025 1025 SMultiValueInput<Int> cfg_timeCodeSeiTimeOffsetValue (std::numeric_limits<Int>::min(), std::numeric_limits<Int>::max(), 0, MAX_TIMECODE_SEI_SETS); 1026 Int warnUnknowParameter = 0; 1026 1027 1027 1028 #if Q0096_OVERLAY_SEI … … 1045 1046 ("help", do_help, false, "this help text") 1046 1047 ("c", po::parseConfigFile, "configuration file name") 1048 ("WarnUnknowParameter,w", warnUnknowParameter, 0, "warn for unknown configuration parameters instead of failing") 1047 1049 1048 1050 // File, I/O and source parameters … … 1688 1690 1689 1691 po::setDefaults(opts); 1690 const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv); 1692 po::ErrorReporter err; 1693 const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv, err); 1691 1694 1692 1695 #if SVC_EXTENSION … … 1720 1723 po::doHelp(cout, opts); 1721 1724 return false; 1725 } 1726 1727 if (err.is_errored) 1728 { 1729 if (!warnUnknowParameter) 1730 { 1731 /* error report has already been printed on stderr */ 1732 return false; 1733 } 1722 1734 } 1723 1735 -
branches/SHM-dev/source/Lib/TAppCommon/program_options_lite.cpp
r1259 r1301 50 50 namespace program_options_lite 51 51 { 52 ErrorReporter default_error_reporter; 53 54 ostream& ErrorReporter::error(const string& where) 55 { 56 is_errored = 1; 57 cerr << where << " error: "; 58 return cerr; 59 } 60 61 ostream& ErrorReporter::warn(const string& where) 62 { 63 cerr << where << " warning: "; 64 return cerr; 65 } 52 66 53 67 Options::~Options() … … 97 111 } 98 112 99 static void setOptions(Options::NamesPtrList& opt_list, const string& value )113 static void setOptions(Options::NamesPtrList& opt_list, const string& value, ErrorReporter& error_reporter) 100 114 { 101 115 /* multiple options may be registered for the same name: … … 103 117 for (Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); ++it) 104 118 { 105 (*it)->opt->parse(value );119 (*it)->opt->parse(value, error_reporter); 106 120 } 107 121 } … … 236 250 } 237 251 238 bool storePair(Options& opts, bool allow_long, bool allow_short, const string& name, const string& value) 252 struct OptionWriter 253 { 254 OptionWriter(Options& rOpts, ErrorReporter& err) 255 : opts(rOpts), error_reporter(err) 256 {} 257 virtual ~OptionWriter() {} 258 259 virtual const string where() = 0; 260 261 bool storePair(bool allow_long, bool allow_short, const string& name, const string& value); 262 bool storePair(const string& name, const string& value) 263 { 264 return storePair(true, true, name, value); 265 } 266 267 Options& opts; 268 ErrorReporter& error_reporter; 269 }; 270 271 bool OptionWriter::storePair(bool allow_long, bool allow_short, const string& name, const string& value) 239 272 { 240 273 bool found = false; … … 261 294 if (!found) 262 295 { 263 /* not found */264 cerr << "Unknown option: `" << name << "' (value:`" << value << "')" << endl;296 error_reporter.error(where()) 297 << "Unknown option `" << name << "' (value:`" << value << "')\n"; 265 298 return false; 266 299 } 267 300 268 setOptions((*opt_it).second, value );301 setOptions((*opt_it).second, value, error_reporter); 269 302 return true; 270 303 } 271 304 272 bool storePair(Options& opts, const string& name, const string& value) 273 { 274 return storePair(opts, true, true, name, value); 275 } 305 struct ArgvParser : public OptionWriter 306 { 307 ArgvParser(Options& rOpts, ErrorReporter& rError_reporter) 308 : OptionWriter(rOpts, rError_reporter) 309 {} 310 311 const string where() { return "command line"; } 312 313 unsigned parseGNU(unsigned argc, const char* argv[]); 314 unsigned parseSHORT(unsigned argc, const char* argv[]); 315 }; 276 316 277 317 /** 278 318 * returns number of extra arguments consumed 279 319 */ 280 unsigned parseGNU(Options& opts,unsigned argc, const char* argv[])320 unsigned ArgvParser::parseGNU(unsigned argc, const char* argv[]) 281 321 { 282 322 /* gnu style long options can take the forms: … … 304 344 extra_argc_consumed = 1; 305 345 #endif 306 if(!storePair( opts,true, false, option, "1"))346 if(!storePair(true, false, option, "1")) 307 347 { 308 348 return 0; … … 313 353 /* argument occurs after option_sep */ 314 354 string val = arg.substr(arg_opt_sep + 1); 315 storePair( opts,true, false, option, val);355 storePair(true, false, option, val); 316 356 } 317 357 … … 319 359 } 320 360 321 unsigned parseSHORT(Options& opts,unsigned argc, const char* argv[])361 unsigned ArgvParser::parseSHORT(unsigned argc, const char* argv[]) 322 362 { 323 363 /* short options can take the forms: … … 334 374 if (argc == 1) 335 375 { 336 cerr << "Not processing option without argument `" << option << "'" << endl; 376 error_reporter.error(where()) 377 << "Not processing option `" << option << "' without argument\n"; 337 378 return 0; /* run out of argv for argument */ 338 379 } 339 storePair( opts,false, true, option, string(argv[1]));380 storePair(false, true, option, string(argv[1])); 340 381 341 382 return 1; … … 343 384 344 385 list<const char*> 345 scanArgv(Options& opts, unsigned argc, const char* argv[]) 346 { 386 scanArgv(Options& opts, unsigned argc, const char* argv[], ErrorReporter& error_reporter) 387 { 388 ArgvParser avp(opts, error_reporter); 389 347 390 /* a list for anything that didn't get handled as an option */ 348 391 list<const char*> non_option_arguments; … … 366 409 { 367 410 /* handle short (single dash) options */ 368 #if 0 369 i += parsePOSIX(opts, argc - i, &argv[i]); 370 #else 371 i += parseSHORT(opts, argc - i, &argv[i]); 372 #endif 411 i += avp.parseSHORT(argc - i, &argv[i]); 373 412 continue; 374 413 } … … 385 424 386 425 /* handle long (double dash) options */ 387 i += parseGNU(opts,argc - i, &argv[i]);426 i += avp.parseGNU(argc - i, &argv[i]); 388 427 } 389 428 … … 391 430 } 392 431 393 void scanLine(Options& opts, string& line) 432 struct CfgStreamParser : public OptionWriter 433 { 434 CfgStreamParser(const string& rName, Options& rOpts, ErrorReporter& rError_reporter) 435 : OptionWriter(rOpts, rError_reporter) 436 , name(rName) 437 , linenum(0) 438 {} 439 440 const string name; 441 int linenum; 442 const string where() 443 { 444 ostringstream os; 445 os << name << ":" << linenum; 446 return os.str(); 447 } 448 449 void scanLine(string& line); 450 void scanStream(istream& in); 451 }; 452 453 void CfgStreamParser::scanLine(string& line) 394 454 { 395 455 /* strip any leading whitespace */ … … 414 474 { 415 475 /* error: badly formatted line */ 476 error_reporter.warn(where()) << "line formatting error\n"; 416 477 return; 417 478 } … … 419 480 { 420 481 /* error: badly formatted line */ 482 error_reporter.warn(where()) << "line formatting error\n"; 421 483 return; 422 484 } … … 427 489 { 428 490 /* error: badly formatted line */ 491 error_reporter.warn(where()) << "line formatting error\n"; 429 492 return; 430 493 } … … 457 520 { 458 521 /* error: no value */ 522 error_reporter.warn(where()) << "no value found\n"; 459 523 return; 460 524 } 461 525 462 526 /* store the value in option */ 463 storePair( opts,true, false, option, value);464 } 465 466 void scanFile(Options& opts,istream& in)527 storePair(true, false, option, value); 528 } 529 530 void CfgStreamParser::scanStream(istream& in) 467 531 { 468 532 do 469 533 { 534 linenum++; 470 535 string line; 471 536 getline(in, line); 472 scanLine( opts,line);537 scanLine(line); 473 538 } while(!!in); 474 539 } … … 484 549 } 485 550 486 void parseConfigFile(Options& opts, const string& filename )551 void parseConfigFile(Options& opts, const string& filename, ErrorReporter& error_reporter) 487 552 { 488 553 ifstream cfgstream(filename.c_str(), ifstream::in); 489 554 if (!cfgstream) 490 555 { 491 cerr << "Failed to open config file: `" << filename << "'" << endl; 492 exit(EXIT_FAILURE); 493 } 494 scanFile(opts, cfgstream); 556 error_reporter.error(filename) << "Failed to open config file\n"; 557 return; 558 } 559 CfgStreamParser csp(filename, opts, error_reporter); 560 csp.scanStream(cfgstream); 495 561 } 496 562 -
branches/SHM-dev/source/Lib/TAppCommon/program_options_lite.h
r1259 r1301 64 64 }; 65 65 66 struct ErrorReporter 67 { 68 ErrorReporter() : is_errored(0) {} 69 virtual ~ErrorReporter() {} 70 virtual std::ostream& error(const std::string& where); 71 virtual std::ostream& warn(const std::string& where); 72 bool is_errored; 73 }; 74 75 extern ErrorReporter default_error_reporter; 76 66 77 void doHelp(std::ostream& out, Options& opts, unsigned columns = 80); 67 unsigned parseGNU(Options& opts, unsigned argc, const char* argv[]); 68 unsigned parseSHORT(Options& opts, unsigned argc, const char* argv[]); 69 std::list<const char*> scanArgv(Options& opts, unsigned argc, const char* argv[]); 70 void scanLine(Options& opts, std::string& line); 71 void scanFile(Options& opts, std::istream& in); 78 std::list<const char*> scanArgv(Options& opts, unsigned argc, const char* argv[], ErrorReporter& error_reporter = default_error_reporter); 72 79 void setDefaults(Options& opts); 73 void parseConfigFile(Options& opts, const std::string& filename); 74 bool storePair(Options& opts, const std::string& name, const std::string& value); 80 void parseConfigFile(Options& opts, const std::string& filename, ErrorReporter& error_reporter = default_error_reporter); 75 81 76 82 /** OptionBase: Virtual base class for storing information relating to a … … 86 92 87 93 /* parse argument arg, to obtain a value for the option */ 88 virtual void parse(const std::string& arg ) = 0;94 virtual void parse(const std::string& arg, ErrorReporter&) = 0; 89 95 /* set the argument to the default value */ 90 96 virtual void setDefault() = 0; … … 102 108 {} 103 109 104 void parse(const std::string& arg );110 void parse(const std::string& arg, ErrorReporter&); 105 111 106 112 void setDefault() … … 116 122 template<typename T> 117 123 inline void 118 Option<T>::parse(const std::string& arg )124 Option<T>::parse(const std::string& arg, ErrorReporter&) 119 125 { 120 126 std::istringstream arg_ss (arg,std::istringstream::in); … … 134 140 template<> 135 141 inline void 136 Option<std::string>::parse(const std::string& arg )142 Option<std::string>::parse(const std::string& arg, ErrorReporter&) 137 143 { 138 144 opt_storage = arg; … … 142 148 struct OptionFunc : public OptionBase 143 149 { 144 typedef void (Func)(Options&, const std::string& );150 typedef void (Func)(Options&, const std::string&, ErrorReporter&); 145 151 146 152 OptionFunc(const std::string& name, Options& parent_, Func *func_, const std::string& desc) … … 148 154 {} 149 155 150 void parse(const std::string& arg )151 { 152 func(parent, arg );156 void parse(const std::string& arg, ErrorReporter& error_reporter) 157 { 158 func(parent, arg, error_reporter); 153 159 } 154 160 … … 160 166 private: 161 167 Options& parent; 162 void (*func)(Options&, const std::string&);168 Func* func; 163 169 }; 164 170
Note: See TracChangeset for help on using the changeset viewer.