Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
Parse options string passed to file IO routines. More...
#include <FileOptions.hpp>
Public Member Functions | |
FileOptions (const char *option_string) | |
FileOptions (const FileOptions ©) | |
FileOptions & | operator= (const FileOptions ©) |
~FileOptions () | |
ErrorCode | get_null_option (const char *name) const |
Check for option with no value. | |
ErrorCode | get_toggle_option (const char *name, bool default_value, bool &value) const |
Check for option with boolean (true/false, yes/no) value. | |
ErrorCode | get_int_option (const char *name, int &value) const |
Check for option with an integer value. | |
ErrorCode | get_int_option (const char *name, int default_val, int &value) const |
Check for option with an integer value. Accept option with no value. | |
ErrorCode | get_real_option (const char *name, double &value) const |
Check for option with a double value. | |
ErrorCode | get_str_option (const char *name, std::string &value) const |
Check for option with any value. | |
ErrorCode | get_option (const char *name, std::string &value) const |
Check for option. | |
ErrorCode | match_option (const char *name, const char *const *values, int &index) const |
Check the string value of an option. | |
ErrorCode | match_option (const char *name, const char *value) const |
Check if an option matches a string value. | |
ErrorCode | get_ints_option (const char *name, std::vector< int > &values) const |
Check for option for which the value is a list of ints. | |
ErrorCode | get_reals_option (const char *name, std::vector< double > &values) const |
Check for option for which the value is a list of doubles. | |
ErrorCode | get_strs_option (const char *name, std::vector< std::string > &values) const |
Check for option for which the value is a list of strings. | |
unsigned | size () const |
bool | empty () const |
void | get_options (std::vector< std::string > &list) const |
bool | all_seen () const |
void | mark_all_seen () const |
ErrorCode | get_unseen_option (std::string &value) const |
Private Member Functions | |
ErrorCode | get_option (const char *name, const char *&value) const |
Check for option. | |
Static Private Member Functions | |
static bool | compare (const char *name, const char *option) |
Private Attributes | |
char * | mData |
std::vector< const char * > | mOptions |
std::vector< bool > | mSeen |
Parse options string passed to file IO routines.
This is a utility class used by file-IO-related code to parse the options string passed to Core::load_file and Core::write_file
Definition at line 37 of file FileOptions.hpp.
moab::FileOptions::FileOptions | ( | const char * | option_string | ) |
Definition at line 38 of file FileOptions.cpp.
References moab::DEFAULT_SEPARATOR, mData, mOptions, mSeen, and moab::strempty().
: mData( 0 ) { // if option string is null, just return if( !str ) return; // check if alternate separator is specified char separator[2] = { DEFAULT_SEPARATOR, '\0' }; if( *str == DEFAULT_SEPARATOR ) { ++str; if( strempty( str ) ) return; separator[0] = *str; ++str; } // don't bother allocating copy of input string if // input string is empty. if( !strempty( str ) ) { // tokenize at separator character mData = strdup( str ); for( char* i = strtok( mData, separator ); i; i = strtok( 0, separator ) ) if( !strempty( i ) ) // skip empty strings mOptions.push_back( i ); } mSeen.resize( mOptions.size(), false ); }
moab::FileOptions::FileOptions | ( | const FileOptions & | copy | ) |
Definition at line 67 of file FileOptions.cpp.
References mData, mOptions, and mSeen.
: mData( 0 ), mOptions( copy.mOptions.size() ) { if( !copy.mOptions.empty() ) { const char* last = copy.mOptions.back(); const char* endptr = last + strlen( last ) + 1; size_t len = endptr - copy.mData; mData = (char*)malloc( len ); memcpy( mData, copy.mData, len ); for( size_t i = 0; i < mOptions.size(); ++i ) mOptions[i] = mData + ( copy.mOptions[i] - copy.mData ); } mSeen = copy.mSeen; }
bool moab::FileOptions::all_seen | ( | ) | const |
Check if all options have been looked at
Definition at line 377 of file FileOptions.cpp.
References mSeen.
Referenced by moab::AdaptiveKDTree::build_tree(), moab::BVHTree::build_tree(), and moab::Core::load_file().
bool moab::FileOptions::compare | ( | const char * | name, |
const char * | option | ||
) | [static, private] |
Case-insensitive compare of name with option value.
Definition at line 357 of file FileOptions.cpp.
References moab::strempty().
Referenced by get_option(), and match_option().
bool moab::FileOptions::empty | ( | ) | const [inline] |
ErrorCode moab::FileOptions::get_int_option | ( | const char * | name, |
int & | value | ||
) | const |
Check for option with an integer value.
Check for an option with an integer value
name | The option name |
value | Output. The value. |
Definition at line 119 of file FileOptions.cpp.
References ErrorCode, get_option(), MB_SUCCESS, MB_TYPE_OUT_OF_RANGE, and moab::strempty().
Referenced by moab::NCHelperFV::init_mesh_vals(), moab::NCHelperEuler::init_mesh_vals(), moab::ReadParallel::load_file(), moab::ReadMCNP5::load_file(), moab::Core::load_file(), moab::Tqdcfr::load_file(), moab::WriteHDF5Parallel::parallel_create_file(), moab::Tree::parse_common_options(), moab::BVHTree::parse_options(), moab::AdaptiveKDTree::parse_options(), moab::ReadNC::parse_options(), moab::WriteNC::parse_options(), moab::ReadCGM::set_options(), moab::ReadHDF5::set_up_read(), moab::WriteSmf::write_file(), moab::WriteVtk::write_file(), moab::WriteGmsh::write_file(), moab::WriteSTL::write_file(), and moab::WriteHDF5::write_file().
{ const char* s; ErrorCode rval = get_option( name, s ); if( MB_SUCCESS != rval ) return rval; // empty string if( strempty( s ) ) return MB_TYPE_OUT_OF_RANGE; // parse value char* endptr; long int pval = strtol( s, &endptr, 0 ); if( !strempty( endptr ) ) // syntax error return MB_TYPE_OUT_OF_RANGE; // check for overflow (parsing long int, returning int) value = pval; if( pval != (long int)value ) return MB_TYPE_OUT_OF_RANGE; return MB_SUCCESS; }
ErrorCode moab::FileOptions::get_int_option | ( | const char * | name, |
int | default_val, | ||
int & | value | ||
) | const |
Check for option with an integer value. Accept option with no value.
Check for an option with an integer value. If the option is found but has no value specified, then pass back the user-specified default value.
: This function will not pass back the default_val, but will instead return MB_ENTITY_NOT_FOUND if the option is not specified at all. The default value is returned only when the option is specified, but is specified w/out a value.
name | The option name |
default_val | The default value for the option. |
value | Output. The value. |
Definition at line 141 of file FileOptions.cpp.
References ErrorCode, get_option(), MB_SUCCESS, MB_TYPE_OUT_OF_RANGE, and moab::strempty().
{ const char* s; ErrorCode rval = get_option( name, s ); if( MB_SUCCESS != rval ) return rval; // empty string if( strempty( s ) ) { value = default_val; return MB_SUCCESS; } // parse value char* endptr; long int pval = strtol( s, &endptr, 0 ); if( !strempty( endptr ) ) // syntax error return MB_TYPE_OUT_OF_RANGE; // check for overflow (parsing long int, returning int) value = pval; if( pval != (long int)value ) return MB_TYPE_OUT_OF_RANGE; return MB_SUCCESS; }
ErrorCode moab::FileOptions::get_ints_option | ( | const char * | name, |
std::vector< int > & | values | ||
) | const |
Check for option for which the value is a list of ints.
Check for an option which is an int list. The value is expected to be a comma-separated list of int ranges, where an int range can be either a single integer value or a range of integer values separated by a dash ('-').
name | The option name |
values | Output. The list of integer values. |
Definition at line 167 of file FileOptions.cpp.
References EATSPACE, ErrorCode, get_option(), MB_SUCCESS, MB_TYPE_OUT_OF_RANGE, and moab::strempty().
Referenced by moab::ReadParallel::load_file(), moab::ReadNC::parse_options(), and moab::WriteNC::parse_options().
{ const char* s; ErrorCode rval = get_option( name, s ); if( MB_SUCCESS != rval ) return rval; // empty string if( strempty( s ) ) return MB_TYPE_OUT_OF_RANGE; // parse values while( !strempty( s ) ) { char* endptr; long int sval = strtol( s, &endptr, 0 ); #define EATSPACE( a ) \ while( ( *( a ) == ' ' || *( a ) == ',' ) && !strempty( a ) ) \ ( a )++; EATSPACE( endptr ); long int eval = sval; if( *endptr == '-' ) { endptr++; s = endptr; eval = strtol( s, &endptr, 0 ); EATSPACE( endptr ); } // check for overflow (parsing long int, returning int) int value = sval; if( sval != (long int)value ) return MB_TYPE_OUT_OF_RANGE; value = eval; if( eval != (long int)value ) return MB_TYPE_OUT_OF_RANGE; for( int i = sval; i <= eval; i++ ) values.push_back( i ); s = endptr; } return MB_SUCCESS; }
ErrorCode moab::FileOptions::get_null_option | ( | const char * | name | ) | const |
Check for option with no value.
Check for an option w/out a value.
name | The option name |
Definition at line 111 of file FileOptions.cpp.
References ErrorCode, get_option(), MB_SUCCESS, MB_TYPE_OUT_OF_RANGE, and moab::strempty().
Referenced by moab::ReadParallel::load_file(), moab::ReadHDF5::load_file(), moab::ReadSTL::load_file(), moab::Tqdcfr::load_file(), moab::ReadMCNP5::load_one_file(), moab::WriteHDF5Parallel::parallel_create_file(), moab::ReadDamsel::parse_options(), moab::ReadNC::parse_options(), moab::WriteNC::parse_options(), moab::ReadCGM::set_options(), moab::ReadHDF5::set_up_read(), moab::WriteVtk::write_file(), moab::WriteSTL::write_file(), moab::WriteHDF5::write_file(), moab::WriteNCDF::write_file(), and moab::WriteHDF5::write_file_impl().
{ const char* s; ErrorCode rval = get_option( name, s ); if( MB_SUCCESS != rval ) return rval; return strempty( s ) ? MB_SUCCESS : MB_TYPE_OUT_OF_RANGE; }
ErrorCode moab::FileOptions::get_option | ( | const char * | name, |
std::string & | value | ||
) | const |
Check for option.
Check for an option
name | The option name |
value | The option value, or an empty string if no value. |
Definition at line 282 of file FileOptions.cpp.
References ErrorCode, and MB_SUCCESS.
Referenced by get_int_option(), get_ints_option(), get_null_option(), get_real_option(), get_reals_option(), get_str_option(), get_strs_option(), moab::ReadParallel::load_file(), moab::ReadVtk::load_file(), moab::ReadSmf::load_file(), moab::Core::load_file(), moab::ReadHDF5::load_file_partial(), match_option(), and moab::ReadTetGen::open_file().
{ const char* s; ErrorCode rval = get_option( name, s ); if( MB_SUCCESS != rval ) return rval; value = s; return MB_SUCCESS; }
ErrorCode moab::FileOptions::get_option | ( | const char * | name, |
const char *& | value | ||
) | const [private] |
Check for option.
Check for an option
name | The option name |
value | The option value, or an empty string if no value. |
Definition at line 292 of file FileOptions.cpp.
References compare(), MB_ENTITY_NOT_FOUND, MB_SUCCESS, mOptions, and mSeen.
{ std::vector< const char* >::const_iterator i; for( i = mOptions.begin(); i != mOptions.end(); ++i ) { const char* opt = *i; if( compare( name, opt ) ) { value = opt + strlen( name ); // if compare returned true, next char after option // name must be either the null char or an equals symbol. if( *value == '=' ) ++value; mSeen[i - mOptions.begin()] = true; return MB_SUCCESS; } } return MB_ENTITY_NOT_FOUND; }
void moab::FileOptions::get_options | ( | std::vector< std::string > & | list | ) | const |
ErrorCode moab::FileOptions::get_real_option | ( | const char * | name, |
double & | value | ||
) | const |
Check for option with a double value.
Check for an option with a double value
name | The option name |
value | Output. The value. |
Definition at line 234 of file FileOptions.cpp.
References ErrorCode, get_option(), MB_SUCCESS, MB_TYPE_OUT_OF_RANGE, and moab::strempty().
Referenced by moab::ReadParallel::load_file(), moab::Tree::parse_common_options(), moab::AdaptiveKDTree::parse_options(), and moab::ReadCGM::set_options().
{ const char* s; ErrorCode rval = get_option( name, s ); if( MB_SUCCESS != rval ) return rval; // empty string if( strempty( s ) ) return MB_TYPE_OUT_OF_RANGE; // parse value char* endptr; value = strtod( s, &endptr ); if( !strempty( endptr ) ) // syntax error return MB_TYPE_OUT_OF_RANGE; return MB_SUCCESS; }
ErrorCode moab::FileOptions::get_reals_option | ( | const char * | name, |
std::vector< double > & | values | ||
) | const |
Check for option for which the value is a list of doubles.
Check for an option which is a double list. The value is expected to be a comma-separated list of double values
name | The option name |
values | Output. The list of double values. |
Definition at line 210 of file FileOptions.cpp.
References EATSPACE, ErrorCode, get_option(), MB_SUCCESS, MB_TYPE_OUT_OF_RANGE, and moab::strempty().
Referenced by moab::ReadNC::parse_options(), and moab::WriteNC::parse_options().
{ const char* s; ErrorCode rval = get_option( name, s ); if( MB_SUCCESS != rval ) return rval; // empty string if( strempty( s ) ) return MB_TYPE_OUT_OF_RANGE; // parse values while( !strempty( s ) ) { char* endptr; double sval = strtod( s, &endptr ); EATSPACE( endptr ); values.push_back( sval ); s = endptr; } return MB_SUCCESS; }
ErrorCode moab::FileOptions::get_str_option | ( | const char * | name, |
std::string & | value | ||
) | const |
Check for option with any value.
Check for an option with any value.
name | The option name |
value | Output. The value. |
Definition at line 272 of file FileOptions.cpp.
References ErrorCode, get_option(), MB_SUCCESS, MB_TYPE_OUT_OF_RANGE, and moab::strempty().
Referenced by moab::NCHelperHOMME::create_mesh(), moab::ReadParallel::load_file(), moab::ReadTetGen::load_file(), moab::ReadNCDF::load_file(), moab::Tqdcfr::load_file(), moab::WriteHDF5Parallel::parallel_create_file(), moab::Tree::parse_common_options(), moab::ReadHDF5::set_up_read(), and moab::ReadNCDF::update().
{ const char* s; ErrorCode rval = get_option( name, s ); if( MB_SUCCESS != rval ) return rval; if( strempty( s ) ) return MB_TYPE_OUT_OF_RANGE; value = s; return MB_SUCCESS; }
ErrorCode moab::FileOptions::get_strs_option | ( | const char * | name, |
std::vector< std::string > & | values | ||
) | const |
Check for option for which the value is a list of strings.
Check for an option which is a string list. The value is expected to be a comma-separated list of string values, with no embedded spaces or commas.
name | The option name |
values | Output. The list of string values. |
Definition at line 252 of file FileOptions.cpp.
References ErrorCode, get_option(), MB_SUCCESS, MB_TYPE_OUT_OF_RANGE, and moab::strempty().
Referenced by main(), moab::ReadNC::parse_options(), and moab::WriteNC::parse_options().
{ const char* s; ErrorCode rval = get_option( name, s ); if( MB_SUCCESS != rval ) return rval; // empty string if( strempty( s ) ) return MB_TYPE_OUT_OF_RANGE; // parse values char separator[3] = { ' ', ',', '\0' }; char* tmp_str = strdup( s ); for( char* i = strtok( tmp_str, separator ); i; i = strtok( 0, separator ) ) if( !strempty( i ) ) // skip empty strings values.push_back( std::string( i ) ); free( tmp_str ); return MB_SUCCESS; }
ErrorCode moab::FileOptions::get_toggle_option | ( | const char * | name, |
bool | default_value, | ||
bool & | value | ||
) | const |
Check for option with boolean (true/false, yes/no) value.
Check for an option with a true/false value. Allowable values are "true", "false", "yes", "no", "1", "0", "on", "off".
name | The option name |
default_value | The value to return if the option is not specified. |
value | The resulting value. This argument is set to the passed default value if the option is not found. |
Definition at line 333 of file FileOptions.cpp.
References ErrorCode, match_option(), MB_ENTITY_NOT_FOUND, MB_SUCCESS, and MB_TYPE_OUT_OF_RANGE.
Referenced by moab::Tree::parse_common_options(), moab::AdaptiveKDTree::parse_options(), and moab::ReadHDF5::set_up_read().
{ static const char* values[] = { "true", "yes", "1", "on", "false", "no", "0", "off", 0 }; const int num_true = 4; int index; ErrorCode result = match_option( name, values, index ); if( result == MB_SUCCESS ) { value = index < num_true; } else if( result == MB_ENTITY_NOT_FOUND ) { value = default_value; result = MB_SUCCESS; } else { result = MB_TYPE_OUT_OF_RANGE; } return result; }
ErrorCode moab::FileOptions::get_unseen_option | ( | std::string & | value | ) | const |
Get first unseen option
Definition at line 388 of file FileOptions.cpp.
References MB_ENTITY_NOT_FOUND, MB_SUCCESS, mOptions, and mSeen.
Referenced by moab::Core::load_file().
{ std::vector< bool >::iterator i = std::find( mSeen.begin(), mSeen.end(), false ); if( i == mSeen.end() ) { name.clear(); return MB_ENTITY_NOT_FOUND; } const char* opt = mOptions[i - mSeen.begin()]; const char* end = strchr( opt, '=' ); name = end ? std::string( opt, end - opt ) : std::string( opt ); return MB_SUCCESS; }
void moab::FileOptions::mark_all_seen | ( | ) | const |
Mark all options as seen. USed for non-root procs during bcast-delete read
Definition at line 382 of file FileOptions.cpp.
References mOptions, and mSeen.
Referenced by moab::ReadParallel::load_file(), moab::ReadCGNS::process_options(), and moab::ReadTemplate::process_options().
ErrorCode moab::FileOptions::match_option | ( | const char * | name, |
const char *const * | values, | ||
int & | index | ||
) | const |
Check the string value of an option.
Check which of a list of possible values a string option contains.
name | The option name |
values | A NULL-terminated array of C-style strings enumerating the possible option values. |
index | Output: The index into values for the option value. |
values
array. Definition at line 320 of file FileOptions.cpp.
References compare(), ErrorCode, get_option(), and MB_SUCCESS.
Referenced by get_toggle_option(), moab::ReadParallel::load_file(), moab::ReadHDF5::load_file_partial(), match_option(), moab::ReadDamsel::parse_options(), moab::ReadNC::parse_options(), moab::WriteNC::parse_options(), moab::ReadCGM::set_options(), moab::ReadHDF5::set_up_read(), and moab::WriteHDF5::write_file_impl().
{ const char* optval; ErrorCode rval = get_option( name, optval ); if( MB_SUCCESS != rval ) return rval; for( index = 0; values[index]; ++index ) if( compare( optval, values[index] ) ) return MB_SUCCESS; index = -1; return MB_FAILURE; }
ErrorCode moab::FileOptions::match_option | ( | const char * | name, |
const char * | value | ||
) | const |
Check if an option matches a string value.
Check if the value for an option is the passed string.
name | The option name |
value | The expected value. |
Definition at line 313 of file FileOptions.cpp.
References match_option().
{ int idx; const char* array[] = { value, NULL }; return match_option( name, array, idx ); }
FileOptions & moab::FileOptions::operator= | ( | const FileOptions & | copy | ) |
Definition at line 82 of file FileOptions.cpp.
References mData, mOptions, and mSeen.
{ // Check for self-assignment if( this == © ) return *this; free( mData ); mData = 0; mOptions.resize( copy.mOptions.size() ); if( !copy.mOptions.empty() ) { const char* last = copy.mOptions.back(); const char* endptr = last + strlen( last ) + 1; size_t len = endptr - copy.mData; mData = (char*)malloc( len ); memcpy( mData, copy.mData, len ); for( size_t i = 0; i < mOptions.size(); ++i ) mOptions[i] = mData + ( copy.mOptions[i] - copy.mData ); } mSeen = copy.mSeen; return *this; }
unsigned moab::FileOptions::size | ( | ) | const [inline] |
char* moab::FileOptions::mData [private] |
Definition at line 239 of file FileOptions.hpp.
Referenced by FileOptions(), operator=(), and ~FileOptions().
std::vector< const char* > moab::FileOptions::mOptions [private] |
Definition at line 240 of file FileOptions.hpp.
Referenced by FileOptions(), get_option(), get_options(), get_unseen_option(), mark_all_seen(), and operator=().
std::vector< bool > moab::FileOptions::mSeen [mutable, private] |
Definition at line 241 of file FileOptions.hpp.
Referenced by all_seen(), FileOptions(), get_option(), get_unseen_option(), mark_all_seen(), and operator=().