[MOAB-dev] r3844 - MOAB/trunk/src
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Wed May 5 13:29:48 CDT 2010
Author: kraftche
Date: 2010-05-05 13:29:48 -0500 (Wed, 05 May 2010)
New Revision: 3844
Modified:
MOAB/trunk/src/FileOptions.cpp
MOAB/trunk/src/FileOptions.hpp
Log:
add support for option with optional integer value
Modified: MOAB/trunk/src/FileOptions.cpp
===================================================================
--- MOAB/trunk/src/FileOptions.cpp 2010-05-05 15:56:54 UTC (rev 3843)
+++ MOAB/trunk/src/FileOptions.cpp 2010-05-05 18:29:48 UTC (rev 3844)
@@ -136,6 +136,35 @@
return MB_SUCCESS;
}
+ErrorCode FileOptions::get_int_option( const char* name,
+ int default_val,
+ int& value ) const
+{
+ 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 FileOptions::get_ints_option( const char* name,
std::vector<int>& values) const
{
Modified: MOAB/trunk/src/FileOptions.hpp
===================================================================
--- MOAB/trunk/src/FileOptions.hpp 2010-05-05 15:56:54 UTC (rev 3843)
+++ MOAB/trunk/src/FileOptions.hpp 2010-05-05 18:29:48 UTC (rev 3844)
@@ -70,6 +70,26 @@
*/
ErrorCode get_int_option( const char* name, int& value ) const;
+ /**\brief Check for option with an integer value. Accept option with no value.
+ *
More information about the moab-dev
mailing list