[MOAB-dev] r1382 - MOAB/trunk

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Tue Nov 13 12:16:35 CST 2007


Author: kraftche
Date: 2007-11-13 12:16:35 -0600 (Tue, 13 Nov 2007)
New Revision: 1382

Modified:
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MeshSetSequence.cpp
   MOAB/trunk/MeshSetSequence.hpp
   MOAB/trunk/SequenceData.cpp
   MOAB/trunk/SequenceData.hpp
   MOAB/trunk/SequenceManager.hpp
   MOAB/trunk/TypeSequenceManager.hpp
Log:
const cleanup

Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2007-11-12 21:17:17 UTC (rev 1381)
+++ MOAB/trunk/MBCore.cpp	2007-11-13 18:16:35 UTC (rev 1382)
@@ -90,7 +90,16 @@
   "MB_FAILURE",
 };
 
-static inline MBMeshSet* get_mesh_set( const SequenceManager* sm,
+static inline const MBMeshSet* get_mesh_set( const SequenceManager* sm,
+                                             MBEntityHandle h )
+{
+  const EntitySequence* seq;
+  if (MBENTITYSET != TYPE_FROM_HANDLE(h) || MB_SUCCESS != sm->find( h, seq ))
+    return 0;
+  return reinterpret_cast<const MeshSetSequence*>(seq)->get_set(h);
+}
+
+static inline MBMeshSet* get_mesh_set( SequenceManager* sm,
                                        MBEntityHandle h )
 {
   EntitySequence* seq;
@@ -308,7 +317,7 @@
   handle = CREATE_HANDLE(type, id, err);
 
     //check to see if handle exists 
-  EntitySequence *dummy_seq = 0;
+  const EntitySequence *dummy_seq = 0;
   MBErrorCode error_code = sequence_manager()->find(handle, dummy_seq);
   return error_code; 
 }
@@ -650,7 +659,7 @@
                                   double *coords) const
 {
   MBErrorCode status;
-  EntitySequence* seq;
+  const EntitySequence* seq;
   const MBEntityHandle* const end = entities + num_entities;
 
   for(const MBEntityHandle* iter = entities; iter != end; ++iter)
@@ -662,7 +671,7 @@
     if(status != MB_SUCCESS )
       return MB_ENTITY_NOT_FOUND;
     
-    static_cast<VertexSequence*>(seq)->get_coordinates(*iter, coords);
+    static_cast<const VertexSequence*>(seq)->get_coordinates(*iter, coords);
     coords += 3;
   }
 
@@ -678,13 +687,13 @@
 
   if ( TYPE_FROM_HANDLE(entity_handle) == MBVERTEX )
   {
-    EntitySequence* seq = 0;
+    const EntitySequence* seq = 0;
     status = sequence_manager()->find(entity_handle, seq);
 
     if (seq == 0 || status != MB_SUCCESS)
       return MB_ENTITY_NOT_FOUND;
 
-    status = static_cast<VertexSequence*>(seq)->get_coordinates_ref(entity_handle, 
+    status = static_cast<const VertexSequence*>(seq)->get_coordinates_ref(entity_handle, 
                                                                           x, y, z);
 
   }
@@ -826,7 +835,7 @@
 
   MBErrorCode result = MB_SUCCESS, temp_result;
   for (i = 0; i < num_handles; i++) {
-    EntitySequence* seq = 0;
+    const EntitySequence* seq = 0;
 
       // We know that connectivity is stored in an EntitySequence so jump straight
       // to the entity sequence
@@ -840,7 +849,7 @@
       continue;
     }
 
-    ElementSequence *elem_seq = static_cast<ElementSequence*>(seq);
+    const ElementSequence *elem_seq = static_cast<const ElementSequence*>(seq);
       // let's be smart about this...
     temp_result = elem_seq->get_connectivity(entity_handles[i], connectivity,
                                              topological_connectivity);
@@ -873,7 +882,7 @@
     return MB_FAILURE;
   }
   
-  EntitySequence* seq = 0;
+  const EntitySequence* seq = 0;
 
     // We know that connectivity is stored in an EntitySequence so jump straight
     // to the entity sequence
@@ -881,7 +890,7 @@
   if (seq == 0 || status != MB_SUCCESS) 
     return MB_ENTITY_NOT_FOUND;
 
-  return static_cast<ElementSequence*>(seq)->get_connectivity(entity_handle, 
+  return static_cast<const ElementSequence*>(seq)->get_connectivity(entity_handle, 
                                                               connectivity,
                                                               number_nodes,
                                                               topological_connectivity,
@@ -1088,11 +1097,11 @@
 {
   MBErrorCode result = MB_SUCCESS;
   if (meshset) {
-    EntitySequence* seq;
+    const EntitySequence* seq;
     result = sequence_manager()->find( meshset, seq );
     if (MB_SUCCESS != result)
       return result;
-    MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
     result = mseq->get_dimension( sequence_manager(), meshset, dimension, entities, recursive );
   }
   else if (dimension > 3) {
@@ -1120,11 +1129,11 @@
   
   MBErrorCode result = MB_SUCCESS;
   if (meshset) {
-    EntitySequence* seq;
+    const EntitySequence* seq;
     result = sequence_manager()->find( meshset, seq );
     if (MB_SUCCESS != result)
       return result;
-    MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
     result = mseq->get_type( sequence_manager(), meshset, type, entities, recursive );
   }  
   else {
@@ -1179,11 +1188,11 @@
 {
   MBErrorCode result = MB_SUCCESS;
   if (meshset) {
-    EntitySequence* seq;
+    const EntitySequence* seq;
     result = sequence_manager()->find( meshset, seq );
     if (MB_SUCCESS != result)
       return result;
-    MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
     result = mseq->get_entities( sequence_manager(), meshset, entities, recursive );
   }  
   else {
@@ -1209,11 +1218,11 @@
     std::copy( tmp_range.begin(), tmp_range.end(), entities.begin() + offset );
   }
   else {
-    EntitySequence* seq;
+    const EntitySequence* seq;
     result = sequence_manager()->find( meshset, seq );
     if (MB_SUCCESS != result)
       return result;
-    MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
     result = mseq->get_entities( meshset, entities );
   }  
   return result;
@@ -1236,11 +1245,11 @@
     }
   }
   else {
-    EntitySequence* seq;
+    const EntitySequence* seq;
     result = sequence_manager()->find( meshset, seq );
     if (MB_SUCCESS != result)
       return result;
-    MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
     result = mseq->num_dimension( sequence_manager(), meshset, dim, number, recursive );
   }  
   
@@ -1259,11 +1268,11 @@
     return MB_TYPE_OUT_OF_RANGE;
   
   if (meshset) {
-    EntitySequence* seq;
+    const EntitySequence* seq;
     result = sequence_manager()->find( meshset, seq );
     if (MB_SUCCESS != result)
       return result;
-    MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
     result = mseq->num_type( sequence_manager(), meshset, type, num_ent, recursive );
   }
   else {
@@ -1294,11 +1303,11 @@
 {
   MBErrorCode result;
   if (meshset) {
-    EntitySequence* seq;
+    const EntitySequence* seq;
     result = sequence_manager()->find( meshset, seq );
     if (MB_SUCCESS != result)
       return result;
-    MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
     return mseq->num_entities( sequence_manager(), meshset, num_ent, recursive );
   }
 
@@ -1348,7 +1357,7 @@
     return tagServer->set_mesh_data(tag_handle, tag_data);
 
   //verify handles
-  EntitySequence* seq;
+  const EntitySequence* seq;
   const MBEntityHandle* iter;
   const MBEntityHandle* end = entity_handles + num_entities;
   for(iter = entity_handles; iter != end; ++iter)
@@ -2143,7 +2152,7 @@
 MBErrorCode MBCore::get_meshset_options( const MBEntityHandle ms_handle, 
                                           unsigned int& options) const
 {
-  MBMeshSet* set = get_mesh_set( sequence_manager(), ms_handle );
+  const MBMeshSet* set = get_mesh_set( sequence_manager(), ms_handle );
   if (!set)
     return MB_ENTITY_NOT_FOUND;
   
@@ -2309,11 +2318,11 @@
 {
   if (0 == meshset) return MB_SUCCESS;
 
-  EntitySequence *seq;
+  const EntitySequence *seq;
   MBErrorCode rval = sequence_manager()->find( meshset, seq );
   if (MB_SUCCESS != rval)
     return MB_ENTITY_NOT_FOUND;
-  MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
 
   return mseq->get_parents( sequence_manager(), meshset, parents, num_hops );
 }
@@ -2338,11 +2347,11 @@
 {
   if (0 == meshset) return MB_SUCCESS;
 
-  EntitySequence *seq;
+  const EntitySequence *seq;
   MBErrorCode rval = sequence_manager()->find( meshset, seq );
   if (MB_SUCCESS != rval)
     return MB_ENTITY_NOT_FOUND;
-  MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
 
   return mseq->get_children( sequence_manager(), meshset, children, num_hops );
 }
@@ -2369,11 +2378,11 @@
     return MB_SUCCESS;
   }
 
-  EntitySequence *seq;
+  const EntitySequence *seq;
   MBErrorCode rval = sequence_manager()->find( meshset, seq );
   if (MB_SUCCESS != rval)
     return MB_ENTITY_NOT_FOUND;
-  MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
 
   return mseq->num_parents( sequence_manager(), meshset, *number, num_hops );
 }
@@ -2386,11 +2395,11 @@
     return MB_SUCCESS;
   }
   
-  EntitySequence *seq;
+  const EntitySequence *seq;
   MBErrorCode rval = sequence_manager()->find( meshset, seq );
   if (MB_SUCCESS != rval)
     return MB_ENTITY_NOT_FOUND;
-  MeshSetSequence* mseq = reinterpret_cast<MeshSetSequence*>(seq);
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
 
   return mseq->num_children( sequence_manager(), meshset, *number, num_hops );
 }
@@ -2706,7 +2715,7 @@
 
 bool MBCore::is_valid(const MBEntityHandle this_ent) const
 {
-  EntitySequence* seq = 0;
+  const EntitySequence* seq = 0;
   MBErrorCode result = sequence_manager()->find(this_ent, seq);
   return seq != 0 && result == MB_SUCCESS;
 }

Modified: MOAB/trunk/MeshSetSequence.cpp
===================================================================
--- MOAB/trunk/MeshSetSequence.cpp	2007-11-12 21:17:17 UTC (rev 1381)
+++ MOAB/trunk/MeshSetSequence.cpp	2007-11-13 18:16:35 UTC (rev 1382)
@@ -154,9 +154,9 @@
     return MB_SUCCESS;
   }
   else {
-    std::vector<MBMeshSet*> list;
+    std::vector<const MBMeshSet*> list;
     MBErrorCode rval = recursive_get_sets( handle, seqman, list );
-    for (std::vector<MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
+    for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_non_set_entities( entities );
     return rval;
   }
@@ -180,9 +180,9 @@
     return MB_SUCCESS;
   }
   else {
-    std::vector<MBMeshSet*> list;
+    std::vector<const MBMeshSet*> list;
     MBErrorCode rval = recursive_get_sets( handle, seqman, list );
-    for (std::vector<MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
+    for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_entities_by_dimension( dimension, entities );
     return rval;
   }
@@ -199,9 +199,9 @@
     return MB_SUCCESS;
   }
   else {
-    std::vector<MBMeshSet*> list;
+    std::vector<const MBMeshSet*> list;
     MBErrorCode rval = recursive_get_sets( handle, seqman, list );
-    for (std::vector<MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
+    for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_entities_by_type( type, entities );
     return rval;
   }
@@ -262,7 +262,7 @@
 
 MBErrorCode MeshSetSequence::recursive_get_sets( MBEntityHandle start_set,
                               const SequenceManager* seq_sets,
-                              std::vector<MBMeshSet*>& sets ) const
+                              std::vector<const MBMeshSet*>& sets )
 {
   std::set<MBEntityHandle> visited;
   std::vector<MBEntityHandle> stack;
@@ -274,6 +274,37 @@
     if (!visited.insert(handle).second)
       continue;
     
+    const EntitySequence* seq;
+    MBErrorCode rval = seq_sets->find( handle, seq );
+    if (MB_SUCCESS != rval)
+      return rval;
+    
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    const MBMeshSet *ms_ptr = mseq->get_set( handle );
+    sets.push_back( ms_ptr );
+    
+    MBRange tmp_range;
+    ms_ptr->get_entities_by_type( MBENTITYSET, tmp_range );
+    std::copy( tmp_range.begin(), tmp_range.end(), std::back_inserter( stack ) );
+  }
+    
+  return MB_SUCCESS;
+}
+
+MBErrorCode MeshSetSequence::recursive_get_sets( MBEntityHandle start_set,
+                              SequenceManager* seq_sets,
+                              std::vector<MBMeshSet*>& sets )
+{
+  std::set<MBEntityHandle> visited;
+  std::vector<MBEntityHandle> stack;
+  stack.push_back( start_set );
+  while (!stack.empty()) {
+    MBEntityHandle handle = stack.back();
+    stack.pop_back();
+    
+    if (!visited.insert(handle).second)
+      continue;
+    
     EntitySequence* seq;
     MBErrorCode rval = seq_sets->find( handle, seq );
     if (MB_SUCCESS != rval)
@@ -319,11 +350,11 @@
       // for each set at the current num_hops
     for (i = lists[index].begin(); i != lists[index].end(); ++i) {
         // get meshset from handle
-      EntitySequence* seq;
+      const EntitySequence* seq;
       MBErrorCode rval = seq_sets->find( *i, seq );
       if (MB_SUCCESS != rval)
         return rval;
-      MBMeshSet *ms_ptr = reinterpret_cast<MeshSetSequence*>(seq)->get_set( *i );
+      const MBMeshSet *ms_ptr = reinterpret_cast<const MeshSetSequence*>(seq)->get_set( *i );
       
         // querying for parents or children?
       array = parents ? ms_ptr->get_parents(count) : ms_ptr->get_children(count);

Modified: MOAB/trunk/MeshSetSequence.hpp
===================================================================
--- MOAB/trunk/MeshSetSequence.hpp	2007-11-12 21:17:17 UTC (rev 1381)
+++ MOAB/trunk/MeshSetSequence.hpp	2007-11-13 18:16:35 UTC (rev 1382)
@@ -99,9 +99,12 @@
                                     std::vector<MBEntityHandle>& results,
                                     int num_hops, bool parents ) const;
                                     
-  MBErrorCode recursive_get_sets( MBEntityHandle start_set,
+  static MBErrorCode recursive_get_sets( MBEntityHandle start_set,
                             SequenceManager const* set_sequences,
-                            std::vector<MBMeshSet*>& sets_out ) const ;
+                            std::vector<const MBMeshSet*>& sets_out );
+  static MBErrorCode recursive_get_sets( MBEntityHandle start_set,
+                            SequenceManager* set_sequences,
+                            std::vector<MBMeshSet*>& sets_out );
   
   enum {
     SET_SIZE = (sizeof(MBMeshSet_MBRange) > sizeof(MBMeshSet_Vector)) ?

Modified: MOAB/trunk/SequenceData.cpp
===================================================================
--- MOAB/trunk/SequenceData.cpp	2007-11-12 21:17:17 UTC (rev 1381)
+++ MOAB/trunk/SequenceData.cpp	2007-11-13 18:16:35 UTC (rev 1382)
@@ -8,7 +8,7 @@
   free( arraySet - numSequenceData );
 }
 
-void* SequenceData::create_data( int index, int bytes_per_ent, void* initial_value )
+void* SequenceData::create_data( int index, int bytes_per_ent, const void* initial_value )
 {  
   char* array = (char*)malloc( bytes_per_ent * size() );
   if (initial_value) {
@@ -29,7 +29,7 @@
 
 void* SequenceData::create_sequence_data( int array_num,
                                           int bytes_per_ent,
-                                          void* initial_value )
+                                          const void* initial_value )
 {
   const int index = -1 - array_num;
   assert( array_num < numSequenceData );
@@ -61,7 +61,7 @@
 
 void* SequenceData::create_tag_data( int tag_num,
                                      int bytes_per_ent,
-                                     void* initial_val )
+                                     const void* initial_val )
 {
   const int index = tag_num + 1;
   if (tag_num >= numTagData) {

Modified: MOAB/trunk/SequenceData.hpp
===================================================================
--- MOAB/trunk/SequenceData.hpp	2007-11-12 21:17:17 UTC (rev 1381)
+++ MOAB/trunk/SequenceData.hpp	2007-11-13 18:16:35 UTC (rev 1382)
@@ -46,13 +46,13 @@
   
   void* create_sequence_data( int array_num, 
                               int bytes_per_ent,
-                              void* initial_val = 0 );
+                              const void* initial_val = 0 );
                              
   void* create_custom_data( int array_num, size_t total_bytes );
   
   AdjacencyDataType* allocate_adjacency_data();
   
-  void* create_tag_data( int tag_num, int bytes_per_ent, void* initial_val = 0 );
+  void* create_tag_data( int tag_num, int bytes_per_ent, const void* initial_val = 0 );
   
   SequenceData* subset( MBEntityHandle start, 
                         MBEntityHandle end,
@@ -73,7 +73,7 @@
 
 private:
 
-  void* create_data( int index, int bytes_per_ent, void* initial_val = 0 );
+  void* create_data( int index, int bytes_per_ent, const void* initial_val = 0 );
   void copy_data_subset( int index, 
                          int size_per_ent, 
                          const void* source, 

Modified: MOAB/trunk/SequenceManager.hpp
===================================================================
--- MOAB/trunk/SequenceManager.hpp	2007-11-12 21:17:17 UTC (rev 1381)
+++ MOAB/trunk/SequenceManager.hpp	2007-11-13 18:16:35 UTC (rev 1382)
@@ -15,11 +15,16 @@
       : handleUtils(handle_utils)
       {}
     
-    MBErrorCode find( MBEntityHandle handle, EntitySequence*& sequence_out ) const
+    MBErrorCode find( MBEntityHandle handle, EntitySequence*& sequence_out )
       { 
         return typeData[TYPE_FROM_HANDLE(handle)].find( handle, sequence_out );
       }
     
+    MBErrorCode find( MBEntityHandle handle, const EntitySequence*& sequence_out ) const
+      { 
+        return typeData[TYPE_FROM_HANDLE(handle)].find( handle, sequence_out );
+      }
+    
     void get_entities( MBEntityType type, MBRange& entities_out ) const
       { typeData[type].get_entities( entities_out ); }
     

Modified: MOAB/trunk/TypeSequenceManager.hpp
===================================================================
--- MOAB/trunk/TypeSequenceManager.hpp	2007-11-12 21:17:17 UTC (rev 1381)
+++ MOAB/trunk/TypeSequenceManager.hpp	2007-11-13 18:16:35 UTC (rev 1382)
@@ -166,7 +166,8 @@
      *\return EntitySequence for handle, or NULL if no such sequence.
      */
   inline EntitySequence* find( MBEntityHandle h ) const;
-  inline MBErrorCode find( MBEntityHandle h, EntitySequence*& ) const;
+  inline MBErrorCode find( MBEntityHandle h, EntitySequence*& );
+  inline MBErrorCode find( MBEntityHandle h, const EntitySequence*& ) const;
   
     /**\brief Get handles for all entities in all sequences. */
   inline void get_entities( MBRange& entities_out ) const;
@@ -339,7 +340,7 @@
   }
 }   
 
-inline MBErrorCode TypeSequenceManager::find( MBEntityHandle h, EntitySequence*& seq ) const
+inline MBErrorCode TypeSequenceManager::find( MBEntityHandle h, EntitySequence*& seq )
 {
   if (!lastReferenced) { // only null if empty
     seq = 0;
@@ -362,6 +363,30 @@
     }
   }
 }   
+
+inline MBErrorCode TypeSequenceManager::find( MBEntityHandle h, const EntitySequence*& seq ) const
+{
+  if (!lastReferenced) { // only null if empty
+    seq = 0;
+    return MB_ENTITY_NOT_FOUND;
+  }
+  else if (h >= lastReferenced->start_handle() && h <= lastReferenced->end_handle()) {
+    seq = lastReferenced;
+    return MB_SUCCESS;
+  }
+  else {
+    DummySequence ds(h);
+    iterator i = sequenceSet.lower_bound( &ds );
+    if (i == end() || (*i)->start_handle() > h ) {
+      seq = 0;
+      return MB_ENTITY_NOT_FOUND;
+    }
+    else {
+      seq = lastReferenced = *i;
+      return MB_SUCCESS;
+    }
+  }
+}   
   
 inline void TypeSequenceManager::get_entities( MBRange& entities_out ) const
 {




More information about the moab-dev mailing list