Changeset 1374 in 3DVCSoftware for branches/HTM-15.2-dev/source/Lib/TAppCommon/program_options_lite.h
- Timestamp:
- 9 Nov 2015, 21:13:05 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HTM-15.2-dev/source/Lib/TAppCommon/program_options_lite.h
r1362 r1374 77 77 struct ErrorReporter 78 78 { 79 #if NH_MV _SEI79 #if NH_MV 80 80 ErrorReporter() : is_errored(0), output_on_unknow_parameter(true) {} 81 81 #else … … 86 86 virtual std::ostream& warn(const std::string& where); 87 87 bool is_errored; 88 #if NH_MV _SEI88 #if NH_MV 89 89 bool output_on_unknow_parameter; 90 90 #endif … … 104 104 { 105 105 #if NH_MV 106 #if NH_MV_SEI107 106 OptionBase(const std::string& name, const std::string& desc, bool duplicate = false, std::vector< int > maxdim = std::vector< int >(0) ) 108 107 : opt_string(name), opt_desc(desc), opt_duplicate(duplicate), max_dim( maxdim ) 109 108 #else 110 OptionBase(const std::string& name, const std::string& desc, bool duplicate = false)111 : opt_string(name), opt_desc(desc), opt_duplicate(duplicate)112 #endif113 #else114 109 OptionBase(const std::string& name, const std::string& desc) 115 110 : opt_string(name), opt_desc(desc) … … 120 115 121 116 /* parse argument arg, to obtain a value for the option */ 122 #if NH_MV _SEI117 #if NH_MV 123 118 virtual void parse(const std::string& arg, const std::vector<int>& idcs, ErrorReporter&) = 0; 124 119 … … 220 215 #if NH_MV 221 216 bool opt_duplicate; 222 #if NH_MV_SEI223 217 std::vector<int> max_dim; 224 #endif225 218 #endif 226 219 }; … … 231 224 { 232 225 #if NH_MV 233 #if NH_MV_SEI234 226 Option(const std::string& name, T& storage, T default_val, const std::string& desc, bool duplicate = false, std::vector< int > maxdim = std::vector< int >(0) ) 235 227 : OptionBase(name, desc, duplicate, maxdim), opt_storage(storage), opt_default_val(default_val) 236 228 #else 237 Option(const std::string& name, T& storage, T default_val, const std::string& desc, bool duplicate = false)238 : OptionBase(name, desc, duplicate), opt_storage(storage), opt_default_val(default_val)239 #endif240 #else241 229 Option(const std::string& name, T& storage, T default_val, const std::string& desc) 242 230 : OptionBase(name, desc), opt_storage(storage), opt_default_val(default_val) … … 244 232 {} 245 233 246 #if NH_MV _SEI234 #if NH_MV 247 235 void parse(const std::string& arg, const std::vector<int>& idcs, ErrorReporter&); 248 236 #else … … 262 250 template<typename T> 263 251 inline void 264 #if NH_MV _SEI252 #if NH_MV 265 253 Option<T>::parse(const std::string& arg, const std::vector<int>& idcs, ErrorReporter&) 266 254 #else … … 268 256 #endif 269 257 { 270 #if NH_MV _SEI258 #if NH_MV 271 259 assert( idcs.size() == 0 ); 272 260 #endif … … 288 276 template<> 289 277 inline void 290 #if NH_MV _SEI278 #if NH_MV 291 279 Option<std::string>::parse(const std::string& arg, const std::vector<int>& idcs, ErrorReporter&) 292 #else 293 Option<std::string>::parse(const std::string& arg, ErrorReporter&) 294 #endif 295 { 296 #if NH_MV_SEI 280 { 297 281 assert( idcs.size() == 0 ); 298 #endif299 282 opt_storage = arg; 300 283 } 284 #else 285 Option<std::string>::parse(const std::string& arg, ErrorReporter&) 286 { 287 opt_storage = arg; 288 } 289 #endif 301 290 302 291 #if NH_MV 303 292 template<> 304 293 inline void 305 #if NH_MV_SEI306 294 Option<char*>::parse(const std::string& arg, const std::vector<int>& idcs, ErrorReporter&) 307 #else 308 Option<char*>::parse(const std::string& arg, ErrorReporter&) 309 #endif 310 { 311 #if NH_MV_SEI 295 { 312 296 assert( idcs.size() == 0 ); 313 #endif314 297 opt_storage = arg.empty() ? NULL : strdup(arg.c_str()) ; 315 298 } 316 299 317 #if !NH_MV_SEI318 319 template<>320 inline void321 Option< std::vector<char*> >::parse(const std::string& arg, ErrorReporter&)322 {323 opt_storage.clear();324 325 char* pcStart = (char*) arg.data();326 char* pcEnd = strtok (pcStart," ");327 328 while (pcEnd != NULL)329 {330 size_t uiStringLength = pcEnd - pcStart;331 char* pcNewStr = (char*) malloc( uiStringLength + 1 );332 strncpy( pcNewStr, pcStart, uiStringLength);333 pcNewStr[uiStringLength] = '\0';334 pcStart = pcEnd+1;335 pcEnd = strtok (NULL, " ,.-");336 opt_storage.push_back( pcNewStr );337 }338 }339 #endif340 341 300 template<> 342 301 inline void 343 #if NH_MV_SEI344 302 Option< std::vector<double> >::parse(const std::string& arg, const std::vector< int > & idcs, ErrorReporter&) 345 #else 346 Option< std::vector<double> >::parse(const std::string& arg, ErrorReporter&) 347 #endif 348 { 349 #if NH_MV_SEI 303 { 350 304 assert( idcs.size() == 0 ); 351 #endif352 305 char* pcNextStart = (char*) arg.data(); 353 306 char* pcEnd = pcNextStart + arg.length(); … … 383 336 384 337 385 #if NH_MV_SEI386 338 template<> 387 339 inline void … … 404 356 xParseVec ( arg, opt_storage[ idcs[0] ][ idcs[1] ] ); 405 357 }; 406 #if SEI_DRI_F0169 358 407 359 template<> 408 360 inline void … … 438 390 while( (pcNextStart < pcEnd) && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++; 439 391 pcOldStart = pcNextStart; 440 441 } 442 443 392 } 444 393 } 445 #endif 446 #else 447 template<> 448 inline void 449 Option< std::vector<int> >::parse(const std::string& arg, ErrorReporter&) 450 { 451 opt_storage.clear(); 452 453 454 char* pcNextStart = (char*) arg.data(); 455 char* pcEnd = pcNextStart + arg.length(); 456 457 char* pcOldStart = 0; 458 459 size_t iIdx = 0; 460 461 462 while (pcNextStart < pcEnd) 463 { 464 465 if ( iIdx < opt_storage.size() ) 466 { 467 opt_storage[iIdx] = (int) strtol(pcNextStart, &pcNextStart,10); 468 } 469 else 470 { 471 opt_storage.push_back( (int) strtol(pcNextStart, &pcNextStart,10)) ; 472 } 473 iIdx++; 474 if ( errno == ERANGE || (pcNextStart == pcOldStart) ) 475 { 476 std::cerr << "Error Parsing Integers: `" << arg << "'" << std::endl; 477 exit(EXIT_FAILURE); 478 }; 479 while( (pcNextStart < pcEnd) && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++; 480 pcOldStart = pcNextStart; 481 } 482 } 483 #endif 484 485 #if NH_MV_SEI 394 486 395 487 396 template<> … … 530 439 xParseVec( arg, opt_storage[idcs[0]][idcs[1]] ); 531 440 }; 532 #else533 template<>534 inline void535 Option< std::vector<bool> >::parse(const std::string& arg, ErrorReporter&)536 {537 char* pcNextStart = (char*) arg.data();538 char* pcEnd = pcNextStart + arg.length();539 540 char* pcOldStart = 0;541 542 size_t iIdx = 0;543 544 while (pcNextStart < pcEnd)545 {546 if ( iIdx < opt_storage.size() )547 {548 opt_storage[iIdx] = (strtol(pcNextStart, &pcNextStart,10) != 0);549 }550 else551 {552 opt_storage.push_back(strtol(pcNextStart, &pcNextStart,10) != 0) ;553 }554 iIdx++;555 556 if ( errno == ERANGE || (pcNextStart == pcOldStart) )557 {558 std::cerr << "Error Parsing Bools: `" << arg << "'" << std::endl;559 exit(EXIT_FAILURE);560 };561 while( (pcNextStart < pcEnd) && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++;562 pcOldStart = pcNextStart;563 }564 }565 #endif566 441 #endif 567 442 /** Option class for argument handling using a user provided function */ … … 574 449 {} 575 450 576 #if NH_MV _SEI451 #if NH_MV 577 452 void parse(const std::string& arg, const std::vector<int>& idcs, ErrorReporter& error_reporter) 578 453 #else … … 650 525 operator()(const std::string& name, std::vector<T>& storage, T default_val, unsigned uiMaxNum, const std::string& desc = "" ) 651 526 { 652 #if NH_MV_SEI653 527 std::vector<T> defVal; 654 528 defVal.resize( uiMaxNum, default_val ); … … 678 552 return *this; 679 553 } 680 #else681 std::string cNameBuffer;682 std::string cDescBuffer;683 684 storage.resize(uiMaxNum);685 for ( unsigned int uiK = 0; uiK < uiMaxNum; uiK++ )686 {687 cNameBuffer .resize( name.size() + 10 );688 cDescBuffer.resize( desc.size() + 10 );689 690 Bool duplicate = (uiK != 0);691 // isn't there are sprintf function for string??692 sprintf((char*) cNameBuffer.c_str() ,name.c_str(),uiK,uiK);693 694 if ( !duplicate )695 {696 sprintf((char*) cDescBuffer.c_str(),desc.c_str(),uiK,uiK);697 }698 699 cNameBuffer.resize( std::strlen(cNameBuffer.c_str()) );700 cDescBuffer.resize( std::strlen(cDescBuffer.c_str()) );701 702 703 parent.addOption(new Option<T>( cNameBuffer, (storage[uiK]), default_val, cDescBuffer, duplicate ));704 }705 706 return *this;707 }708 #endif709 554 #endif 710 555 /**
Note: See TracChangeset for help on using the changeset viewer.