Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
moab::RangeSetIterator Class Reference

#include <SetIterator.hpp>

+ Inheritance diagram for moab::RangeSetIterator:
+ Collaboration diagram for moab::RangeSetIterator:

Public Member Functions

virtual ~RangeSetIterator ()
 Destructor. More...
 
virtual ErrorCode get_next_arr (std::vector< EntityHandle > &arr, bool &atend)
 get the next chunkSize entities Return the next chunkSize entities. More...
 
virtual ErrorCode reset ()
 reset the iterator to the beginning of the set More...
 
- Public Member Functions inherited from moab::SetIterator
virtual ~SetIterator ()
 destructor More...
 
EntityHandle ent_set () const
 get the ent set for this iterator More...
 
unsigned int chunk_size () const
 get the chunk size of this iterator More...
 
EntityType ent_type () const
 get the entity type for this iterator More...
 
int ent_dimension () const
 get the dimension for this iterator More...
 

Protected Member Functions

 RangeSetIterator (Core *core, EntityHandle ent_set, int chunk_size, EntityType ent_type, int ent_dimension, bool check_valid=false)
 Constructor. More...
 
- Protected Member Functions inherited from moab::SetIterator
 SetIterator (Core *core, EntityHandle eset, unsigned int chunk_sz, EntityType ent_tp, int ent_dim, bool check_valid=false)
 Constructor. More...
 

Private Member Functions

ErrorCode get_next_by_type (const EntityHandle *&ptr, int count, std::vector< EntityHandle > &arr, bool &atend)
 
ErrorCode get_next_by_dimension (const EntityHandle *&ptr, int count, std::vector< EntityHandle > &arr, bool &atend)
 
ErrorCode build_pair_vec ()
 Build the special pair vector for the root set. More...
 

Private Attributes

EntityHandle iterPos
 Current iterator position, 0 if at beginning. More...
 
EntityHandlepairPtr
 Special range pair ptr for root set. More...
 
int numPairs
 Number of range pairs. More...
 

Friends

class Core
 

Additional Inherited Members

- Protected Attributes inherited from moab::SetIterator
CoremyCore
 Core instance. More...
 
EntityHandle entSet
 handle for entity set corresponding to this iterator More...
 
unsigned int chunkSize
 chunk size of this iterator More...
 
EntityType entType
 entity type this iterator iterates over More...
 
int entDimension
 dimension this iterator iterates over More...
 
bool checkValid
 check for entity validity before returning handles More...
 

Detailed Description

Definition at line 95 of file SetIterator.hpp.

Constructor & Destructor Documentation

◆ ~RangeSetIterator()

moab::RangeSetIterator::~RangeSetIterator ( )
virtual

Destructor.

Definition at line 40 of file SetIterator.cpp.

41 {
42  if( pairPtr ) delete[] pairPtr;
43  numPairs = 0;
44 }

References numPairs, and pairPtr.

◆ RangeSetIterator()

moab::RangeSetIterator::RangeSetIterator ( Core core,
EntityHandle  ent_set,
int  chunk_size,
EntityType  ent_type,
int  ent_dimension,
bool  check_valid = false 
)
protected

Constructor.

Parameters
coreMOAB Core instance
ent_setEntitySet to which this iterator corresponds
chunk_sizeChunk size of this iterator
ent_typeEntity type for this iterator
ent_dimEntity dimension for this iterator

Definition at line 21 of file SetIterator.cpp.

27  : SetIterator( core, eset, chunk_sz, ent_tp, ent_dim, check_valid ), iterPos( 0 ), pairPtr( NULL ), numPairs( 0 )
28 {
29  if( !eset )
30  {
31  // special case for the root set, have to keep a local array
32  ErrorCode rval = build_pair_vec();
33  assert( MB_SUCCESS == rval );
34 
35  // empty statement to avoid warning
36  (void)( rval );
37  }
38 }

References build_pair_vec(), ErrorCode, and MB_SUCCESS.

Member Function Documentation

◆ build_pair_vec()

ErrorCode moab::RangeSetIterator::build_pair_vec ( )
private

Build the special pair vector for the root set.

Definition at line 46 of file SetIterator.cpp.

47 {
48  // shouldn't be here unless we're iterating the root set
49  assert( !entSet );
50 
51  Range all_ents;
52  ErrorCode rval = myCore->get_entities_by_handle( 0, all_ents );
53  if( MB_SUCCESS != rval ) return rval;
54 
55  if( pairPtr ) delete[] pairPtr;
56  pairPtr = new EntityHandle[2 * all_ents.psize()];
57  Range::const_pair_iterator pi;
58  int i;
59  for( pi = all_ents.const_pair_begin(), i = 0; pi != all_ents.const_pair_end(); ++pi, i += 2 )
60  {
61  pairPtr[i] = ( *pi ).first;
62  pairPtr[i + 1] = ( *pi ).second;
63  }
64  numPairs = all_ents.psize();
65 
66  return MB_SUCCESS;
67 }

