[MOAB-dev] r1264 - MOAB/trunk

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Mon Aug 27 18:01:14 CDT 2007


Author: kraftche
Date: 2007-08-27 18:01:14 -0500 (Mon, 27 Aug 2007)
New Revision: 1264

Modified:
   MOAB/trunk/TagServer.cpp
   MOAB/trunk/TagServer.hpp
Log:
Make MB_TAG_MESH be different than MB_TAG_SPARSE.
Now if an application requests a tag of type MB_TAG_MESH
 o it will get an error if it tries to get/set valus on anything other
    than the mesh
 o it will get back MB_TAG_MESH from MBInterface::tag_get_type().




Modified: MOAB/trunk/TagServer.cpp
===================================================================
--- MOAB/trunk/TagServer.cpp	2007-08-27 22:29:30 UTC (rev 1263)
+++ MOAB/trunk/TagServer.cpp	2007-08-27 23:01:14 UTC (rev 1264)
@@ -121,7 +121,7 @@
     }
   }
     
-  MBErrorCode result;
+  MBErrorCode result = MB_FAILURE;;
   MBTagId id;
 
     // Input size must be a multiple of the size of the data type.
@@ -136,14 +136,14 @@
       result = mBitServer->reserve_tag_id(data_size, id);
       break;
     case MB_TAG_SPARSE:
-    case MB_TAG_MESH:
       result = mSparseData->reserve_tag_id(data_size, id);
       break;
     case MB_TAG_DENSE:
       result = mDenseData->reserve_tag_id(data_size, default_value, id);
       break;
-    default:
-      result = MB_FAILURE;
+    case MB_TAG_MESH:
+      result = reserve_mesh_tag_id( id );
+      break;
   }
   
   if(result != MB_SUCCESS)
@@ -170,7 +170,7 @@
   if(iterator == mTagTable.end())
     return MB_TAG_NOT_FOUND;
 
-  MBErrorCode status = MB_TAG_NOT_FOUND;
+  MBErrorCode status = MB_FAILURE;
   
   MBTagId id = ID_FROM_TAG_HANDLE(tag_handle);
   switch (PROP_FROM_TAG_HANDLE(tag_handle)) {
@@ -178,14 +178,14 @@
       status = mBitServer->release_tag_id(id);
       break;
     case MB_TAG_SPARSE:
-    case MB_TAG_MESH:
       status = mSparseData->release_tag_id(id);
       break;
     case MB_TAG_DENSE:
       status = mDenseData->release_tag_id(id);
       break;
-    default:
-      status = MB_FAILURE;
+    case MB_TAG_MESH:
+      status = MB_SUCCESS;
+      break;
   }
 
   if (MB_SUCCESS == status) {
@@ -282,9 +282,10 @@
       return mSparseData->set_data(id, entity_handle, data);
     case MB_TAG_DENSE:
       return mDenseData->set_data(id, entity_handle, data);
-    default:
-      return MB_TAG_NOT_FOUND;
+    case MB_TAG_MESH:
+      return MB_FAILURE;
   }
+  return MB_FAILURE;
 }
 
 
@@ -436,6 +437,9 @@
     case MB_TAG_BIT:
       result = get_bits(tag_handle, entity_handle, *((unsigned char *)data));
       break;
+    case MB_TAG_MESH:
+      result = MB_FAILURE;
+      break;
   }
 
   // if we couldn't get a value
@@ -690,32 +694,18 @@
 
 MBErrorCode TagServer::remove_data( const MBTag tag_handle, const MBEntityHandle entity_handle )
 {
-
-
-  // there is no remove_data equivalent for Dense tags
-  if( PROP_FROM_TAG_HANDLE(tag_handle) == MB_TAG_DENSE)
-  {
-    return MB_SUCCESS;
+  switch (PROP_FROM_TAG_HANDLE(tag_handle)) {
+    case MB_TAG_DENSE:
+      return MB_SUCCESS;
+    case MB_TAG_SPARSE:
+      return mSparseData->remove_data(ID_FROM_TAG_HANDLE(tag_handle), entity_handle);
+    case MB_TAG_BIT:
+      return MB_FAILURE;
+    case MB_TAG_MESH:
+      return MB_FAILURE;
   }
-  else if(PROP_FROM_TAG_HANDLE(tag_handle) == MB_TAG_SPARSE)
-  {
-    return mSparseData->remove_data(ID_FROM_TAG_HANDLE(tag_handle), entity_handle);
-  }
-  else if(PROP_FROM_TAG_HANDLE(tag_handle) == MB_TAG_BIT)
-  {
-      // can't take bit tags off entities currently
-    return MB_FAILURE;
-  }
-
-
-  // use the delete_tag function instead of this
-  //else if(reinterpret_cast<long>(tag_handle) & TAG_BIT_PROPERTIES[MB_TAG_STATIC)
-  //{
-    //return mStaticSparseData.remove_data(ID_FROM_TAG_HANDLE(tag_handle));
-  //}
-
+  
   return MB_TAG_NOT_FOUND;
-
 }
 
 
@@ -752,6 +742,9 @@
     case MB_TAG_BIT:
       result = mBitServer->get_entities(id, type, entities);
       break;
+    case MB_TAG_MESH:
+      result = MB_TYPE_OUT_OF_RANGE;
+      break;
   }
   
   return result;
