[MOAB-dev] r5584 - MOAB/trunk/tools/dagmc
sjackson at cae.wisc.edu
sjackson at cae.wisc.edu
Wed Jun 20 11:51:10 CDT 2012
Author: sjackson
Date: 2012-06-20 11:51:10 -0500 (Wed, 20 Jun 2012)
New Revision: 5584
Modified:
MOAB/trunk/tools/dagmc/DagMC.cpp
MOAB/trunk/tools/dagmc/DagMC.hpp
MOAB/trunk/tools/dagmc/obb_analysis.cpp
Log:
Allow DagMC properties to have multiple values
A single property can now have multiple values set on a single volume
or surface. This changes the internal implementation of the property
system, but the public interface is the same except for a single new
function prop_values()
Modified: MOAB/trunk/tools/dagmc/DagMC.cpp
===================================================================
--- MOAB/trunk/tools/dagmc/DagMC.cpp 2012-06-18 18:51:44 UTC (rev 5583)
+++ MOAB/trunk/tools/dagmc/DagMC.cpp 2012-06-20 16:51:10 UTC (rev 5584)
@@ -1687,6 +1687,58 @@
return MB_SUCCESS;
}
+ErrorCode DagMC::append_packed_string( Tag tag, EntityHandle eh,
+ std::string& new_string )
+{
+ // When properties have multiple values, the values are tagged in a single character array
+ // with the different values separated by null characters
+ ErrorCode rval;
+ const void* p;
+ const char* str;
+ int len;
+ rval = MBI->tag_get_by_ptr( tag, &eh, 1, &p, &len );
+ if( rval == MB_TAG_NOT_FOUND ){
+ // This is the first entry, and can be set directly
+ p = new_string.c_str();
+ return MBI->tag_clear_data( tag, &eh, 1, p, new_string.length()+1);
+ }
+ else if( rval != MB_SUCCESS ) return rval;
+ else{
+ str = static_cast<const char*>(p);
+ }
+
+ // append a new value for the property to the existing property string
+ unsigned int tail_len = new_string.length() + 1;
+ char* new_packed_string = new char[ len + tail_len ];
+ memcpy( new_packed_string, str, len );
+ memcpy( new_packed_string + len, new_string.c_str(), tail_len );
+
+ int new_len = len + tail_len;
+ p = new_packed_string;
+ rval = MBI->tag_set_by_ptr( tag, &eh, 1, &p, &new_len );
+ delete[] new_packed_string;
+ return rval;
+}
+
+ErrorCode DagMC::unpack_packed_string( Tag tag, EntityHandle eh,
+ std::vector< std::string >& values )
+{
+ ErrorCode rval;
+ const void* p;
+ const char* str;
+ int len;
+ rval = MBI->tag_get_by_ptr( tag, &eh, 1, &p, &len );
+ if( rval != MB_SUCCESS ) return rval;
+ str = static_cast<const char*>(p);
More information about the moab-dev
mailing list