References moab::Range::const_pair_begin(), moab::Range::const_pair_end(), moab::SetIterator::entSet, ErrorCode, moab::Core::get_entities_by_handle(), MB_SUCCESS, moab::SetIterator::myCore, numPairs, pairPtr, and moab::Range::psize().

Referenced by get_next_arr(), and RangeSetIterator().

◆ get_next_arr()

ErrorCode moab::RangeSetIterator::get_next_arr ( std::vector< EntityHandle > &  arr,
bool &  atend 
)
virtual

get the next chunkSize entities Return the next chunkSize entities.

Parameters
arrArray of entities returned.
atendReturns true if iterator is at the end of iterable values, otherwise false

Implements moab::SetIterator.

Definition at line 69 of file SetIterator.cpp.

70 {
71  atend = false;
72 
73  int count;
74  const EntityHandle* ptr;
75  WriteUtilIface* iface;
76  std::vector< EntityHandle > tmp_arr;
77  std::vector< EntityHandle >* tmp_ptr = &arr;
78  if( checkValid ) tmp_ptr = &tmp_arr;
79  ErrorCode rval;
80  if( !pairPtr )
81  {
82  Interface* mbImpl = dynamic_cast< Interface* >( myCore );
83  rval = mbImpl->query_interface( iface );
84  if( MB_SUCCESS != rval ) return rval;
85 
86  rval = iface->get_entity_list_pointers( &entSet, 1, &ptr, WriteUtilIface::CONTENTS, &count );
87  if( MB_SUCCESS != rval ) return rval;
88  mbImpl->release_interface( iface );
89  }
90  else
91  {
92  if( checkValid )
93  {
94  rval = build_pair_vec();
95  if( MB_SUCCESS != rval ) return rval;
96  }
97  ptr = pairPtr;
98  count = 2 * numPairs;
99  }
100  assert( !( count % 2 ) );
101  if( !count )
102  {
103  atend = true;
104  return MB_SUCCESS;
105  }
106 
107  if( -1 == entDimension )
108  rval = get_next_by_type( ptr, count, *tmp_ptr, atend );
109  else
110  rval = get_next_by_dimension( ptr, count, *tmp_ptr, atend );
111  if( MB_SUCCESS != rval ) return rval;
112 
113  if( checkValid )
114  {
115  for( std::vector< EntityHandle >::iterator vit = tmp_ptr->begin(); vit != tmp_ptr->end(); ++vit )
116  {
117  if( myCore->is_valid( *vit ) ) arr.push_back( *vit );
118  }
119  }
120 
121  return MB_SUCCESS;
122 }

References build_pair_vec(), moab::SetIterator::checkValid, moab::WriteUtilIface::CONTENTS, moab::SetIterator::entDimension, moab::SetIterator::entSet, ErrorCode, get_next_by_dimension(), get_next_by_type(), iface, moab::Core::is_valid(), MB_SUCCESS, moab::SetIterator::myCore, numPairs, pairPtr, moab::Interface::query_interface(), and moab::Interface::release_interface().

◆ get_next_by_dimension()

ErrorCode moab::RangeSetIterator::get_next_by_dimension ( const EntityHandle *&  ptr,
int  count,
std::vector< EntityHandle > &  arr,
bool &  atend 
)
private

Definition at line 175 of file SetIterator.cpp.

