[cgma-dev] r3547 - cgm/trunk/geom/parallel
hongjun at mcs.anl.gov
hongjun at mcs.anl.gov
Thu Feb 18 15:29:20 CST 2010
Author: hongjun
Date: 2010-02-18 15:29:20 -0600 (Thu, 18 Feb 2010)
New Revision: 3547
Added:
cgm/trunk/geom/parallel/CGMFileOptions.cpp
cgm/trunk/geom/parallel/CGMFileOptions.hpp
Removed:
cgm/trunk/geom/parallel/FileOptions.cpp
cgm/trunk/geom/parallel/FileOptions.hpp
Modified:
cgm/trunk/geom/parallel/Makefile.am
cgm/trunk/geom/parallel/ParallelGeomTool.cpp
Log:
o "FileOptions" name is changed to "CGMFileOptions" to avoid multiple definitions for linking both CGM and MOAB
Added: cgm/trunk/geom/parallel/CGMFileOptions.cpp
===================================================================
--- cgm/trunk/geom/parallel/CGMFileOptions.cpp (rev 0)
+++ cgm/trunk/geom/parallel/CGMFileOptions.cpp 2010-02-18 21:29:20 UTC (rev 3547)
@@ -0,0 +1,463 @@
+/**\file CGMFileOptions.cpp
+ *\ copied from MOAB
+ *\date 2009-06-11
+ */
+
+#include "CGMFileOptions.hpp"
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+const char DEFAULT_SEPARATOR = ';';
+
+static inline bool strempty( const char* s ) { return !*s; }
+
+CGMFileOptions::CGMFileOptions( const char* str )
+ : 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 );
+ }
+}
+
+CGMFileOptions::CGMFileOptions( const CGMFileOptions& copy ) :
+ 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);
+ }
+}
+
+CGMFileOptions& CGMFileOptions::operator=( const CGMFileOptions& copy )
+{
+ 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);
+ }
+
+ return *this;
+}
+
+CGMFileOptions::~CGMFileOptions()
+{
+ free( mData );
+}
+
+CGMFOErrorCode CGMFileOptions::get_null_option( const char* name ) const
+{
+ const char* s;
+ CGMFOErrorCode rval = get_option( name, s );
+ if (FO_SUCCESS != rval)
+ return rval;
+ return strempty(s) ? FO_SUCCESS : FO_TYPE_OUT_OF_RANGE;
+}
+
+CGMFOErrorCode CGMFileOptions::get_int_option( const char* name, int& value ) const
+{
+ const char* s;
+ CGMFOErrorCode rval = get_option( name, s );
+ if (FO_SUCCESS != rval)
+ return rval;
+
+ // empty string
+ if (strempty(s))
+ return FO_TYPE_OUT_OF_RANGE;
+
+ // parse value
+ char* endptr;
+ long int pval = strtol( s, &endptr, 0 );
+ if (!strempty(endptr)) // syntax error
+ return FO_TYPE_OUT_OF_RANGE;
+
+ // check for overflow (parsing long int, returning int)
+ value = pval;
+ if (pval != (long int)value)
+ return FO_TYPE_OUT_OF_RANGE;
+
+ return FO_SUCCESS;
+}
+
+CGMFOErrorCode CGMFileOptions::get_ints_option( const char* name,
+ std::vector<int>& values) const
+{
+ const char* s;
+ CGMFOErrorCode rval = get_option( name, s );
+ if (FO_SUCCESS != rval)
+ return rval;
+
+ // empty string
+ if (strempty(s))
+ return FO_TYPE_OUT_OF_RANGE;
+
+ // parse values
+ while (!strempty(s)) {
+ char* endptr;
+ long int sval = strtol( s, &endptr, 0 );
+
+#define EATSPACE(a) while ((!strncmp(a, " ", 1) || \
+ !strncmp(a, ",", 1)) && !strempty(a)) a++;
+ //EATSPACE(endptr);
+
+ while ((!strncmp(endptr, " ", 1) ||
+ !strncmp(endptr, ",", 1)) && !strempty(endptr)) {
+ endptr++;
+ }
+
+ long int eval = sval;
+ if (!strcmp(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 FO_TYPE_OUT_OF_RANGE;
+ value = eval;
+ if (eval != (long int)value)
+ return FO_TYPE_OUT_OF_RANGE;
+
+ for (int i = sval; i <= eval; i++)
+ values.push_back(i);
+
+ s = endptr;
+ }
+
+ return FO_SUCCESS;
+}
+
+CGMFOErrorCode CGMFileOptions::get_real_option ( const char* name, double& value ) const
+{
+ const char* s;
+ CGMFOErrorCode rval = get_option( name, s );
+ if (FO_SUCCESS != rval)
+ return rval;
+
+ // empty string
+ if (strempty(s))
+ return FO_TYPE_OUT_OF_RANGE;
+
+ // parse value
+ char* endptr;
+ value = strtod( s, &endptr );
+ if (!strempty(endptr)) // syntax error
+ return FO_TYPE_OUT_OF_RANGE;
+
+ return FO_SUCCESS;
+}
+
+CGMFOErrorCode CGMFileOptions::get_str_option( const char* name, std::string& value ) const
+{
+ const char* s;
+ CGMFOErrorCode rval = get_option( name, s );
+ if (FO_SUCCESS != rval)
+ return rval;
+ if (strempty(s))
+ return FO_TYPE_OUT_OF_RANGE;
+ value = s;
+ return FO_SUCCESS;
+}
+
+CGMFOErrorCode CGMFileOptions::get_option( const char* name, std::string& value ) const
+{
+ const char* s;
+ CGMFOErrorCode rval = get_option( name, s );
+ if (FO_SUCCESS != rval)
+ return rval;
+
+ value = s;
+ return FO_SUCCESS;
+}
+
+CGMFOErrorCode CGMFileOptions::get_option( const char* name, const char*& value ) const
+{
+ 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;
+
+ return FO_SUCCESS;
+ }
+ }
+
+ return FO_ENTITY_NOT_FOUND;
+}
+
+CGMFOErrorCode CGMFileOptions::match_option( const char* name,
+ const char* value ) const
+{
+ int idx;
+ const char* array[] = { value, NULL };
+ return match_option( name, array, idx );
+}
+
+CGMFOErrorCode CGMFileOptions::match_option( const char* name,
+ const char* const* values,
+ int& index ) const
+{
+ const char* optval;
+ CGMFOErrorCode rval = get_option( name, optval );
+ if (FO_SUCCESS != rval)
+ return rval;
+
+ for (index = 0; values[index]; ++index)
+ if (compare( optval, values[index] ))
+ return FO_SUCCESS;
+
+ index = -1;
+ return FO_FAILURE;
+}
+
+
+bool CGMFileOptions::compare( const char* name, const char* option )
+{
+ while (!strempty(name) && toupper(*name) == toupper(*option)) {
+ ++name;
+ ++option;
+ }
+ // match if name matched option for length of name,
+ // and option either matched entirely or matches up to
+ // and equals sign.
+ return strempty(name) && (strempty(option) || *option == '=');
+}
+
+void CGMFileOptions::get_options( std::vector<std::string>& list ) const
+{
+ list.clear();
+ list.resize( mOptions.size() );
+ std::copy( mOptions.begin(), mOptions.end(), list.begin() );
+}
+
+#ifdef TEST
+
+#include <iostream>
+
+#define CHECK(A) \
+ if (FO_SUCCESS != (A)) { \
+ std::cerr << "Failure at line " << __LINE__ << ": error code " << (A) << std::endl; \
+ return 1; \
+ }
+
+#define EQUAL(A,B) \
+ if (A != B) { \
+ std::cerr << "Failure at line " << __LINE__ << ": expected " << (B) << " but got " << (A) << std::endl; \
+ return 2; \
+ }
+
+int main()
+{
+ CGMFileOptions tool( "INT1=1;NUL1;STR1=ABC;DBL1=1.0;dbl2=2.0;DBL3=3.0;INT2=2;nul2;NUL3;INT3=3;str2=once upon a time;str3==fubar=;;" );
+
+ std::string s;
+ int i;
+ double d;
+ CGMFOErrorCodeyy rval;
+
+ // test basic get_option method without deleting entry
+ rval = tool.get_option( "STR1", s );
+ CHECK(rval);
+ EQUAL( s, "ABC" );
+
+ // test basic get_option method again, this time deleting the entry
+ rval = tool.get_option( "STR1", s );
+ CHECK(rval);
+ EQUAL( s, "ABC" );
+
+ // test basig get_option method with a null option
+ rval = tool.get_option( "NUL2", s );
+ CHECK( rval );
+ EQUAL( s.empty(), true );
+
+
+ // test null option
+ rval = tool.get_null_option( "nul1" );
+ CHECK( rval );
+
+ // try null option method on non-null value
+ rval = tool.get_null_option( "INT1" ) ;
+ EQUAL( rval, FO_TYPE_OUT_OF_RANGE) ;
+
+
+ // test integer option
+ rval = tool.get_int_option( "int1", i );
+ CHECK( rval );
+ EQUAL( i, 1 );
+
+ rval = tool.get_int_option( "int2", i );
+ CHECK( rval );
+ EQUAL( i, 2 );
+
+ // test integer option on non-integer value
+ rval = tool.get_int_option( "dbl2", i );
+ EQUAL( rval, FO_TYPE_OUT_OF_RANGE );
+
+ // test integer option on null value
+ rval = tool.get_int_option( "NUL3", i);
+ EQUAL( rval, FO_TYPE_OUT_OF_RANGE );
+
+ // test double option
+ rval = tool.get_real_option( "dbl1", d );
+ CHECK( rval );
+ EQUAL( d, 1.0 );
+
+ rval = tool.get_real_option( "dbl2", d );
+ CHECK( rval );
+ EQUAL( d, 2.0 );
+
+ rval = tool.get_real_option( "int3", d );
+ CHECK( rval );
+ EQUAL( d, 3.0 );
+
+ // test real option on non-real value
+ rval = tool.get_real_option( "str2", d );
+ EQUAL( rval, FO_TYPE_OUT_OF_RANGE );
+
+
+ // test real option on null value
+ rval = tool.get_real_option( "NUL3", d );
+ EQUAL( rval, FO_TYPE_OUT_OF_RANGE );
+
+ // test get a simple string option
+ rval = tool.get_str_option( "DBL3", s );
+ CHECK( rval );
+ EQUAL( s, "3.0" );
+
+ // test get a string with spaces
+ rval = tool.get_str_option("STR2", s );
+ CHECK( rval );
+ EQUAL( s, "once upon a time" );
+
+ // try to get a string value for a null option
+ rval = tool.get_str_option( "nul3", s );
+ EQUAL( rval, FO_TYPE_OUT_OF_RANGE );
+
+ // test options using generic get_option method
+
+ rval = tool.get_option( "NUL3", s );
+ CHECK( rval );
+ EQUAL( s.empty(), true );
+
+ rval = tool.get_option( "STR3", s );
+ CHECK( rval );
+ EQUAL( s, "=fubar=" );
+
+ // test size of options string
+ unsigned l = tool.size();
+ EQUAL( l, 12u );
+
+
+ // test alternate separator
+
+ CGMFileOptions tool2( ";+OPT1=ABC+OPT2=" );
+ l = tool2.size();
+ EQUAL( l, 2 );
+
+ rval = tool2.get_option( "opt1", s );
+ CHECK( rval );
+ EQUAL( s, "ABC" );
+
+ rval = tool2.get_option( "opt2", s );
+ CHECK( rval );
+ bool e = s.empty();
+ EQUAL( e, true );
+
+ l = tool2.size();
+ EQUAL( l, 2 );
+
+
+ // test empty options string
+
+ CGMFileOptions tool3( ";;;;" );
+ e = tool3.empty();
+ EQUAL( e, true );
+ l = tool3.size();
+ EQUAL( l, 0 );
+
+ CGMFileOptions tool4(NULL);
+ e = tool4.empty();
+ EQUAL( e, true );
+ l = tool4.size();
+ EQUAL( l, 0 );
+
+ CGMFileOptions tool5(";+");
+ e = tool5.empty();
+ EQUAL( e, true );
+ l = tool5.size();
+ EQUAL( l, 0 );
+
+ // test copy constructor
+
+ CGMFileOptions tool6( tool2 );
+
+ rval = tool6.get_option( "opt1", s );
+ CHECK( rval );
+ EQUAL( s, "ABC" );
+
+ rval = tool6.get_option( "opt2", s );
+ CHECK( rval );
+ e = s.empty();
+ EQUAL( e, true );
+
+ l = tool6.size();
+ EQUAL( l, 2 );
+
+ CGMFileOptions tool7( tool5 );
+ e = tool7.empty();
+ EQUAL( e, true );
+ l = tool7.size();
+ EQUAL( l, 0 );
+
+ // test assignment operator
+
+ CGMFileOptions tool8( tool2 );
+ tool8 = tool;
+ EQUAL( tool8.size(), tool.size() );
+
+ return 0;
+}
+
+#endif
Added: cgm/trunk/geom/parallel/CGMFileOptions.hpp
===================================================================
--- cgm/trunk/geom/parallel/CGMFileOptions.hpp (rev 0)
+++ cgm/trunk/geom/parallel/CGMFileOptions.hpp 2010-02-18 21:29:20 UTC (rev 3547)
@@ -0,0 +1,165 @@
+/**\file CGMFileOptions.hpp
+ *\copied from MOAB
+ *\date 2009-06-11
+ */
+
+#ifndef CGM_FILE_OPTIONS_HPP
+#define CGM_FILE_OPTIONS_HPP
+
+#include <string>
+#include <vector>
+#include "CubitDefines.h"
+
+/* file option type */
+enum CGMFOErrorCode
+{
+ FO_SUCCESS = 0,
+ FO_TYPE_OUT_OF_RANGE,
+ FO_ENTITY_NOT_FOUND,
+ FO_FAILURE
+};
+
+/**\brief 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 ParallelMeshTool::load_file
+ */
+class CGMFileOptions {
+public:
+
+ /*\param options_string The concatenation of a list of
+ * options, separated either by the default separator
+ * (semicolon) with a custom separator specified at
+ * the beginning of the string (semicolon followed by
+ * destired separator character.)
+ */
+ CGMFileOptions( const char* option_string );
+
+ CGMFileOptions( const CGMFileOptions& copy );
+ CGMFileOptions& operator=( const CGMFileOptions& copy );
+
+ ~CGMFileOptions();
+
+ /**\brief Check for option with no value
+ *
+ * Check for an option w/out a value.
+ *\param name The option name
+ *\return - CUBIT_SUCCESS if option is found
+ * - CUBIT_TYPE_OUT_OF_RANGE if options is found, but has value
+ * - CUBIT_ENTITY_NOT_FOUND if option is not found.
+ */
+ CGMFOErrorCode get_null_option( const char* name ) const;
+
+ /**\brief Check for option with an integer value.
+ *
+ * Check for an option with an integer value
+ *\param name The option name
+ *\param value Output. The value.
+ *\return - CUBIT_SUCCESS if option is found
+ * - CUBIT_TYPE_OUT_OF_RANGE if options is found, but does not have an integer value
+ * - CUBIT_ENTITY_NOT_FOUND if option is not found.
+ */
+ CGMFOErrorCode get_int_option( const char* name, int& value ) const;
+
+ /**\brief Check for option with a double value.
+ *
+ * Check for an option with a double value
+ *\param name The option name
+ *\param value Output. The value.
+ *\return - CUBIT_SUCCESS if option is found
+ * - CUBIT_TYPE_OUT_OF_RANGE if options is found, but does not have a double value
+ * - CUBIT_ENTITY_NOT_FOUND if option is not found.
+ */
+ CGMFOErrorCode get_real_option( const char* name, double& value ) const;
+
+ /**\brief Check for option with any value.
+ *
+ * Check for an option with any value.
+ *\param name The option name
+ *\param value Output. The value.
+ *\return - CUBIT_SUCCESS if option is found
+ * - CUBIT_TYPE_OUT_OF_RANGE if options is found, but does not have a value
+ * - CUBIT_ENTITY_NOT_FOUND if option is not found.
+ */
+ CGMFOErrorCode get_str_option( const char* name, std::string& value ) const;
+
+ /**\brief Check for option
+ *
+ * Check for an option
+ *\param name The option name
+ *\param value The option value, or an empty string if no value.
+ *\return CUBIT_SUCCESS or CUBIT_ENTITY_NOT_FOUND
+ */
+ CGMFOErrorCode get_option( const char* name, std::string& value ) const;
+
+ /**\brief Check the string value of an option
+ *
+ * Check which of a list of possible values a string option contains.
+ *\param name The option name
+ *\param values A NULL-terminated array of C-style strings enumerating
+ * the possible option values.
+ *\param index Output: The index into <code>values</code> for the
+ * option value.
+ *\return CUBIT_SUCCESS if matched name and value.
+ * CUBIT_ENTITY_NOT_FOUND if the option was not specified
+ * CUBIT_FAILURE if the option value is not in the input <code>values</code> array.
+ */
+ CGMFOErrorCode match_option( const char* name, const char* const* values, int& index ) const;
+
+ /**\brief Check if an option matches a string value
+ *
+ * Check if the value for an option is the passed string.
+ *\param name The option name
+ *\param value The expected value.
+ *\return CUBIT_SUCCESS if matched name and value.
+ * CUBIT_ENTITY_NOT_FOUND if the option was not specified
+ * CUBIT_FAILURE if the option value doesn't match the passed string/
+ */
+ CGMFOErrorCode match_option( const char* name, const char* value ) const;
+
+ /**\brief 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 ('-').
+ *
+ *\param name The option name
+ *\param values Output. The list of integer values.
+ *\return - CUBIT_SUCCESS if option is found
+ * - CUBIT_TYPE_OUT_OF_RANGE if options is found, but does not contain an ID list
+ * - CUBIT_ENTITY_NOT_FOUND if option is not found.
+ */
+ CGMFOErrorCode get_ints_option( const char* name, std::vector<int>& values) const;
+
+ /** number of options */
+ inline unsigned size() const
+ { return mOptions.size(); }
+
+ /** true if no options */
+ inline bool empty() const
+ { return mOptions.empty(); }
+
+ /** Get list of options */
+ void get_options( std::vector<std::string>& list ) const;
+
+private:
+
+ /**\brief Check for option
+ *
+ * Check for an option
+ *\param name The option name
+ *\param value The option value, or an empty string if no value.
+ *\return CUBIT_SUCCESS or CUBIT_ENTITY_NOT_FOUND
+ */
+ CGMFOErrorCode get_option( const char* name, const char*& value) const;
+
+ char* mData;
+ std::vector<const char*> mOptions;
+
+ /** Case-insensitive compare of name with option value. */
+ static bool compare( const char* name, const char* option );
+};
+
+#endif
+
Deleted: cgm/trunk/geom/parallel/FileOptions.cpp
===================================================================
--- cgm/trunk/geom/parallel/FileOptions.cpp 2010-02-16 02:58:31 UTC (rev 3546)
+++ cgm/trunk/geom/parallel/FileOptions.cpp 2010-02-18 21:29:20 UTC (rev 3547)
@@ -1,463 +0,0 @@
-/**\file FileOptions.cpp
- *\ copied from MOAB
- *\date 2009-06-11
- */
-
-#include "FileOptions.hpp"
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-
-const char DEFAULT_SEPARATOR = ';';
-
-static inline bool strempty( const char* s ) { return !*s; }
-
-FileOptions::FileOptions( const char* str )
- : 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 );
- }
-}
-
-FileOptions::FileOptions( const FileOptions& copy ) :
- 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);
- }
-}
-
-FileOptions& FileOptions::operator=( const FileOptions& copy )
-{
- 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);
- }
-
- return *this;
-}
-
-FileOptions::~FileOptions()
-{
- free( mData );
-}
-
-FOErrorCode FileOptions::get_null_option( const char* name ) const
-{
- const char* s;
- FOErrorCode rval = get_option( name, s );
- if (FO_SUCCESS != rval)
- return rval;
- return strempty(s) ? FO_SUCCESS : FO_TYPE_OUT_OF_RANGE;
-}
-
-FOErrorCode FileOptions::get_int_option( const char* name, int& value ) const
-{
- const char* s;
- FOErrorCode rval = get_option( name, s );
- if (FO_SUCCESS != rval)
- return rval;
-
- // empty string
- if (strempty(s))
- return FO_TYPE_OUT_OF_RANGE;
-
- // parse value
- char* endptr;
- long int pval = strtol( s, &endptr, 0 );
- if (!strempty(endptr)) // syntax error
- return FO_TYPE_OUT_OF_RANGE;
-
- // check for overflow (parsing long int, returning int)
- value = pval;
- if (pval != (long int)value)
- return FO_TYPE_OUT_OF_RANGE;
-
- return FO_SUCCESS;
-}
-
-FOErrorCode FileOptions::get_ints_option( const char* name,
- std::vector<int>& values) const
-{
- const char* s;
- FOErrorCode rval = get_option( name, s );
- if (FO_SUCCESS != rval)
- return rval;
-
- // empty string
- if (strempty(s))
- return FO_TYPE_OUT_OF_RANGE;
-
- // parse values
- while (!strempty(s)) {
- char* endptr;
- long int sval = strtol( s, &endptr, 0 );
-
-#define EATSPACE(a) while ((!strncmp(a, " ", 1) || \
- !strncmp(a, ",", 1)) && !strempty(a)) a++;
- //EATSPACE(endptr);
-
- while ((!strncmp(endptr, " ", 1) ||
- !strncmp(endptr, ",", 1)) && !strempty(endptr)) {
- endptr++;
- }
-
- long int eval = sval;
- if (!strcmp(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 FO_TYPE_OUT_OF_RANGE;
- value = eval;
- if (eval != (long int)value)
- return FO_TYPE_OUT_OF_RANGE;
-
- for (int i = sval; i <= eval; i++)
- values.push_back(i);
-
- s = endptr;
- }
-
- return FO_SUCCESS;
-}
-
-FOErrorCode FileOptions::get_real_option ( const char* name, double& value ) const
-{
- const char* s;
- FOErrorCode rval = get_option( name, s );
- if (FO_SUCCESS != rval)
- return rval;
-
- // empty string
- if (strempty(s))
- return FO_TYPE_OUT_OF_RANGE;
-
- // parse value
- char* endptr;
- value = strtod( s, &endptr );
- if (!strempty(endptr)) // syntax error
- return FO_TYPE_OUT_OF_RANGE;
-
- return FO_SUCCESS;
-}
-
-FOErrorCode FileOptions::get_str_option( const char* name, std::string& value ) const
-{
- const char* s;
- FOErrorCode rval = get_option( name, s );
- if (FO_SUCCESS != rval)
- return rval;
- if (strempty(s))
- return FO_TYPE_OUT_OF_RANGE;
- value = s;
- return FO_SUCCESS;
-}
-
-FOErrorCode FileOptions::get_option( const char* name, std::string& value ) const
-{
- const char* s;
- FOErrorCode rval = get_option( name, s );
- if (FO_SUCCESS != rval)
- return rval;
-
- value = s;
- return FO_SUCCESS;
-}
-
-FOErrorCode FileOptions::get_option( const char* name, const char*& value ) const
-{
- 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;
-
- return FO_SUCCESS;
- }
- }
-
- return FO_ENTITY_NOT_FOUND;
-}
-
-FOErrorCode FileOptions::match_option( const char* name,
- const char* value ) const
-{
- int idx;
- const char* array[] = { value, NULL };
- return match_option( name, array, idx );
-}
-
-FOErrorCode FileOptions::match_option( const char* name,
- const char* const* values,
- int& index ) const
-{
- const char* optval;
- FOErrorCode rval = get_option( name, optval );
- if (FO_SUCCESS != rval)
- return rval;
-
- for (index = 0; values[index]; ++index)
- if (compare( optval, values[index] ))
- return FO_SUCCESS;
-
- index = -1;
- return FO_FAILURE;
-}
-
-
-bool FileOptions::compare( const char* name, const char* option )
-{
- while (!strempty(name) && toupper(*name) == toupper(*option)) {
- ++name;
- ++option;
- }
- // match if name matched option for length of name,
- // and option either matched entirely or matches up to
- // and equals sign.
- return strempty(name) && (strempty(option) || *option == '=');
-}
-
-void FileOptions::get_options( std::vector<std::string>& list ) const
-{
- list.clear();
- list.resize( mOptions.size() );
- std::copy( mOptions.begin(), mOptions.end(), list.begin() );
-}
-
-#ifdef TEST
-
-#include <iostream>
-
-#define CHECK(A) \
- if (FO_SUCCESS != (A)) { \
- std::cerr << "Failure at line " << __LINE__ << ": error code " << (A) << std::endl; \
- return 1; \
- }
-
-#define EQUAL(A,B) \
- if (A != B) { \
- std::cerr << "Failure at line " << __LINE__ << ": expected " << (B) << " but got " << (A) << std::endl; \
- return 2; \
- }
-
-int main()
-{
- FileOptions tool( "INT1=1;NUL1;STR1=ABC;DBL1=1.0;dbl2=2.0;DBL3=3.0;INT2=2;nul2;NUL3;INT3=3;str2=once upon a time;str3==fubar=;;" );
-
- std::string s;
- int i;
- double d;
- FOErrorCodeyy rval;
-
- // test basic get_option method without deleting entry
- rval = tool.get_option( "STR1", s );
- CHECK(rval);
- EQUAL( s, "ABC" );
-
- // test basic get_option method again, this time deleting the entry
- rval = tool.get_option( "STR1", s );
- CHECK(rval);
- EQUAL( s, "ABC" );
-
- // test basig get_option method with a null option
- rval = tool.get_option( "NUL2", s );
- CHECK( rval );
- EQUAL( s.empty(), true );
-
-
- // test null option
- rval = tool.get_null_option( "nul1" );
- CHECK( rval );
-
- // try null option method on non-null value
- rval = tool.get_null_option( "INT1" ) ;
- EQUAL( rval, FO_TYPE_OUT_OF_RANGE) ;
-
-
- // test integer option
- rval = tool.get_int_option( "int1", i );
- CHECK( rval );
- EQUAL( i, 1 );
-
- rval = tool.get_int_option( "int2", i );
- CHECK( rval );
- EQUAL( i, 2 );
-
- // test integer option on non-integer value
- rval = tool.get_int_option( "dbl2", i );
- EQUAL( rval, FO_TYPE_OUT_OF_RANGE );
-
- // test integer option on null value
- rval = tool.get_int_option( "NUL3", i);
- EQUAL( rval, FO_TYPE_OUT_OF_RANGE );
-
- // test double option
- rval = tool.get_real_option( "dbl1", d );
- CHECK( rval );
- EQUAL( d, 1.0 );
-
- rval = tool.get_real_option( "dbl2", d );
- CHECK( rval );
- EQUAL( d, 2.0 );
-
- rval = tool.get_real_option( "int3", d );
- CHECK( rval );
- EQUAL( d, 3.0 );
-
- // test real option on non-real value
- rval = tool.get_real_option( "str2", d );
- EQUAL( rval, FO_TYPE_OUT_OF_RANGE );
-
-
- // test real option on null value
- rval = tool.get_real_option( "NUL3", d );
- EQUAL( rval, FO_TYPE_OUT_OF_RANGE );
-
- // test get a simple string option
- rval = tool.get_str_option( "DBL3", s );
- CHECK( rval );
- EQUAL( s, "3.0" );
-
- // test get a string with spaces
- rval = tool.get_str_option("STR2", s );
- CHECK( rval );
- EQUAL( s, "once upon a time" );
-
- // try to get a string value for a null option
- rval = tool.get_str_option( "nul3", s );
- EQUAL( rval, FO_TYPE_OUT_OF_RANGE );
-
- // test options using generic get_option method
-
- rval = tool.get_option( "NUL3", s );
- CHECK( rval );
- EQUAL( s.empty(), true );
-
- rval = tool.get_option( "STR3", s );
- CHECK( rval );
- EQUAL( s, "=fubar=" );
-
- // test size of options string
- unsigned l = tool.size();
- EQUAL( l, 12u );
-
-
- // test alternate separator
-
- FileOptions tool2( ";+OPT1=ABC+OPT2=" );
- l = tool2.size();
- EQUAL( l, 2 );
-
- rval = tool2.get_option( "opt1", s );
- CHECK( rval );
- EQUAL( s, "ABC" );
-
- rval = tool2.get_option( "opt2", s );
- CHECK( rval );
- bool e = s.empty();
- EQUAL( e, true );
-
- l = tool2.size();
- EQUAL( l, 2 );
-
-
- // test empty options string
-
- FileOptions tool3( ";;;;" );
- e = tool3.empty();
- EQUAL( e, true );
- l = tool3.size();
- EQUAL( l, 0 );
-
- FileOptions tool4(NULL);
- e = tool4.empty();
- EQUAL( e, true );
- l = tool4.size();
- EQUAL( l, 0 );
-
- FileOptions tool5(";+");
- e = tool5.empty();
- EQUAL( e, true );
- l = tool5.size();
- EQUAL( l, 0 );
-
- // test copy constructor
-
- FileOptions tool6( tool2 );
-
- rval = tool6.get_option( "opt1", s );
- CHECK( rval );
- EQUAL( s, "ABC" );
-
- rval = tool6.get_option( "opt2", s );
- CHECK( rval );
- e = s.empty();
- EQUAL( e, true );
-
- l = tool6.size();
- EQUAL( l, 2 );
-
- FileOptions tool7( tool5 );
- e = tool7.empty();
- EQUAL( e, true );
- l = tool7.size();
- EQUAL( l, 0 );
-
- // test assignment operator
-
- FileOptions tool8( tool2 );
- tool8 = tool;
- EQUAL( tool8.size(), tool.size() );
-
- return 0;
-}
-
-#endif
Deleted: cgm/trunk/geom/parallel/FileOptions.hpp
===================================================================
--- cgm/trunk/geom/parallel/FileOptions.hpp 2010-02-16 02:58:31 UTC (rev 3546)
+++ cgm/trunk/geom/parallel/FileOptions.hpp 2010-02-18 21:29:20 UTC (rev 3547)
@@ -1,165 +0,0 @@
-/**\file FileOptions.hpp
- *\copied from MOAB
- *\date 2009-06-11
- */
-
-#ifndef FILE_OPTIONS_HPP
-#define FILE_OPTIONS_HPP
-
-#include <string>
-#include <vector>
-#include "CubitDefines.h"
-
-/* file option type */
-enum FOErrorCode
-{
- FO_SUCCESS = 0,
- FO_TYPE_OUT_OF_RANGE,
- FO_ENTITY_NOT_FOUND,
- FO_FAILURE
-};
-
-/**\brief 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 ParallelMeshTool::load_file
- */
-class FileOptions {
-public:
-
- /*\param options_string The concatenation of a list of
- * options, separated either by the default separator
- * (semicolon) with a custom separator specified at
- * the beginning of the string (semicolon followed by
- * destired separator character.)
- */
- FileOptions( const char* option_string );
-
- FileOptions( const FileOptions& copy );
- FileOptions& operator=( const FileOptions& copy );
-
- ~FileOptions();
-
- /**\brief Check for option with no value
- *
- * Check for an option w/out a value.
- *\param name The option name
- *\return - CUBIT_SUCCESS if option is found
- * - CUBIT_TYPE_OUT_OF_RANGE if options is found, but has value
- * - CUBIT_ENTITY_NOT_FOUND if option is not found.
- */
- FOErrorCode get_null_option( const char* name ) const;
-
- /**\brief Check for option with an integer value.
- *
- * Check for an option with an integer value
- *\param name The option name
- *\param value Output. The value.
- *\return - CUBIT_SUCCESS if option is found
- * - CUBIT_TYPE_OUT_OF_RANGE if options is found, but does not have an integer value
- * - CUBIT_ENTITY_NOT_FOUND if option is not found.
- */
- FOErrorCode get_int_option( const char* name, int& value ) const;
-
- /**\brief Check for option with a double value.
- *
- * Check for an option with a double value
- *\param name The option name
- *\param value Output. The value.
- *\return - CUBIT_SUCCESS if option is found
- * - CUBIT_TYPE_OUT_OF_RANGE if options is found, but does not have a double value
- * - CUBIT_ENTITY_NOT_FOUND if option is not found.
- */
- FOErrorCode get_real_option( const char* name, double& value ) const;
-
- /**\brief Check for option with any value.
- *
- * Check for an option with any value.
- *\param name The option name
- *\param value Output. The value.
- *\return - CUBIT_SUCCESS if option is found
- * - CUBIT_TYPE_OUT_OF_RANGE if options is found, but does not have a value
- * - CUBIT_ENTITY_NOT_FOUND if option is not found.
- */
- FOErrorCode get_str_option( const char* name, std::string& value ) const;
-
- /**\brief Check for option
- *
- * Check for an option
- *\param name The option name
- *\param value The option value, or an empty string if no value.
- *\return CUBIT_SUCCESS or CUBIT_ENTITY_NOT_FOUND
- */
- FOErrorCode get_option( const char* name, std::string& value ) const;
-
- /**\brief Check the string value of an option
- *
- * Check which of a list of possible values a string option contains.
- *\param name The option name
- *\param values A NULL-terminated array of C-style strings enumerating
- * the possible option values.
- *\param index Output: The index into <code>values</code> for the
- * option value.
- *\return CUBIT_SUCCESS if matched name and value.
- * CUBIT_ENTITY_NOT_FOUND if the option was not specified
- * CUBIT_FAILURE if the option value is not in the input <code>values</code> array.
- */
- FOErrorCode match_option( const char* name, const char* const* values, int& index ) const;
-
- /**\brief Check if an option matches a string value
- *
- * Check if the value for an option is the passed string.
- *\param name The option name
- *\param value The expected value.
- *\return CUBIT_SUCCESS if matched name and value.
- * CUBIT_ENTITY_NOT_FOUND if the option was not specified
- * CUBIT_FAILURE if the option value doesn't match the passed string/
- */
- FOErrorCode match_option( const char* name, const char* value ) const;
-
- /**\brief 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 ('-').
- *
- *\param name The option name
- *\param values Output. The list of integer values.
- *\return - CUBIT_SUCCESS if option is found
- * - CUBIT_TYPE_OUT_OF_RANGE if options is found, but does not contain an ID list
- * - CUBIT_ENTITY_NOT_FOUND if option is not found.
- */
- FOErrorCode get_ints_option( const char* name, std::vector<int>& values) const;
-
- /** number of options */
- inline unsigned size() const
- { return mOptions.size(); }
-
- /** true if no options */
- inline bool empty() const
- { return mOptions.empty(); }
-
- /** Get list of options */
- void get_options( std::vector<std::string>& list ) const;
-
-private:
-
- /**\brief Check for option
- *
- * Check for an option
- *\param name The option name
- *\param value The option value, or an empty string if no value.
- *\return CUBIT_SUCCESS or CUBIT_ENTITY_NOT_FOUND
- */
- FOErrorCode get_option( const char* name, const char*& value) const;
-
- char* mData;
- std::vector<const char*> mOptions;
-
- /** Case-insensitive compare of name with option value. */
- static bool compare( const char* name, const char* option );
-};
-
-#endif
-
Modified: cgm/trunk/geom/parallel/Makefile.am
===================================================================
--- cgm/trunk/geom/parallel/Makefile.am 2010-02-16 02:58:31 UTC (rev 3546)
+++ cgm/trunk/geom/parallel/Makefile.am 2010-02-18 21:29:20 UTC (rev 3547)
@@ -23,7 +23,7 @@
libcubit_parallel_la_SOURCES = \
CGMProcConfig.cpp \
CGMParallelComm.cpp \
- FileOptions.cpp \
+ CGMFileOptions.cpp \
ParallelGeomTool.cpp
# The non-template headers
@@ -34,6 +34,6 @@
CGMmpi_config.h \
CGMProcConfig.hpp \
CGMParallelComm.hpp \
- FileOptions.hpp \
+ CGMFileOptions.hpp \
ParallelGeomTool.hpp
Modified: cgm/trunk/geom/parallel/ParallelGeomTool.cpp
===================================================================
--- cgm/trunk/geom/parallel/ParallelGeomTool.cpp 2010-02-16 02:58:31 UTC (rev 3546)
+++ cgm/trunk/geom/parallel/ParallelGeomTool.cpp 2010-02-18 21:29:20 UTC (rev 3547)
@@ -7,6 +7,8 @@
#include "CubitEntity.hpp"
#include "CastTo.hpp"
#include "CubitUtil.hpp"
+#include "CubitAttrib.hpp"
+#include "CADefines.hpp"
#include "TopologyBridge.hpp"
#include "GeometryQueryTool.hpp"
@@ -60,11 +62,11 @@
const int* set_tag_values,
int num_set_tag_values)
{
- FileOptions opts(options);
+ CGMFileOptions opts(options);
// Get parallel settings
int parallel_mode;
- FOErrorCode result = opts.match_option("PARALLEL", CGMparallelOptsNames,
+ CGMFOErrorCode result = opts.match_option("PARALLEL", CGMparallelOptsNames,
parallel_mode);
if (FO_FAILURE == result) {
PRINT_ERROR( "Unexpected value for 'PARALLEL' option\n" );
@@ -215,7 +217,7 @@
std::vector<int> &partition_tag_vals,
bool distrib,
std::vector<int> &pa_vec,
- const FileOptions &opts,
+ const CGMFileOptions &opts,
const char* set_tag_name,
const int* set_tag_values,
const int num_set_tag_values,
More information about the cgma-dev
mailing list