@@ -774,6 +767,9 @@
     case MB_TAG_BIT:
       result = mBitServer->get_entities(range, id, type, entities);
       break;
+    case MB_TAG_MESH:
+      result = MB_TYPE_OUT_OF_RANGE;
+      break;
   }
   
   return result;
@@ -798,6 +794,9 @@
       result = mBitServer->get_entities_with_tag_value(id, type, 
                                 entities, *((const unsigned char*)value));
       break;
+    case MB_TAG_MESH:
+      result = MB_TYPE_OUT_OF_RANGE;
+      break;
   }
 
   return result;
@@ -824,6 +823,9 @@
       result = mBitServer->get_entities_with_tag_value(range, id, type, 
                                    entities, *((const unsigned char*)value));
       break;
+    case MB_TAG_MESH:
+      result = MB_TYPE_OUT_OF_RANGE;
+      break;
   }
 
   return result;
@@ -985,6 +987,8 @@
       return mDenseData->get_number_entities(id, type, num_entities);
     case MB_TAG_BIT:
       return mBitServer->get_number_entities(id, type, num_entities);
+    case MB_TAG_MESH:
+      return MB_TYPE_OUT_OF_RANGE;
   }
   return MB_TAG_NOT_FOUND;
 }
@@ -1002,6 +1006,8 @@
       return mDenseData->get_number_entities(range, id, type, num_entities);
     case MB_TAG_BIT:
       return mBitServer->get_number_entities(range, id, type, num_entities);
+    case MB_TAG_MESH:
+      return MB_TYPE_OUT_OF_RANGE;
   }
   return MB_TAG_NOT_FOUND;
 }
@@ -1023,12 +1029,12 @@
     case MB_TAG_BIT:
       mBitServer->get_memory_use( id, result, tmp );
       break;
-    default:
+    case MB_TAG_MESH:
       break;
   }
 
     // add in size of entry in mTagTable
-  return result + sizeof(MBTag) + sizeof(TagInfo)  + 3*sizeof(void*);
+  return result + sizeof(MBTag) + sizeof(TagInfo) + 3*sizeof(void*);
 }
 
 MBErrorCode TagServer::get_memory_use( MBTag tag_handle,
@@ -1050,7 +1056,7 @@
     case MB_TAG_BIT:
       mBitServer->get_memory_use( id, total, per_entity );
       break;
-    default:
+    case MB_TAG_MESH:
       break;
   }
   
@@ -1058,11 +1064,33 @@
   total += sizeof(MBTag) + sizeof(TagInfo) + 3*sizeof(void*);
   if (tag_info->default_value())
     total += tag_info->get_size();
+  if (tag_info->get_mesh_value())
+    total += tag_info->get_size();
   total += tag_info->get_name().size();
   
   return MB_SUCCESS;
 }
 
+MBErrorCode TagServer::reserve_mesh_tag_id( MBTagId& id_out ) const
+{
+  MBTag tag = TAG_HANDLE_FROM_ID( 1, MB_TAG_MESH );
+  std::map<MBTag,TagInfo>::const_iterator i = mTagTable.lower_bound( tag );
+  if (i == mTagTable.end() || i->first > tag) {
+    id_out = 1;
+    return MB_SUCCESS;
+  }
+  
+  tag = i->first + 1;
+  for (++i; i != mTagTable.end() && tag == i->first; ++i)
+    tag = i->first + 1;
+  
+  id_out = ID_FROM_TAG_HANDLE( tag );
+  return MB_SUCCESS;
+}
+    
+  
+  
+
 #ifdef TEST
 
 #include <iostream>

Modified: MOAB/trunk/TagServer.hpp
===================================================================
--- MOAB/trunk/TagServer.hpp	2007-08-27 22:29:30 UTC (rev 1263)
+++ MOAB/trunk/TagServer.hpp	2007-08-27 23:01:14 UTC (rev 1264)
@@ -40,6 +40,7 @@
 #include <map>
 
 #include "MBTypes.h"
+#include "MBInternals.hpp"
 
 class MBRange;
 class DenseTagSuperCollection;
@@ -103,6 +104,8 @@
 
 private:    
 
+  MBErrorCode reserve_mesh_tag_id( int& id_out );
+
   //! stores the tag name
   std::string mTagName;
 
@@ -272,6 +275,8 @@
 
 private:
 
+  MBErrorCode reserve_mesh_tag_id( MBTagId& id_out ) const;
+
   //! table of tag ids and tag information
   //! do we really need to do it this way?
   //! we at least need a table between names and tag ids




More information about the moab-dev mailing list