Ignore:
Timestamp:
9 Nov 2015, 21:13:05 (8 years ago)
Author:
tech
Message:

Macro cleanups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HTM-15.2-dev/source/Lib/TAppCommon/program_options_lite.h

    r1362 r1374  
    7777    struct ErrorReporter
    7878    {
    79 #if NH_MV_SEI
     79#if NH_MV
    8080      ErrorReporter() : is_errored(0), output_on_unknow_parameter(true)  {}
    8181#else
     
    8686      virtual std::ostream& warn(const std::string& where);
    8787      bool is_errored;
    88 #if NH_MV_SEI
     88#if NH_MV
    8989      bool output_on_unknow_parameter;
    9090#endif
     
    104104    {
    105105#if NH_MV     
    106 #if NH_MV_SEI     
    107106      OptionBase(const std::string& name, const std::string& desc, bool duplicate = false, std::vector< int > maxdim = std::vector< int >(0) )
    108107        : opt_string(name), opt_desc(desc), opt_duplicate(duplicate), max_dim( maxdim )
    109108#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 #endif
    113 #else
    114109      OptionBase(const std::string& name, const std::string& desc)
    115110      : opt_string(name), opt_desc(desc)
     
    120115
    121116      /* parse argument arg, to obtain a value for the option */
    122 #if NH_MV_SEI
     117#if NH_MV
    123118      virtual void parse(const std::string& arg, const std::vector<int>& idcs,  ErrorReporter&) = 0;
    124119     
     
    220215#if NH_MV
    221216      bool        opt_duplicate;
    222 #if NH_MV_SEI
    223217      std::vector<int> max_dim;
    224 #endif
    225218#endif
    226219    };
     
    231224    {
    232225#if NH_MV
    233 #if NH_MV_SEI
    234226      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) )
    235227        : OptionBase(name, desc, duplicate, maxdim), opt_storage(storage), opt_default_val(default_val)
    236228#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 #endif
    240 #else
    241229      Option(const std::string& name, T& storage, T default_val, const std::string& desc)
    242230      : OptionBase(name, desc), opt_storage(storage), opt_default_val(default_val)
     
    244232      {}
    245233
    246 #if NH_MV_SEI
     234#if NH_MV
    247235      void parse(const std::string& arg, const std::vector<int>& idcs, ErrorReporter&);
    248236#else
     
    262250    template<typename T>
    263251    inline void
    264 #if NH_MV_SEI
     252#if NH_MV
    265253    Option<T>::parse(const std::string& arg, const std::vector<int>& idcs, ErrorReporter&)
    266254#else
     
    268256#endif
    269257    {
    270 #if NH_MV_SEI
     258#if NH_MV
    271259      assert( idcs.size() == 0 );
    272260#endif
     
    288276    template<>
    289277    inline void
    290 #if NH_MV_SEI
     278#if NH_MV
    291279    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    {
    297281      assert( idcs.size() == 0 );
    298 #endif
    299282      opt_storage = arg;
    300283    }
     284#else
     285    Option<std::string>::parse(const std::string& arg, ErrorReporter&)
     286    {
     287      opt_storage = arg;
     288    }
     289#endif
    301290
    302291#if NH_MV   
    303292    template<>
    304293    inline void
    305 #if NH_MV_SEI
    306294      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    {
    312296      assert( idcs.size() == 0 );
    313 #endif
    314297      opt_storage = arg.empty() ? NULL : strdup(arg.c_str()) ;
    315298    }
    316299
    317 #if !NH_MV_SEI
    318 
    319     template<>
    320     inline void
    321       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 #endif
    340 
    341300    template<>   
    342301    inline void
    343 #if NH_MV_SEI
    344302      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    {
    350304      assert( idcs.size() == 0 );
    351 #endif
    352305      char* pcNextStart = (char*) arg.data();
    353306      char* pcEnd = pcNextStart + arg.length();
     
    383336
    384337
    385 #if NH_MV_SEI
    386338    template<>
    387339    inline void
     
    404356      xParseVec ( arg, opt_storage[ idcs[0] ][ idcs[1] ] );
    405357    };
    406 #if SEI_DRI_F0169
     358
    407359    template<>
    408360    inline void
     
    438390            while( (pcNextStart < pcEnd) && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++; 
    439391            pcOldStart = pcNextStart;
    440 
    441         }       
    442 
    443 
     392        }
    444393    }
    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
    486395
    487396    template<>
     
    530439      xParseVec( arg, opt_storage[idcs[0]][idcs[1]] );
    531440    };
    532 #else
    533     template<>
    534     inline void
    535       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         else
    551         {
    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 #endif
    566441#endif
    567442    /** Option class for argument handling using a user provided function */
     
    574449      {}
    575450
    576 #if NH_MV_SEI
     451#if NH_MV
    577452      void parse(const std::string& arg, const std::vector<int>& idcs, ErrorReporter& error_reporter)
    578453#else
     
    650525        operator()(const std::string& name, std::vector<T>& storage, T default_val, unsigned uiMaxNum, const std::string& desc = "" )
    651526      {
    652 #if NH_MV_SEI
    653527        std::vector<T> defVal;
    654528        defVal.resize( uiMaxNum, default_val );
     
    678552        return *this;
    679553      }
    680 #else
    681         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 #endif
    709554#endif
    710555      /**
Note: See TracChangeset for help on using the changeset viewer.