MOAB: Mesh Oriented datABase  (version 5.4.1)
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 dependency graph for ProgOptions.cpp:

Go to the source code of this file.

Classes

class  ProgOpt

Defines

#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)

Define Documentation

#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.

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

enum OptType
Enumerator:
FLAG 
INT 
REAL 
STRING 
INT_VECT 

Definition at line 19 of file ProgOptions.cpp.

{
    FLAG = 0,
    INT,
    REAL,
    STRING,
    INT_VECT
};

Function Documentation

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

Definition at line 459 of file ProgOptions.cpp.

References MPI_COMM_WORLD, rank, and size.

Referenced by ProgOptions::evaluate().

{
#ifndef MOAB_HAVE_MPI
    return s;
#else
    int rank, size;
    if( MPI_SUCCESS != MPI_Comm_rank( MPI_COMM_WORLD, &rank ) || MPI_SUCCESS != MPI_Comm_size( MPI_COMM_WORLD, &size ) )
        return s;
    int width = 1;
    while( size > 10 )
    {
        size /= 10;
        width++;
    }

    size_t j = s.find( '%' );
    if( j == std::string::npos ) return s;

    std::ostringstream st;
    st << std::setfill( '0' );
    st << s.substr( 0, j );
    st << rank;

    size_t i;
    while( ( i = s.find( '%', j + 1 ) ) != std::string::npos )
    {
        st << s.substr( j, i - j );
        st << std::setw( width ) << rank;
        j = i;
    }
    st << s.substr( j + 1 );
    return st.str();
#endif
}
template<typename T >
static OptType get_opt_type ( ) [inline, static]
template<>
OptType get_opt_type< double > ( )

Definition at line 42 of file ProgOptions.cpp.

References REAL.

{
    return REAL;
}
template<>
OptType get_opt_type< int > ( )

Definition at line 37 of file ProgOptions.cpp.

References INT.

{
    return INT;
}
template<>
OptType get_opt_type< std::string > ( )

Definition at line 47 of file ProgOptions.cpp.

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

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

{
    return STRING;
}
template<>
OptType get_opt_type< std::vector< int > > ( )

Definition at line 52 of file ProgOptions.cpp.

References INT_VECT.

{
    return INT_VECT;
}
template<>
OptType get_opt_type< void > ( )

Definition at line 32 of file ProgOptions.cpp.

References FLAG.

{
    return FLAG;
}
static bool parse_int_list ( const char *  string,
std::vector< int > &  results 
) [static]

Definition at line 409 of file ProgOptions.cpp.

Referenced by ProgOptions::evaluate().

{
    bool okay   = true;
    char* mystr = strdup( string );
    for( const char* ptr = strtok( mystr, ", \t" ); ptr; ptr = strtok( 0, ", \t" ) )
    {
        char* endptr;
        long val = strtol( ptr, &endptr, 0 );
        if( endptr == ptr )
        {
            std::cerr << "Not an integer: \"" << ptr << '"' << std::endl;
            okay = false;
            break;
        }

        long val2 = val;
        if( *endptr == '-' )
        {
            const char* sptr = endptr + 1;
            val2             = strtol( sptr, &endptr, 0 );
            if( endptr == sptr )
            {
                std::cerr << "Not an integer: \"" << sptr << '"' << std::endl;
                okay = false;
                break;
            }
            if( val2 < val )
            {
                std::cerr << "Invalid id range: \"" << ptr << '"' << std::endl;
                okay = false;
                break;
            }
        }

        if( *endptr )
        {
            okay = false;
            break;
        }

        for( ; val <= val2; ++val )
            results.push_back( (int)val );
    }

    free( mystr );
    return okay;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines