![]() |
Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
Go to the source code of this file.
Classes | |
struct | TagSpec |
Typedefs | |
typedef unsigned char | bittype |
Functions | |
int | parse_tag_spec (char *string, TagSpec &result, moab::Interface *iface) |
int | parse_tag_create (char *string, TagSpec &result, moab::Interface *iface) |
void | tag_syntax (std::ostream &stream) |
int parse_tag_create | ( | char * | string, |
TagSpec & | result, | ||
moab::Interface * | iface | ||
) |
Definition at line 275 of file parse.cpp.
References ErrorCode, TagSpec::handle, MB_ENTITY_NOT_FOUND, MB_SUCCESS, MB_TAG_ANY, MB_TAG_CREAT, MB_TAG_SPARSE, MB_TYPE_BIT, MB_TYPE_DOUBLE, MB_TYPE_HANDLE, MB_TYPE_INTEGER, MB_TYPE_OPAQUE, parse_values(), moab::Interface::tag_get_data_type(), moab::Interface::tag_get_default_value(), moab::Interface::tag_get_handle(), moab::Interface::tag_get_length(), and TagSpec::value.
Referenced by main().
{
// split at '=' signs
char* eq1 = strrchr( name, '=' );
if( !eq1 )
{
std::cerr << "Invalid tag specification: " << name << std::endl;
return 1;
}
*eq1 = '\0';
++eq1;
char *type_str = eq1, *val = 0;
char* eq2 = strrchr( name, '=' );
if( eq2 )
{
*eq2 = '\0';
++eq2;
val = ( '\0' == eq1[0] ) ? 0 : eq1;
type_str = eq2;
}
// parse type data
char* size_str = strchr( type_str, ':' );
if( !size_str )
{
std::cerr << "Invalid tag type specification: " << type_str << std::endl;
return 1;
}
*size_str = '\0';
++size_str;
DataType type;
if( !strcmp( type_str, "int" ) )
{
type = MB_TYPE_INTEGER;
}
else if( !strcmp( type_str, "double" ) )
{
type = MB_TYPE_DOUBLE;
}
else if( !strcmp( type_str, "bit" ) )
{
type = MB_TYPE_BIT;
}
else if( !strcmp( type_str, "handle" ) )
{
type = MB_TYPE_HANDLE;
}
else if( !strcmp( type_str, "opaque" ) )
{
type = MB_TYPE_OPAQUE;
}
else
{
std::cerr << "Invalid tag type specification: " << type_str << std::endl;
return 1;
}
char* end_ptr;
int count = (int)strtol( size_str, &end_ptr, 0 );
if( !*size_str || *end_ptr || count < 1 )
{
std::cerr << "Invalid tag size specification: " << size_str << std::endl;
return 1;
}
// parse default value
result.value = 0;
if( val )
{
result.value = parse_values( val, type, count );
if( !result.value ) return 1;
}
// check if tag exists
if( MB_SUCCESS == iface->tag_get_handle( name, 0, MB_TYPE_OPAQUE, result.handle, MB_TAG_ANY ) )
{
// make sure it matches
DataType etype;
int esize;
if( MB_SUCCESS != iface->tag_get_data_type( result.handle, etype ) ||
MB_SUCCESS != iface->tag_get_length( result.handle, esize ) )
{
std::cerr << "Error accessing properties of tag: " << name << std::endl;
return 3;
}
if( etype != type || esize != count )
{
std::cerr << "Tag already exists with different type: " << name << std::endl;
return 1;
}
std::vector< unsigned char > value( esize );
if( result.value )
{
ErrorCode rval = iface->tag_get_default_value( result.handle, &value[0] );
if( rval != MB_ENTITY_NOT_FOUND && rval != MB_SUCCESS )
{
std::cerr << "Error checking default value of tag: " << name << std::endl;
return 3;
}
else if( rval == MB_ENTITY_NOT_FOUND || memcmp( &value[0], result.value, esize ) )
{
std::cerr << "Tag already exists and default value doesn't match: " << name << std::endl;
return 1;
}
}
}
else
{
ErrorCode rval =
iface->tag_get_handle( name, count, type, result.handle, MB_TAG_SPARSE | MB_TAG_CREAT, result.value );
if( MB_SUCCESS != rval )
{
std::cerr << "Failed to create tag: " << name << std::endl;
return 3;
}
}
return 0;
}
int parse_tag_spec | ( | char * | string, |
TagSpec & | result, | ||
moab::Interface * | iface | ||
) |
Definition at line 218 of file parse.cpp.
References ErrorCode, TagSpec::handle, MB_SUCCESS, MB_TAG_ANY, MB_TAG_NOT_FOUND, MB_TYPE_OPAQUE, parse_values(), size, moab::Interface::tag_get_data_type(), moab::Interface::tag_get_handle(), moab::Interface::tag_get_length(), and TagSpec::value.
Referenced by main().
{
// Separate optional tag value from tag name
char* val = strrchr( name, '=' );
if( val )
{
// zero-length tag name>
if( val == name )
{
std::cerr << "Cannot create tag w/out name: " << name << std::endl;
return 1;
}
*val = '\0';
if( !*++val ) // if name ends with an '=', set val to NULL.
val = 0;
}
// Get tag
ErrorCode rval = iface->tag_get_handle( name, 0, MB_TYPE_OPAQUE, result.handle, MB_TAG_ANY );
if( MB_TAG_NOT_FOUND == rval )
{
std::cerr << "Tag not found: " << name << std::endl;
return 2;
}
else if( MB_SUCCESS != rval )
{
std::cerr << "Error retrieving tag handle: " << name << std::endl;
return 3;
}
// Parse tag value
result.value = 0;
if( val )
{
DataType type;
rval = iface->tag_get_data_type( result.handle, type );
if( MB_SUCCESS != rval )
{
std::cerr << "Error retrieving type for tag: " << name << std::endl;
return 3;
}
int size;
rval = iface->tag_get_length( result.handle, size );
if( MB_SUCCESS != rval )
{
std::cerr << "Error retrieving size for tag: " << name << std::endl;
return 3;
}
result.value = parse_values( val, type, size );
if( !result.value ) return 1;
}
return 0;
}
void tag_syntax | ( | std::ostream & | stream | ) |
Definition at line 10 of file parse.cpp.
Referenced by usage().
{
s << "Tags are specified as =[value], where the tag value " << std::endl
<< "is optional." << std::endl
<< std::endl
<< "Values of integral types (INTEGER, BIT, and HANDLE) are " << std::endl
<< "specified using standard C integer notation (a 0x prefix " << std::endl
<< "for hexidecimal, 0 prefix for octal, and no prefix for " << std::endl
<< "decimal.) The value of an opaque tag is interpreted as " << std::endl
<< "either a integral value or a character string. If the tag " << std::endl
<< "value begins with the prefix 0x it will be interpreted as a " << std::endl
<< "hexidecimal (base-16) number. If the value does not begin " << std::endl
<< "with the 0x prefix, it is interpreted as a character string." << std::endl
<< "Characater strings will be padded with null characters as" << std::endl
<< "necessary to fill the tag." << std::endl
<< "Floating-point (real) values must be specified in base-10." << std::endl
<< "C exponential notation (e.g. 1e-10) is accepted." << std::endl
<< std::endl
<< "If the tag is an array of integral or floating-point values " << std::endl
<< "then the tag value must be specified as a comma-separated " << std::endl
<< "list, with NO spaces." << std::endl
<< std::endl
<< "Tags are created with the syntax name=type:size[=default_value]." << std::endl
<< "where type is one of {int,double,opaque,handle,bit} and size is " << std::endl
<< "the number of values of the specified type, or the number of " << std::endl
<< "bytes if the type is 'opaque', A default value for the tag may " << std::endl
<< "be specified." << std::endl;
}