[MOAB-dev] r1564 - MOAB/trunk

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Fri Jan 25 14:04:27 CST 2008


Author: kraftche
Date: 2008-01-25 14:04:27 -0600 (Fri, 25 Jan 2008)
New Revision: 1564

Modified:
   MOAB/trunk/SparseTagCollection.cpp
   MOAB/trunk/SparseTagCollection.hpp
   MOAB/trunk/SparseTagSuperCollection.cpp
   MOAB/trunk/SparseTagSuperCollection.hpp
Log:
low level code for varialbe-length sparse tag values

Modified: MOAB/trunk/SparseTagCollection.cpp
===================================================================
--- MOAB/trunk/SparseTagCollection.cpp	2008-01-25 19:55:30 UTC (rev 1563)
+++ MOAB/trunk/SparseTagCollection.cpp	2008-01-25 20:04:27 UTC (rev 1564)
@@ -33,6 +33,7 @@
 #include "SparseTagCollection.hpp"
 #include "MBRange.hpp"
 #include "TagCompare.hpp"
+#include "VarLenTag.hpp"
 
 SparseTagCollection::SparseTagCollection(int data_size)
 {
@@ -57,6 +58,9 @@
 
 MBErrorCode SparseTagCollection::set_data(const MBEntityHandle entity_handle, const void* data)
 {
+  if (mDataSize == MB_VARIABLE_LENGTH)
+    return MB_VARIABLE_DATA_LENGTH;
+
   MBErrorCode ret_val = MB_TAG_NOT_FOUND;
 
   std::map<MBEntityHandle, void*>::iterator iterator =
@@ -82,6 +86,9 @@
 
 MBErrorCode SparseTagCollection::get_data(const MBEntityHandle entity_handle, void* data)
 {
+  if (mDataSize == MB_VARIABLE_LENGTH)
+    return MB_VARIABLE_DATA_LENGTH;
+
   std::map<MBEntityHandle, void*>::iterator iter =
     mData.find(entity_handle);
 
@@ -92,8 +99,55 @@
   return MB_SUCCESS;
 }
 
+MBErrorCode SparseTagCollection::set_data(const MBEntityHandle entity_handle, const void* data, int size)
+{
+  std::map<MBEntityHandle, void*>::iterator iterator =
+    mData.lower_bound(entity_handle);
+  
+  if (mDataSize == MB_VARIABLE_LENGTH) {
+    if (iterator == mData.end() || iterator->first != entity_handle) {
+      void* new_data = mAllocator.allocate(sizeof(VarLenTag));
+      new (new_data) VarLenTag;
+      iterator = mData.insert( iterator, std::pair<const MBEntityHandle,void*>(entity_handle, new_data) );
+    }
+    reinterpret_cast<VarLenTag*>(iterator->second)->set( data, size );
+  }
+  else {
+    if (size != 0 && size != mDataSize)
+      return MB_INVALID_SIZE;
+  
+    if (iterator == mData.end() || iterator->first != entity_handle) {
+      void* new_data = mAllocator.allocate(mDataSize);
+      iterator = mData.insert( iterator, std::pair<const MBEntityHandle,void*>(entity_handle, new_data) );
+    }
+    memcpy( iterator->second, data, mDataSize);
+  }
 
+  return MB_SUCCESS;
+}
 
+MBErrorCode SparseTagCollection::get_data(const MBEntityHandle entity_handle, const void*& data, int& size)
+{
+  std::map<MBEntityHandle, void*>::iterator iter =
+    mData.find(entity_handle);
+
+  if(iter == mData.end())
+    return MB_TAG_NOT_FOUND;
+  
+  if (mDataSize == MB_VARIABLE_LENGTH) {
+    const VarLenTag* vtag = reinterpret_cast<const VarLenTag*>(iter->second);
+    size = vtag->size();
+    data = vtag->data();
+  }
+  else {
+    size = mDataSize;
+    data = iter->second;
+  }
+  return MB_SUCCESS;
+}
+
+
+
 MBErrorCode SparseTagCollection::remove_data( const MBEntityHandle entity_handle )
 {
   std::map<MBEntityHandle, void*>::iterator iterator =

Modified: MOAB/trunk/SparseTagCollection.hpp
===================================================================
--- MOAB/trunk/SparseTagCollection.hpp	2008-01-25 19:55:30 UTC (rev 1563)
+++ MOAB/trunk/SparseTagCollection.hpp	2008-01-25 20:04:27 UTC (rev 1564)
@@ -78,7 +78,13 @@
 
   //! get the tag data for an entity id
   MBErrorCode get_data(const MBEntityHandle entity_handle, void* data);
+  
+  //! set variable-length tag data for an entity id
+  MBErrorCode set_data(const MBEntityHandle entity_handle, const void* data, int length);
 
+  //! get the variable-length data for an entity id
+  MBErrorCode get_data(const MBEntityHandle entity_handle, const void*& data, int& length);
+
   //! removes the data
   MBErrorCode remove_data(const MBEntityHandle entity_handle);
 

Modified: MOAB/trunk/SparseTagSuperCollection.cpp
===================================================================
--- MOAB/trunk/SparseTagSuperCollection.cpp	2008-01-25 19:55:30 UTC (rev 1563)
+++ MOAB/trunk/SparseTagSuperCollection.cpp	2008-01-25 20:04:27 UTC (rev 1564)
@@ -62,7 +62,7 @@
 
 MBErrorCode SparseTagSuperCollection::reserve_tag_id(int data_size, MBTagId tag_id)
 {
-  if(data_size<=0)
+  if(data_size<=0 && data_size != MB_VARIABLE_LENGTH)
     return MB_FAILURE;
 
   if (tag_id >= mDataTags.size())
@@ -105,7 +105,21 @@
   return coll ? coll->get_data( entity_handle, data ) : MB_TAG_NOT_FOUND;
 }
 
+MBErrorCode SparseTagSuperCollection::set_data(const MBTagId tag_handle, 
+    const MBEntityHandle entity_handle, const void* data, int size)
+{
+  SparseTagCollection* coll = get_collection(tag_handle);
+  return coll ? coll->set_data( entity_handle, data, size ) : MB_TAG_NOT_FOUND;
+}
 
+MBErrorCode SparseTagSuperCollection::get_data(const MBTagId tag_handle, 
+    const MBEntityHandle entity_handle, const void*& data, int& size)
+{
+  SparseTagCollection* coll = get_collection(tag_handle);
+  return coll ? coll->get_data( entity_handle, data, size ) : MB_TAG_NOT_FOUND;
+}
+
+
 MBErrorCode SparseTagSuperCollection::remove_data( const MBTagId tag_handle, 
     const MBEntityHandle entity_handle )
 {

Modified: MOAB/trunk/SparseTagSuperCollection.hpp
===================================================================
--- MOAB/trunk/SparseTagSuperCollection.hpp	2008-01-25 19:55:30 UTC (rev 1563)
+++ MOAB/trunk/SparseTagSuperCollection.hpp	2008-01-25 20:04:27 UTC (rev 1564)
@@ -78,6 +78,12 @@
   //! get the data of a tag
   MBErrorCode get_data(const MBTagId tag_handle, const MBEntityHandle entity_handle, void* data);
 
+  //! set the data of a variable-length tag
+  MBErrorCode set_data(const MBTagId tag_handle, const MBEntityHandle entity_handle, const void* data, int length);
+
+  //! get the data of a variable-length tag
+  MBErrorCode get_data(const MBTagId tag_handle, const MBEntityHandle entity_handle, const void*& data, int& length);
+
   //! removes data
   MBErrorCode remove_data(const MBTagId tag_handle, const MBEntityHandle entity_handle);
 




More information about the moab-dev mailing list