Changeset 608 in 3DVCSoftware for trunk/source/Lib/TAppCommon/program_options_lite.h
- Timestamp:
- 1 Sep 2013, 22:47:26 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TAppCommon/program_options_lite.h
r56 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 34 34 #include <sstream> 35 35 #include <string> 36 #include <vector>37 36 #include <list> 38 37 #include <map> 39 #include <stdlib.h> 38 #include "../TLibCommon/TypeDef.h" 39 40 #if H_MV 41 #include <vector> 40 42 #include <errno.h> 41 43 #include <cstring> 42 #include <math.h>43 44 44 45 #ifdef WIN32 45 46 #define strdup _strdup 46 47 #endif 47 48 #endif 48 49 //! \ingroup TAppCommon 49 50 //! \{ … … 56 57 struct Options; 57 58 59 struct ParseFailure : public std::exception 60 { 61 ParseFailure(std::string arg0, std::string val0) throw() 62 : arg(arg0), val(val0) 63 {} 64 65 ~ParseFailure() throw() {}; 66 67 std::string arg; 68 std::string val; 69 70 const char* what() const throw() { return "Option Parse Failure"; } 71 }; 72 58 73 void doHelp(std::ostream& out, Options& opts, unsigned columns = 80); 59 74 unsigned parseGNU(Options& opts, unsigned argc, const char* argv[]); … … 71 86 struct OptionBase 72 87 { 88 #if H_MV 89 OptionBase(const std::string& name, const std::string& desc, bool duplicate = false) 90 : opt_string(name), opt_desc(desc), opt_duplicate(duplicate) 91 #else 73 92 OptionBase(const std::string& name, const std::string& desc) 74 93 : opt_string(name), opt_desc(desc) 94 #endif 75 95 {}; 76 96 … … 84 104 std::string opt_string; 85 105 std::string opt_desc; 106 #if H_MV 107 bool opt_duplicate; 108 #endif 86 109 }; 87 110 … … 90 113 struct Option : public OptionBase 91 114 { 115 #if H_MV 116 Option(const std::string& name, T& storage, T default_val, const std::string& desc, bool duplicate = false) 117 : OptionBase(name, desc, duplicate), opt_storage(storage), opt_default_val(default_val) 118 #else 92 119 Option(const std::string& name, T& storage, T default_val, const std::string& desc) 93 120 : OptionBase(name, desc), opt_storage(storage), opt_default_val(default_val) 121 #endif 94 122 {} 95 123 … … 111 139 { 112 140 std::istringstream arg_ss (arg,std::istringstream::in); 113 arg_ss >> opt_storage; 141 arg_ss.exceptions(std::ios::failbit); 142 try 143 { 144 arg_ss >> opt_storage; 145 } 146 catch (...) 147 { 148 throw ParseFailure(opt_string, arg); 149 } 114 150 } 115 151 … … 122 158 opt_storage = arg; 123 159 } 124 160 161 #if H_MV 125 162 template<> 126 163 inline void … … 258 295 } 259 296 } 260 297 #endif 261 298 /** Option class for argument handling using a user provided function */ 262 299 struct OptionFunc : public OptionBase … … 333 370 } 334 371 372 #if H_MV 335 373 template<typename T> 336 374 OptionSpecific& … … 338 376 { 339 377 std::string cNameBuffer; 340 std::string cDesc riptionBuffer;378 std::string cDescBuffer; 341 379 342 380 cNameBuffer .resize( name.size() + 10 ); 343 cDesc riptionBuffer.resize( desc.size() + 10 );381 cDescBuffer.resize( desc.size() + 10 ); 344 382 345 383 storage.resize(uiMaxNum); 346 384 for ( unsigned int uiK = 0; uiK < uiMaxNum; uiK++ ) 347 385 { 386 Bool duplicate = (uiK != 0); 348 387 // isn't there are sprintf function for string?? 349 388 sprintf((char*) cNameBuffer.c_str() ,name.c_str(),uiK,uiK); 350 sprintf((char*) cDescriptionBuffer.c_str(),desc.c_str(),uiK,uiK); 351 352 parent.addOption(new Option<T>( cNameBuffer, (storage[uiK]), default_val, cDescriptionBuffer )); 389 390 if ( !duplicate ) 391 { 392 sprintf((char*) cDescBuffer.c_str(),desc.c_str(),uiK,uiK); 393 } 394 395 cNameBuffer.resize( std::strlen(cNameBuffer.c_str()) ); 396 cDescBuffer.resize( std::strlen(cDescBuffer.c_str()) ); 397 398 399 parent.addOption(new Option<T>( cNameBuffer, (storage[uiK]), default_val, cDescBuffer, duplicate )); 353 400 } 354 401 355 402 return *this; 356 403 } 357 404 #endif 358 405 /** 359 406 * Add option described by name to the parent Options list,
Note: See TracChangeset for help on using the changeset viewer.