179 {
180  // iterating by dimension - type should be maxtype
181  if( entType != MBMAXTYPE )
182  {
183  MB_SET_ERR( MB_FAILURE, "Both dimension and type should not be set on an iterator" );
184  }
185 
186  unsigned int num_ret = 0;
187  size_t idx = 0;
188  // initialize to first relevant handle
189  while( (int)idx < count && ( iterPos > ptr[idx + 1] ||
190  ( !iterPos && entDimension > CN::Dimension( TYPE_FROM_HANDLE( ptr[idx + 1] ) ) ) ) )
191  idx += 2;
192  if( (int)idx == count || CN::Dimension( TYPE_FROM_HANDLE( ptr[idx] ) ) > entDimension )
193  {
194  atend = true;
195  return MB_SUCCESS;
196  }
197  if( !iterPos )
198  iterPos = ptr[idx];
199  else if( CN::Dimension( TYPE_FROM_HANDLE( ptr[idx] ) ) < entDimension )
201 
202  // idx points to start of subrange, iterPos in that subrange
203  do
204  {
205  EntityHandle next = ptr[idx + 1];
206  if( CN::Dimension( TYPE_FROM_HANDLE( next ) ) != entDimension )
208  unsigned int this_ret = chunkSize - num_ret;
209  unsigned int to_end = next - iterPos + 1;
210  if( to_end < this_ret ) this_ret = to_end;
211  std::copy( MeshSet::hdl_iter( iterPos ), MeshSet::hdl_iter( iterPos + this_ret ), std::back_inserter( arr ) );
212  if( this_ret == to_end )
213  {
214  idx += 2;
215  iterPos = ( (int)idx < count ? ptr[idx] : 0 );
216  }
217  else
218  iterPos += this_ret;
219 
220  num_ret += this_ret;
221  } while( (int)idx < count && num_ret < chunkSize && iterPos &&
223 
224  if( !iterPos || CN::Dimension( TYPE_FROM_HANDLE( iterPos ) ) != entDimension ) atend = true;
225 
226  return MB_SUCCESS;
227 }

References moab::SetIterator::chunkSize, moab::CREATE_HANDLE(), moab::CN::Dimension(), moab::SetIterator::entDimension, moab::SetIterator::entType, moab::GeomUtil::first(), iterPos, moab::LAST_HANDLE(), MB_SET_ERR, MB_SUCCESS, MBMAXTYPE, moab::TYPE_FROM_HANDLE(), and moab::CN::TypeDimensionMap.

Referenced by get_next_arr().

◆ get_next_by_type()

ErrorCode moab::RangeSetIterator::get_next_by_type ( const EntityHandle *&  ptr,
int  count,
std::vector< EntityHandle > &  arr,
bool &  atend 
)
private

Definition at line 124 of file SetIterator.cpp.

128 {
129  unsigned int num_ret = 0;
130  bool max_type = ( entType == MBMAXTYPE );
131  size_t idx = 0;
132  // initialize to first relevant handle
133  while( (int)idx < count &&
134  ( iterPos > ptr[idx + 1] ||
135  ( !max_type && !iterPos && CREATE_HANDLE( entType, ID_FROM_HANDLE( iterPos ) ) > ptr[idx + 1] ) ) )
136  idx += 2;
137  if( (int)idx == count || TYPE_FROM_HANDLE( ptr[idx] ) > entType )
138  {
139  atend = true;
140  return MB_SUCCESS;
141  }
142  if( !iterPos && max_type )
143  iterPos = ptr[idx];
144  else if( !iterPos && TYPE_FROM_HANDLE( ptr[idx] ) <= entType && TYPE_FROM_HANDLE( ptr[idx + 1] ) >= entType )
145  {
146  iterPos = std::max( CREATE_HANDLE( entType, 1 ), ptr[idx] );
147  }
148 
149  // idx points to start of subrange, iterPos in that subrange
150  do
151  {
152  EntityHandle next = ptr[idx + 1];
153  if( TYPE_FROM_HANDLE( next ) != entType && !max_type ) next = LAST_HANDLE( entType );
154  unsigned int this_ret = chunkSize - num_ret;
155  unsigned int to_end = next - iterPos + 1;
156  if( to_end < this_ret ) this_ret = to_end;
157  std::copy( MeshSet::hdl_iter( iterPos ), MeshSet::hdl_iter( iterPos + this_ret ), std::back_inserter( arr ) );
158  if( this_ret == to_end )
159  {
160  idx += 2;
161  iterPos = ( (int)idx < count ? ptr[idx] : 0 );
162  }
163  else
164  iterPos += this_ret;
165 
166  num_ret += this_ret;
167  } while( (int)idx < count && num_ret < chunkSize && iterPos &&
168  ( max_type || TYPE_FROM_HANDLE( iterPos ) == entType ) );
169 
170  if( !iterPos || ( !max_type && TYPE_FROM_HANDLE( iterPos ) != entType ) ) atend = true;
171 
172  return MB_SUCCESS;
173 }

References moab::SetIterator::chunkSize, moab::CREATE_HANDLE(), moab::SetIterator::entType, moab::ID_FROM_HANDLE(), iterPos, moab::LAST_HANDLE(), MB_SUCCESS, MBMAXTYPE, and moab::TYPE_FROM_HANDLE().

Referenced by get_next_arr().

◆ reset()

ErrorCode moab::RangeSetIterator::reset ( )
virtual

reset the iterator to the beginning of the set

Implements moab::SetIterator.

Definition at line 229 of file SetIterator.cpp.

230 {
231  iterPos = 0;
232  return MB_SUCCESS;
233 }

References iterPos, and MB_SUCCESS.

Friends And Related Function Documentation

◆ Core

friend class Core
friend

Definition at line 98 of file SetIterator.hpp.

Member Data Documentation

◆ iterPos

EntityHandle moab::RangeSetIterator::iterPos
private

Current iterator position, 0 if at beginning.

Definition at line 141 of file SetIterator.hpp.

Referenced by get_next_by_dimension(), get_next_by_type(), and reset().

◆ numPairs

int moab::RangeSetIterator::numPairs
private

Number of range pairs.

Definition at line 147 of file SetIterator.hpp.

Referenced by build_pair_vec(), get_next_arr(), and ~RangeSetIterator().

◆ pairPtr

EntityHandle* moab::RangeSetIterator::pairPtr
private

Special range pair ptr for root set.

Definition at line 144 of file SetIterator.hpp.

Referenced by build_pair_vec(), get_next_arr(), and ~RangeSetIterator().


The documentation for this class was generated from the following files: