moab
MeshSet.hpp
Go to the documentation of this file.
00001 #ifndef MB_MESHSET_HPP
00002 #define MB_MESHSET_HPP
00003 
00004 #ifndef IS_BUILDING_MB
00005 #error "MB_MeshSet.hpp isn't supposed to be included into an application"
00006 #endif
00007 
00008 #include "moab/Interface.hpp"
00009 #include "Internals.hpp"
00010 #include "moab/Range.hpp"
00011 #include "moab/CN.hpp"
00012 
00013 #include <assert.h>
00014 #include <vector>
00015 #include <algorithm>
00016 #include <iterator>
00017 
00018 namespace moab {
00019 
00020 class AEntityFactory;
00021 
00025 class MeshSet
00026 {
00027 public:
00028 
00030   inline MeshSet();
00031   inline MeshSet(unsigned flags);
00032 
00034   inline ~MeshSet();
00035   
00036   inline ErrorCode set_flags( unsigned flags, EntityHandle my_handle, AEntityFactory* adjacencies );
00037     
00038 
00040   inline const EntityHandle* get_children( int& count_out ) const ;
00041 
00043   inline const EntityHandle* get_parents( int& count_out ) const;
00044 
00046   inline int num_children() const ;
00047     
00049   inline int num_parents() const;
00050 
00053   int add_parent(EntityHandle parent);
00054     
00057   int add_child(EntityHandle child);
00058     
00061   int remove_parent(EntityHandle parent);
00062     
00065   int remove_child(EntityHandle child);
00066 
00067   unsigned flags() const { return mFlags; }
00069   int tracking()     const { return mFlags & MESHSET_TRACK_OWNER; }
00070   int set()          const { return mFlags & MESHSET_SET; }
00071   int ordered()      const { return mFlags & MESHSET_ORDERED; }
00072   int vector_based() const { return ordered(); }
00073 
00076   ErrorCode replace_entities(EntityHandle my_handle, 
00077                                const EntityHandle *old_entities, 
00078                                const EntityHandle *new_entities,
00079                                size_t num_entities,
00080                                AEntityFactory* mAdjFact);
00081   
00083   inline ErrorCode clear( EntityHandle myhandle, AEntityFactory* adjacencies );
00084   
00086   inline ErrorCode clear_all( EntityHandle myhandle, AEntityFactory* adjacencies );
00087 
00089   inline const EntityHandle* get_contents( size_t& count_out ) const;
00091   inline EntityHandle* get_contents( size_t& count_out );
00092 
00094   inline ErrorCode get_entities(std::vector<EntityHandle>& entities) const;
00095 
00097   inline ErrorCode get_entities( Range& entities ) const;
00098   
00100   inline ErrorCode get_entities_by_type(EntityType entity_type, std::vector<EntityHandle> &entity_list) const;
00101   
00102   inline ErrorCode get_entities_by_type( EntityType type, Range& entity_list) const;
00103     
00105   inline unsigned int num_entities_by_type(EntityType type) const;
00106       
00107   inline ErrorCode get_entities_by_dimension( int dimension, std::vector<EntityHandle> &entity_list) const;
00108 
00109   inline ErrorCode get_entities_by_dimension( int dimension, Range& entity_list) const;
00110   
00112   inline unsigned int num_entities_by_dimension(int dimension) const;
00113       
00114   inline ErrorCode get_non_set_entities( Range& range ) const;
00115 
00123   inline bool contains_entities(const EntityHandle *entities, int num_entities, const int op) const;
00124 
00125   
00127   inline ErrorCode subtract(const MeshSet *meshset_2,
00128                                EntityHandle my_handle,
00129                                AEntityFactory* adjacencies);
00130 
00131   ErrorCode intersect(const MeshSet *meshset_2,
00132                                 EntityHandle my_handle,
00133                                 AEntityFactory* adjacencies);
00134 
00135   inline ErrorCode unite(const MeshSet *meshset_2,
00136                             EntityHandle my_handle,
00137                             AEntityFactory* adjacencies);
00138 
00140   inline ErrorCode add_entities(const EntityHandle *entity_handles,
00141                                    const int num_entities,
00142                                    EntityHandle my_handle,
00143                                    AEntityFactory* adjacencies);
00144     
00146   inline ErrorCode add_entities(const Range &entities,
00147                                    EntityHandle my_handle,
00148                                    AEntityFactory* adjacencies);
00149     
00151   inline ErrorCode remove_entities(const Range& entities,
00152                                       EntityHandle my_handle,
00153                                       AEntityFactory* adjacencies);
00154     
00155    
00157   inline ErrorCode remove_entities(const EntityHandle *entities,
00158                                       const int num_entities,
00159                                       EntityHandle my_handle,
00160                                       AEntityFactory* adjacencies);
00161 
00163   inline unsigned int num_entities() const;
00164   
00165   inline bool empty() const { return mContentCount == ZERO; }
00166   
00167   unsigned long get_memory_use() const;
00168 
00169 protected:
00170   
00172   ErrorCode convert( unsigned flags, EntityHandle my_handle, AEntityFactory* adj );
00173 
00175   ErrorCode create_adjacencies( EntityHandle myhandle, AEntityFactory* adjacencies );
00176 
00178   ErrorCode remove_adjacencies( EntityHandle myhandle, AEntityFactory* adjacencies );
00179 
00181   ErrorCode insert_entity_vector( const EntityHandle* vect, size_t len, EntityHandle my_h, AEntityFactory* adj );
00182  
00184   ErrorCode insert_entity_ranges( const EntityHandle* range_vect, size_t len, EntityHandle my_h, AEntityFactory* adj );
00185 
00187   ErrorCode insert_entity_ranges( const Range& range, EntityHandle my_h, AEntityFactory* adj );
00188 
00190   ErrorCode remove_entity_vector( const EntityHandle* vect, size_t len, EntityHandle my_h, AEntityFactory* adj );
00191 
00193   ErrorCode remove_entity_ranges( const EntityHandle* range_vect, size_t len, EntityHandle my_h, AEntityFactory* adj );
00194 
00196   ErrorCode remove_entity_ranges( const Range& range, EntityHandle my_h, AEntityFactory* adj );
00197 
00198 public:  
00200   enum Count { ZERO=0, ONE=1, TWO=2, MANY=3 };
00205   union CompactList {
00206     EntityHandle hnd[2];  
00207     EntityHandle* ptr[2]; 
00208   };
00209 
00210 private:
00212   unsigned char mFlags;
00217   unsigned mParentCount : 2;
00222   unsigned mChildCount : 2;
00226   unsigned mContentCount : 2;
00228   CompactList parentMeshSets, childMeshSets, contentList;
00229 
00230 public:
00232   static inline int DIM_FROM_HANDLE( EntityHandle h )
00233     { return CN::Dimension( TYPE_FROM_HANDLE( h ) ); }
00234   
00236   static inline EntityHandle FIRST_OF_DIM( int dim )
00237     { return FIRST_HANDLE( CN::TypeDimensionMap[dim].first ); }
00238   
00240   static inline EntityHandle LAST_OF_DIM( int dim )
00241     { return LAST_HANDLE( CN::TypeDimensionMap[dim].second ); }
00242 
00244   struct not_type_test {
00245       inline not_type_test( EntityType type ) : mType(type) {}
00246       inline bool operator()( EntityHandle handle )
00247         { return TYPE_FROM_HANDLE(handle) != mType; }
00248       EntityType mType;
00249   };
00250 
00252   struct type_test {
00253       inline type_test( EntityType type ) : mType(type) {}
00254       inline bool operator()( EntityHandle handle )
00255         { return TYPE_FROM_HANDLE(handle) == mType; }
00256       EntityType mType;
00257   };
00258 
00260   struct not_dim_test {
00261       inline not_dim_test( int dimension ) : mDim(dimension) {}
00262       inline bool operator()( EntityHandle handle ) const
00263         { return DIM_FROM_HANDLE(handle) != mDim; }
00264       int mDim;
00265   };
00266 
00268   struct dim_test {
00269       inline dim_test( int dimension ) : mDim(dimension) {}
00270       inline bool operator()( EntityHandle handle ) const
00271         { return DIM_FROM_HANDLE(handle) == mDim; }
00272       int mDim;
00273   };
00274   
00278   struct hdl_iter {
00279     EntityHandle h;
00280     hdl_iter( EntityHandle val ) : h(val) {}
00281     hdl_iter& operator++() { ++h; return *this; }
00282     hdl_iter& operator--() { --h; return *this; }
00283     hdl_iter operator++(int) { return hdl_iter(h++); }
00284     hdl_iter operator--(int) { return hdl_iter(h--); }
00285     hdl_iter& operator+=(size_t s) { h += s; return *this; }
00286     hdl_iter& operator-=(size_t s) { h -= s; return *this; }
00287     EntityHandle operator*() const { return h; }
00288     bool operator==(hdl_iter other) const { return h == other.h; }
00289     bool operator!=(hdl_iter other) const { return h != other.h; }
00290     bool operator< (hdl_iter other) const { return h <  other.h; }
00291     bool operator> (hdl_iter other) const { return h >  other.h; }
00292     bool operator<=(hdl_iter other) const { return h <= other.h; }
00293     bool operator>=(hdl_iter other) const { return h >= other.h; }
00294     
00295     struct iterator_category : public std::random_access_iterator_tag { };
00296     typedef EntityID difference_type;
00297     typedef EntityHandle value_type;
00298     typedef EntityHandle* pointer;
00299     typedef EntityHandle& reference;
00300   };
00301   
00302 };
00303 
00304 inline MeshSet::hdl_iter::difference_type
00305  operator-( const MeshSet::hdl_iter a, const MeshSet::hdl_iter b )
00306   { return (MeshSet::hdl_iter::difference_type)a.h 
00307          - (MeshSet::hdl_iter::difference_type)b.h; }
00308 
00309 
00311 MeshSet::MeshSet()
00312   : mFlags(0), mParentCount(ZERO), mChildCount(ZERO), mContentCount(ZERO)
00313 { }
00314 
00316 MeshSet::MeshSet(unsigned flg)
00317         : mFlags((unsigned char)flg), mParentCount(ZERO), mChildCount(ZERO), mContentCount(ZERO)
00318 { }
00319 
00321 MeshSet::~MeshSet() 
00322 {
00323   if (mChildCount == MANY)
00324     free( childMeshSets.ptr[0] );
00325   if (mParentCount == MANY)
00326     free( parentMeshSets.ptr[0] );
00327   if (mContentCount == MANY)
00328     free( contentList.ptr[0] );
00329   mChildCount = mParentCount = mContentCount = ZERO;
00330 }
00331   
00332 ErrorCode MeshSet::set_flags( unsigned flg, EntityHandle my_handle, AEntityFactory* adjacencies ) 
00333 {
00334   if(ZERO != mContentCount) {
00335     ErrorCode result = convert(flg, my_handle, adjacencies);
00336     if(MB_SUCCESS != result) return result;
00337   }
00338   mFlags = (unsigned char)flg;
00339   return MB_SUCCESS;
00340 }
00341     
00342 
00344 const EntityHandle* MeshSet::get_children( int& count_out ) const 
00345 { 
00346   count_out = mChildCount;
00347   if (count_out < MANY)
00348     return childMeshSets.hnd;
00349 
00350   count_out = childMeshSets.ptr[1] - childMeshSets.ptr[0];
00351   return childMeshSets.ptr[0];
00352 }
00353 
00355 const EntityHandle* MeshSet::get_parents( int& count_out ) const
00356 { 
00357   count_out = mParentCount;
00358   if (count_out < MANY)
00359     return parentMeshSets.hnd;
00360 
00361   count_out = parentMeshSets.ptr[1] - parentMeshSets.ptr[0];
00362   return parentMeshSets.ptr[0];
00363 }
00364 
00366 int MeshSet::num_children() const 
00367 {
00368   if (mChildCount < MANY)
00369     return mChildCount;
00370   else
00371     return childMeshSets.ptr[1] - childMeshSets.ptr[0];
00372 }
00373 
00375 int MeshSet::num_parents() const
00376 {
00377   if (mParentCount < MANY)
00378     return mParentCount;
00379   else
00380     return parentMeshSets.ptr[1] - parentMeshSets.ptr[0];
00381 }
00382   
00383 inline ErrorCode MeshSet::clear( EntityHandle myhandle, AEntityFactory* adjacencies )
00384 { 
00385   if (tracking())
00386     remove_adjacencies( myhandle, adjacencies );
00387   if (mContentCount == MANY)
00388     free( contentList.ptr[0] );
00389   mContentCount = ZERO;
00390   return MB_SUCCESS;
00391 }
00392   
00393 inline ErrorCode MeshSet::clear_all( EntityHandle myhandle, AEntityFactory* adjacencies )
00394 { 
00395   ErrorCode rval = clear( myhandle, adjacencies );
00396   if (mChildCount == MANY)
00397     free( childMeshSets.ptr[0] );
00398   mChildCount = ZERO;
00399   if (mParentCount == MANY)
00400     free( parentMeshSets.ptr[0] );
00401   mParentCount = ZERO;
00402   return rval;
00403 }
00404 
00405 inline const EntityHandle* MeshSet::get_contents( size_t& count_out ) const
00406 {
00407   if (mContentCount == MANY) {
00408     count_out = contentList.ptr[1] - contentList.ptr[0];
00409     return contentList.ptr[0];
00410   }
00411   else {
00412     count_out = mContentCount;
00413     return contentList.hnd;
00414   }
00415 }
00416 
00417 inline EntityHandle* MeshSet::get_contents( size_t& count_out )
00418 {
00419   if (mContentCount == MANY) {
00420     count_out = contentList.ptr[1] - contentList.ptr[0];
00421     return contentList.ptr[0];
00422   }
00423   else {
00424     count_out = mContentCount;
00425     return contentList.hnd;
00426   }
00427 }
00428 
00429 inline ErrorCode MeshSet::get_entities(std::vector<EntityHandle>& entities) const
00430 {
00431   size_t count;
00432   const EntityHandle* ptr = get_contents( count );
00433   if (vector_based()) {
00434     size_t old_size = entities.size();
00435     entities.resize( count+old_size );
00436     std::copy( ptr, ptr+count, entities.begin()+old_size );
00437   }
00438   else {
00439     assert(count%2 == 0);
00440     for (size_t i = 0; i < count; i += 2) 
00441       std::copy( hdl_iter(ptr[i]), hdl_iter(ptr[i+1]+1), std::back_inserter(entities) );
00442   }
00443   return MB_SUCCESS;
00444 } 
00445 
00446 inline ErrorCode MeshSet::get_entities(Range& entities) const
00447 {
00448   size_t count;
00449   const EntityHandle* ptr = get_contents( count );
00450   if (vector_based()) {
00451     std::copy( ptr, ptr+count, range_inserter(entities) );
00452   }
00453   else {
00454     assert(count%2 == 0);
00455     Range::iterator in = entities.begin();
00456     for (size_t i = 0; i < count; i += 2) 
00457       in = entities.insert( in, ptr[i], ptr[i+1] );
00458   }
00459   return MB_SUCCESS;
00460 } 
00461 
00462 
00464 inline ErrorCode MeshSet::get_entities_by_type(EntityType type,
00465                                                std::vector<EntityHandle> &entity_list
00466                                                ) const
00467 {
00468   size_t count;
00469   const EntityHandle* ptr = get_contents( count );
00470   if (MBMAXTYPE == type) {
00471     return get_entities( entity_list);
00472   }
00473   else if (vector_based()) {
00474     std::remove_copy_if( ptr, ptr+count, 
00475                          std::back_inserter( entity_list ),
00476                          not_type_test(type) );
00477   }
00478   else {
00479     size_t idx = std::lower_bound( ptr, ptr+count, FIRST_HANDLE(type) ) - ptr;
00480     if (idx < count && TYPE_FROM_HANDLE(ptr[idx]) == type) {
00481       if (idx % 2) { // only part of first block is of type
00482         std::copy( hdl_iter(FIRST_HANDLE(type)), hdl_iter(ptr[idx]+1), std::back_inserter( entity_list ) );
00483         ++idx;
00484       }
00485       for (; idx < count; idx += 2) {
00486         if (TYPE_FROM_HANDLE(ptr[idx+1]) == type) // whole block is of type
00487           std::copy( hdl_iter(ptr[idx]), hdl_iter(ptr[idx+1]+1), std::back_inserter( entity_list ) );
00488         else {
00489           if (TYPE_FROM_HANDLE(ptr[idx]) == type) // part of last block is of type
00490             std::copy( hdl_iter(ptr[idx]), hdl_iter(LAST_HANDLE(type)), std::back_inserter( entity_list ) );
00491           break;
00492         }
00493       }
00494     }
00495   }
00496 
00497   return MB_SUCCESS;
00498 }
00499 
00500 
00501 inline ErrorCode MeshSet::get_entities_by_type( EntityType type,
00502                                                     Range& entity_list) const
00503 {
00504   size_t count;
00505   const EntityHandle* ptr = get_contents( count );
00506   if (MBMAXTYPE == type) {
00507     return get_entities( entity_list );
00508   }
00509   else if (vector_based()) {
00510     std::remove_copy_if( ptr, ptr+count, 
00511                          range_inserter( entity_list ),
00512                          not_type_test(type) );
00513   }
00514   else {
00515     size_t idx = std::lower_bound( ptr, ptr+count, FIRST_HANDLE(type) ) - ptr;
00516     Range::iterator in = entity_list.begin();
00517     if (idx < count && TYPE_FROM_HANDLE(ptr[idx]) == type) {
00518       if (idx % 2) { // only part of first block is of type
00519         in = entity_list.insert( in, FIRST_HANDLE(type), ptr[idx] );
00520         ++idx;
00521       }
00522       for (; idx < count; idx += 2) {
00523         if (TYPE_FROM_HANDLE(ptr[idx+1]) == type) // whole block is of type
00524           in = entity_list.insert( in, ptr[idx], ptr[idx+1] );
00525         else {
00526           if (TYPE_FROM_HANDLE(ptr[idx]) == type) // part of last block is of type
00527             entity_list.insert( in, ptr[idx], LAST_HANDLE(type) );
00528           break;
00529         }
00530       }
00531     }
00532   }
00533 
00534   return MB_SUCCESS;
00535 }
00536 
00538 inline unsigned int MeshSet::num_entities_by_type(EntityType type) const
00539 {
00540   unsigned int result;
00541   size_t count;
00542   const EntityHandle* ptr = get_contents( count );
00543   if (MBMAXTYPE == type) {
00544     return num_entities( );
00545   }
00546   else if (vector_based()) {
00547     #ifndef __SUNPRO_CC
00548       result = std::count_if( ptr, ptr+count, type_test(type) );
00549     #else
00550       std::count_if( ptr, ptr+count, type_test(type), result );
00551     #endif
00552   }
00553   else {
00554     result = 0;
00555     size_t idx = std::lower_bound( ptr, ptr+count, FIRST_HANDLE(type) ) - ptr;
00556     if (idx < count && TYPE_FROM_HANDLE(ptr[idx]) == type) {
00557       if (idx % 2) { // only part of first block is of type
00558         result += ptr[idx] - FIRST_HANDLE(type) + 1;
00559         ++idx;
00560       }
00561       for (; idx < count; idx += 2) {
00562         if (TYPE_FROM_HANDLE(ptr[idx+1]) == type) // whole block is of type
00563           result += ptr[idx+1] - ptr[idx] + 1;
00564         else {
00565           if (TYPE_FROM_HANDLE(ptr[idx]) == type) // part of last block is of type
00566             result += LAST_HANDLE(type) - ptr[idx] + 1;
00567           break;
00568         }
00569       }
00570     }
00571   }
00572 
00573   return result;
00574 }
00575 
00576 inline ErrorCode MeshSet::get_entities_by_dimension( int dimension,
00577                                                          std::vector<EntityHandle> &entity_list
00578                                                          ) const
00579 {
00580   size_t count;
00581   const EntityHandle* ptr = get_contents( count );
00582   if (vector_based()) {
00583     std::remove_copy_if( ptr, ptr+count, 
00584                          std::back_inserter( entity_list ),
00585                          not_dim_test(dimension) );
00586   }
00587   else {
00588     size_t idx = std::lower_bound( ptr, ptr+count, FIRST_OF_DIM(dimension) ) - ptr;
00589     if (idx < count && DIM_FROM_HANDLE(ptr[idx]) == dimension) {
00590       if (idx % 2) { // only part of first block is of type
00591         std::copy( hdl_iter(FIRST_OF_DIM(dimension)), hdl_iter(ptr[idx]+1), std::back_inserter( entity_list ) );
00592         ++idx;
00593       }
00594       for (; idx < count; idx += 2) {
00595         if (DIM_FROM_HANDLE(ptr[idx+1]) == dimension) // whole block is of type
00596           std::copy( hdl_iter(ptr[idx]), hdl_iter(ptr[idx+1]+1), std::back_inserter( entity_list ) );
00597         else {
00598           if (DIM_FROM_HANDLE(ptr[idx]) == dimension) // part of last block is of type
00599             std::copy( hdl_iter(ptr[idx]), hdl_iter(LAST_OF_DIM(dimension)), std::back_inserter( entity_list ) );
00600           break;
00601         }
00602       }
00603     }
00604   }
00605 
00606   return MB_SUCCESS;
00607 }
00608 
00609 
00610 inline ErrorCode MeshSet::get_entities_by_dimension( int dimension,
00611                                                          Range& entity_list) const
00612 {
00613   size_t count;
00614   const EntityHandle* ptr = get_contents( count );
00615   if (vector_based()) {
00616     std::remove_copy_if( ptr, ptr+count, 
00617                          range_inserter( entity_list ),
00618                          not_dim_test(dimension) );
00619   }
00620   else {
00621     size_t idx = std::lower_bound( ptr, ptr+count, FIRST_OF_DIM(dimension) ) - ptr;
00622     Range::iterator in = entity_list.begin();
00623     if (idx < count && DIM_FROM_HANDLE(ptr[idx]) == dimension) {
00624       if (idx % 2) { // only part of first block is of type
00625         in = entity_list.insert( in, FIRST_OF_DIM(dimension), ptr[idx] );
00626         ++idx;
00627       }
00628       for (; idx < count; idx += 2) {
00629         if (DIM_FROM_HANDLE(ptr[idx+1]) == dimension) // whole block is of type
00630           in = entity_list.insert( in, ptr[idx], ptr[idx+1] );
00631         else {
00632           if (DIM_FROM_HANDLE(ptr[idx]) == dimension) // part of last block is of type
00633             entity_list.insert( in, ptr[idx], LAST_OF_DIM(dimension) );
00634           break;
00635         }
00636       }
00637     }
00638   }
00639 
00640   return MB_SUCCESS;
00641 }
00642 
00644 inline unsigned int MeshSet::num_entities_by_dimension(int dimension) const
00645 {
00646   unsigned int result;
00647   size_t count;
00648   const EntityHandle* ptr = get_contents( count );
00649   if (vector_based()) {
00650     #ifndef __SUNPRO_CC
00651       result = std::count_if( ptr, ptr+count, dim_test(dimension) );
00652     #else
00653       std::count_if( ptr, ptr+count, dim_test(dimension), result );
00654     #endif
00655   }
00656   else {
00657     result = 0;
00658     size_t idx = std::lower_bound( ptr, ptr+count, FIRST_OF_DIM(dimension) ) - ptr;
00659     if (idx < count && DIM_FROM_HANDLE(ptr[idx]) == dimension) {
00660       if (idx % 2) { // only part of first block is of type
00661         result += ptr[idx] - FIRST_OF_DIM(dimension) + 1;
00662         ++idx;
00663       }
00664       for (; idx < count; idx += 2) {
00665         if (DIM_FROM_HANDLE(ptr[idx+1]) == dimension) // whole block is of type
00666           result += ptr[idx+1] - ptr[idx] + 1;
00667         else {
00668           if (DIM_FROM_HANDLE(ptr[idx]) == dimension) // part of last block is of type
00669             result += LAST_OF_DIM(dimension) - ptr[idx] + 1;
00670           break;
00671         }
00672       }
00673     }
00674   }
00675 
00676   return result;
00677 }
00678 
00679 inline ErrorCode MeshSet::get_non_set_entities( Range& range ) const
00680 {
00681   size_t count;
00682   const EntityHandle* ptr = get_contents( count );
00683   if (vector_based()) {
00684     std::remove_copy_if( ptr, ptr+count, 
00685                          range_inserter( range ),
00686                          type_test(MBENTITYSET) );
00687   }
00688   else {
00689     Range::iterator in = range.begin();
00690     for (size_t idx = 0; idx < count; idx += 2) {
00691       if (TYPE_FROM_HANDLE(ptr[idx+1]) != MBENTITYSET)
00692         in = range.insert( in, ptr[idx], ptr[idx+1] );
00693       else {
00694         if (TYPE_FROM_HANDLE(ptr[idx]) != MBENTITYSET)
00695           in = range.insert( in, ptr[idx], LAST_HANDLE( MBENTITYSET - 1 ) );
00696         break;
00697       }
00698     }
00699   }
00700 
00701   return MB_SUCCESS;
00702 }
00703 
00704 inline bool MeshSet::contains_entities(const EntityHandle *entities, 
00705                                          int num_ents,
00706                                          const int op) const
00707 {
00708   size_t count;
00709   const EntityHandle* const ptr = get_contents( count );
00710   const EntityHandle* const end = ptr + count;
00711   size_t found_count = 0;
00712   if (vector_based()) {
00713     for (int i = 0; i < num_ents; ++i)
00714       if (std::find( ptr, end, entities[i] ) < end)
00715         ++found_count; 
00716   }
00717   else {
00718     assert(0 == count % 2);
00719     for (int i = 0; i < num_ents; ++i) {
00720       const unsigned long idx = std::lower_bound( ptr, end, entities[i] ) - ptr;
00721       if (idx < count && (idx%2 != 0 || ptr[idx] == entities[i]))
00722         ++found_count;
00723     }
00724   }
00725 
00726   return found_count >= ((Interface::INTERSECT == op) ? (unsigned)num_ents : 1u);
00727 }
00728 
00729 
00730 
00732 inline ErrorCode MeshSet::subtract(const MeshSet *meshset_2,
00733                                        EntityHandle my_handle,
00734                                        AEntityFactory* adjacencies)
00735 {
00736   size_t count;
00737   const EntityHandle* const ptr = meshset_2->get_contents( count );
00738   if (meshset_2->vector_based()) 
00739     return remove_entity_vector( ptr, count, my_handle, adjacencies );
00740   else
00741     return remove_entity_ranges( ptr, count, my_handle, adjacencies );
00742 }
00743 
00744 inline ErrorCode MeshSet::unite(const MeshSet *meshset_2,
00745                                     EntityHandle my_handle,
00746                                     AEntityFactory* adjacencies)
00747 {
00748   size_t count;
00749   const EntityHandle* const ptr = meshset_2->get_contents( count );
00750   if (meshset_2->vector_based()) 
00751     return insert_entity_vector( ptr, count, my_handle, adjacencies );
00752   else
00753     return insert_entity_ranges( ptr, count, my_handle, adjacencies );
00754 }
00755 
00757 inline ErrorCode MeshSet::add_entities(const EntityHandle *entity_handles,
00758                                            const int num_ents,
00759                                            EntityHandle my_handle,
00760                                            AEntityFactory* adjacencies)
00761 {
00762   return insert_entity_vector( entity_handles, num_ents, my_handle, adjacencies );
00763 }
00764 
00766 inline ErrorCode MeshSet::add_entities(const Range &entities,
00767                                            EntityHandle my_handle,
00768                                            AEntityFactory* adjacencies)
00769 {
00770   return insert_entity_ranges( entities, my_handle, adjacencies );
00771 }
00772 
00774 inline ErrorCode MeshSet::remove_entities(const Range& entities,
00775                                               EntityHandle my_handle,
00776                                               AEntityFactory* adjacencies)
00777 {
00778   return remove_entity_ranges(  entities, my_handle, adjacencies );
00779 }
00780 
00781 
00783 inline ErrorCode MeshSet::remove_entities(const EntityHandle *entities,
00784                                               const int num_ents,
00785                                               EntityHandle my_handle,
00786                                               AEntityFactory* adjacencies)
00787 {
00788   return remove_entity_vector( entities, num_ents, my_handle, adjacencies );
00789 }
00790 
00792 unsigned int MeshSet::num_entities() const
00793 {
00794   size_t count;
00795   const EntityHandle* list = get_contents( count );
00796   if (vector_based())
00797     return count;
00798   
00799   int result = 0;
00800   const EntityHandle *const end = list + count;
00801   for (; list < end; list += 2)
00802     result += list[1] - list[0] + 1;
00803   return result;
00804 }
00805   
00806 } // namespace moab
00807 
00808 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines