Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProgOptions.cpp File Reference
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <list>
#include <limits>
#include <set>
#include <algorithm>
#include <cassert>
#include <cstring>
#include "moab/MOABConfig.h"
#include "moab/ProgOptions.hpp"
#include "moab_mpi.h"
+ Include dependency graph for ProgOptions.cpp:

Go to the source code of this file.

Classes

class  ProgOpt
 

Macros

#define DECLARE_OPTION_TYPE(T)
 
#define DECLARE_VALUED_OPTION_TYPE(T)
 

Enumerations

enum  OptType {
  FLAG = 0 , INT , REAL , STRING ,
  INT_VECT
}
 

Functions

template<typename T >
static OptType get_opt_type ()
 
template<>
OptType get_opt_type< void > ()
 
template<>
OptType get_opt_type< int > ()
 
template<>
OptType get_opt_type< double > ()
 
template<>
OptType get_opt_type< std::string > ()
 
template<>
OptType get_opt_type< std::vector< int > > ()
 
static bool parse_int_list (const char *string, std::vector< int > &results)
 
static std::string do_rank_subst (const std::string &s)
 

Macro Definition Documentation

◆ DECLARE_OPTION_TYPE

#define DECLARE_OPTION_TYPE (   T)
Value:
template void ProgOptions::addOpt< T >( const std::string&, const std::string&, T*, int ); \ template bool ProgOptions::getOpt< T >( const std::string&, T* );

Definition at line 1029 of file ProgOptions.cpp.

◆ DECLARE_VALUED_OPTION_TYPE

#define DECLARE_VALUED_OPTION_TYPE (   T)
Value:
DECLARE_OPTION_TYPE( T ) \ template void ProgOptions::getOptAllArgs< T >( const std::string&, std::vector< T >& ); \ template void ProgOptions::addRequiredArg< T >( const std::string&, const std::string&, T*, int ); \ template void ProgOptions::addOptionalArgs< T >( unsigned, const std::string&, const std::string&, int ); \ template T ProgOptions::getReqArg< T >( const std::string& ); \ template void ProgOptions::getArgs< T >( const std::string&, std::vector< T >& );

Definition at line 1033 of file ProgOptions.cpp.

Enumeration Type Documentation

◆ OptType

enum OptType
Enumerator
FLAG 
INT 
REAL 
STRING 
INT_VECT 

Definition at line 19 of file ProgOptions.cpp.

20 { 21  FLAG = 0, 22  INT, 23  REAL, 24  STRING, 25  INT_VECT 26 };

Function Documentation

◆ do_rank_subst()

static std::string do_rank_subst ( const std::string &  s)
static

Definition at line 459 of file ProgOptions.cpp.

460 { 461 #ifndef MOAB_HAVE_MPI 462  return s; 463 #else 464  int rank, size; 465  if( MPI_SUCCESS != MPI_Comm_rank( MPI_COMM_WORLD, &rank ) || MPI_SUCCESS != MPI_Comm_size( MPI_COMM_WORLD, &size ) ) 466  return s; 467  int width = 1; 468  while( size > 10 ) 469  { 470  size /= 10; 471  width++; 472  } 473  474  size_t j = s.find( '%' ); 475  if( j == std::string::npos ) return s; 476  477  std::ostringstream st; 478  st << std::setfill( '0' ); 479  st << s.substr( 0, j ); 480  st << rank; 481  482  size_t i; 483  while( ( i = s.find( '%', j + 1 ) ) != std::string::npos ) 484  { 485  st << s.substr( j, i - j ); 486  st << std::setw( width ) << rank; 487  j = i; 488  } 489  st << s.substr( j + 1 ); 490  return st.str(); 491 #endif 492 }

References size.

Referenced by ProgOptions::evaluate().

◆ get_opt_type()

template<typename T >
static OptType get_opt_type ( )
inlinestatic

◆ get_opt_type< double >()

template<>
OptType get_opt_type< double > ( )

Definition at line 42 of file ProgOptions.cpp.

43 { 44  return REAL; 45 }

References REAL.

◆ get_opt_type< int >()

template<>
OptType get_opt_type< int > ( )

Definition at line 37 of file ProgOptions.cpp.

38 { 39  return INT; 40 }

References INT.

◆ get_opt_type< std::string >()

template<>
OptType get_opt_type< std::string > ( )

Definition at line 47 of file ProgOptions.cpp.

48 { 49  return STRING; 50 }

References get_opt_type< std::string >(), and STRING.

Referenced by get_opt_type< std::string >().

◆ get_opt_type< std::vector< int > >()

template<>
OptType get_opt_type< std::vector< int > > ( )

Definition at line 52 of file ProgOptions.cpp.

53 { 54  return INT_VECT; 55 }

References INT_VECT.

◆ get_opt_type< void >()

template<>
OptType get_opt_type< void > ( )

Definition at line 32 of file ProgOptions.cpp.

33 { 34  return FLAG; 35 }

References FLAG.

◆ parse_int_list()

static bool parse_int_list ( const char *  string,
std::vector< int > &  results 
)
static

Definition at line 409 of file ProgOptions.cpp.

410 { 411  bool okay = true; 412  char* mystr = strdup( string ); 413  for( const char* ptr = strtok( mystr, ", \t" ); ptr; ptr = strtok( 0, ", \t" ) ) 414  { 415  char* endptr; 416  long val = strtol( ptr, &endptr, 0 ); 417  if( endptr == ptr ) 418  { 419  std::cerr << "Not an integer: \"" << ptr << '"' << std::endl; 420  okay = false; 421  break; 422  } 423  424  long val2 = val; 425  if( *endptr == '-' ) 426  { 427  const char* sptr = endptr + 1; 428  val2 = strtol( sptr, &endptr, 0 ); 429  if( endptr == sptr ) 430  { 431  std::cerr << "Not an integer: \"" << sptr << '"' << std::endl; 432  okay = false; 433  break; 434  } 435  if( val2 < val ) 436  { 437  std::cerr << "Invalid id range: \"" << ptr << '"' << std::endl; 438  okay = false; 439  break; 440  } 441  } 442  443  if( *endptr ) 444  { 445  okay = false; 446  break; 447  } 448  449  for( ; val <= val2; ++val ) 450  results.push_back( (int)val ); 451  } 452  453  free( mystr ); 454  return okay; 455 }

Referenced by ProgOptions::evaluate().