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

Iterate over the blocks of EntityHandles in an Range that are in the same EntitySequence. More...

#include <RangeSeqIntersectIter.hpp>

+ Collaboration diagram for moab::RangeSeqIntersectIter:

Public Member Functions

 RangeSeqIntersectIter (SequenceManager *sequences)
 
ErrorCode init (Range::const_iterator start, Range::const_iterator end)
 
ErrorCode step ()
 
bool is_at_end () const
 Check if next call to step() will return MB_FAILURE. More...
 
EntitySequenceget_sequence () const
 
EntityHandle get_start_handle () const
 
EntityHandle get_end_handle () const
 

Private Member Functions

ErrorCode update_entity_sequence ()
 
ErrorCode find_invalid_range ()
 

Private Attributes

SequenceManagermSequenceManager
 THE EntitySequenceManager. More...
 
EntitySequencemSequence
 EntitySequence corresponding to current location. More...
 
Range::const_pair_iterator rangeIter
 Current position in Range. More...
 
EntityHandle mStartHandle
 
EntityHandle mEndHandle
 Subset of current EntitySequence. More...
 
EntityHandle mLastHandle
 The last of the list of all handles in the Range. More...
 

Detailed Description

Iterate over the blocks of EntityHandles in an Range that are in the same EntitySequence.

Iterate over an Range, returning blocks of entities that are the largest ranges of contiguous handles that meet one of the following conditions:

  • All are valid handles belonging to the same EntitySequence
  • All are invalid handles of the same EntityType

The return type from init() or step() indicates whether or not the current range contains valid entities. If the handles are either all valid or all holes in an EntitySequence, that sequence can be obtained with get_sequence(). get_sequence() will return NULL if there is no corresponding EntitySequence for the block of handles.

This class keeps a data related to the 'current' EntitySequence and references to the Range pasesd to init(). Changing either of these while an instance of this class is in use would be bad.

Definition at line 55 of file RangeSeqIntersectIter.hpp.

Constructor & Destructor Documentation

◆ RangeSeqIntersectIter()

moab::RangeSeqIntersectIter::RangeSeqIntersectIter ( SequenceManager sequences)
inline

Definition at line 58 of file RangeSeqIntersectIter.hpp.

59  : mSequenceManager( sequences ), mSequence( 0 ), mStartHandle( 0 ), mEndHandle( 0 ), mLastHandle( 0 )
60  {
61  }

Member Function Documentation

◆ find_invalid_range()

ErrorCode moab::RangeSeqIntersectIter::find_invalid_range ( )
private

Handle error case where we encountered an EntityHandle w/out a corresponding EntitySequence. Trim mEndHandle such that it is before the next valid EntityHandle of the same type.

Returns
Always returns MB_ENTITY_NOT_FOUND

Definition at line 112 of file RangeSeqIntersectIter.cpp.

113 {
114  assert( !mSequence );
115 
116  // no more entities in current range
118 
119  // Find the next EntitySequence
120  EntityType type = TYPE_FROM_HANDLE( mStartHandle );
121  const TypeSequenceManager& map = mSequenceManager->entity_map( type );
122  TypeSequenceManager::const_iterator iter = map.upper_bound( mStartHandle );
123  // If no next sequence of the same type
124  if( iter == map.end() )
125  {
126  // If end type not the same as start type, split on type
127  if( type != TYPE_FROM_HANDLE( mEndHandle ) )
128  {
129  int junk;
130  mEndHandle = CREATE_HANDLE( type, MB_END_ID, junk );
131  }
132  }
133  // otherwise invalid range ends at min(mEndHandle, sequence start handle - 1)
134  else if( ( *iter )->start_handle() <= mEndHandle )
135  {
136  mEndHandle = ( *iter )->start_handle() - 1;
137  }
138 
139  return MB_ENTITY_NOT_FOUND;
140 }

References moab::CREATE_HANDLE(), moab::TypeSequenceManager::end(), moab::SequenceManager::entity_map(), MB_END_ID, MB_ENTITY_NOT_FOUND, mEndHandle, mSequence, mSequenceManager, mStartHandle, moab::TYPE_FROM_HANDLE(), and moab::TypeSequenceManager::upper_bound().

Referenced by update_entity_sequence().

◆ get_end_handle()

◆ get_sequence()

EntitySequence* moab::RangeSeqIntersectIter::get_sequence ( ) const
inline

◆ get_start_handle()

◆ init()

ErrorCode moab::RangeSeqIntersectIter::init ( Range::const_iterator  start,
Range::const_iterator  end 
)

Initialize iterator to first valid subset

Returns
- MB_SUCCESS : initial position of iterator is valid
  • MB_ENITITY_NOT_FOUND : range contains invalid handle – can step past by calling again
  • MB_FAILURE : No entities (start == end)

Definition at line 29 of file RangeSeqIntersectIter.cpp.

30 {
31  mSequence = 0;
32  rangeIter = start;
33 
34  // special case : nothing to iterate over
35  if( start == end )
36  {
38  return MB_FAILURE;
39  }
40 
41  // normal case
42  mStartHandle = *start;
43  --end;
44  mLastHandle = *end;
45  mEndHandle = ( *rangeIter ).second;
47 
48 #if MB_RANGE_SEQ_INTERSECT_ITER_STATS
50  update_stats( mEndHandle - mStartHandle + 1 );
51  return result;
52 #else
53  return update_entity_sequence();
54 #endif
55 }

References ErrorCode, mEndHandle, mLastHandle, mSequence, mStartHandle, rangeIter, and update_entity_sequence().

Referenced by moab::WriteUtil::gather_nodes_from_elements(), moab::WriteUtil::get_entity_list_pointers(), moab::AEntityFactory::get_memory_use(), moab::get_tagged(), and moab::WriteDamsel::write_file().

◆ is_at_end()

bool moab::RangeSeqIntersectIter::is_at_end ( ) const
inline

Check if next call to step() will return MB_FAILURE.

Check if the iterator cannot be advanced any further. If this method returns true, then the next call to step() will return MB_FAILURE.

Definition at line 85 of file RangeSeqIntersectIter.hpp.

86  {
87  return mEndHandle == mLastHandle;
88  }

References mEndHandle, and mLastHandle.

Referenced by step().

◆ step()

ErrorCode moab::RangeSeqIntersectIter::step ( )

Step iterator to next range.

Returns
- MB_SUCCESS : there is another range, and iter has been changed to it
  • MB_ENITITY_NOT_FOUND : range contains invalid handle – can step past by calling again
  • MB_FAILURE : at end.

Definition at line 57 of file RangeSeqIntersectIter.cpp.

58 {
59  // If at end, return MB_FAILURE
60  if( is_at_end() ) return MB_FAILURE;
61  // If the last block was at the end of the rangeIter pair,
62  // then advance the iterator and set the next block
63  else if( mEndHandle == ( *rangeIter ).second )
64  {
65  ++rangeIter;
66  mStartHandle = ( *rangeIter ).first;
67  }
68  // Otherwise start with next entity in the pair
69  else
70  {
72  }
73  // Always take the remaining entities in the rangeIter pair.
74  // will trim up the end of the range in update_entity_sequence().
75  mEndHandle = ( *rangeIter ).second;
77 
78  // Now trim up the range (decrease mEndHandle) as necessary
79  // for the corresponding EntitySquence
80 #if MB_RANGE_SEQ_INTERSECT_ITER_STATS
82  update_stats( mEndHandle - mStartHandle + 1 );
83  return result;
84 #else
85  return update_entity_sequence();
86 #endif
87 }

References ErrorCode, is_at_end(), mEndHandle, mLastHandle, mStartHandle, rangeIter, and update_entity_sequence().

Referenced by moab::WriteUtil::gather_nodes_from_elements(), moab::WriteUtil::get_entity_list_pointers(), moab::AEntityFactory::get_memory_use(), moab::get_tagged(), and moab::WriteDamsel::write_file().

◆ update_entity_sequence()

ErrorCode moab::RangeSeqIntersectIter::update_entity_sequence ( )
private

Update entity sequence data (mSequence and freeIndex) for current mStartHandle. If mEndHandle is past end of sequence, trim it. Called by step() and init(). step() handles iterating over the pairs in the Range. This method handles iterating over the set of EntitySequences that intersect the pair.

Definition at line 89 of file RangeSeqIntersectIter.cpp.

90 {
91  // mStartHandle to mEndHandle is a subset of the Range.
92  // Update sequence data as necessary and trim that subset
93  // (reduce mEndHandle) for the current EntitySequence.
94 
95  // Need to update the sequence pointer?
97  {
98 
99  // Check that the mStartHandle is valid
101 
103  }
104 
105  // if mEndHandle is past end of sequence or block of used
106  // handles within sequence, shorten it.
108 
109  return MB_SUCCESS;
110 }

References moab::EntitySequence::end_handle(), moab::SequenceManager::find(), find_invalid_range(), MB_SUCCESS, MB_TYPE_OUT_OF_RANGE, MBMAXTYPE, mEndHandle, mSequence, mSequenceManager, mStartHandle, and moab::TYPE_FROM_HANDLE().

Referenced by init(), and step().

Member Data Documentation

◆ mEndHandle

EntityHandle moab::RangeSeqIntersectIter::mEndHandle
private

◆ mLastHandle

EntityHandle moab::RangeSeqIntersectIter::mLastHandle
private

The last of the list of all handles in the Range.

Definition at line 137 of file RangeSeqIntersectIter.hpp.

Referenced by init(), is_at_end(), and step().

◆ mSequence

EntitySequence* moab::RangeSeqIntersectIter::mSequence
private

EntitySequence corresponding to current location.

Definition at line 134 of file RangeSeqIntersectIter.hpp.

Referenced by find_invalid_range(), get_sequence(), init(), and update_entity_sequence().

◆ mSequenceManager

SequenceManager* moab::RangeSeqIntersectIter::mSequenceManager
private

THE EntitySequenceManager.

Definition at line 133 of file RangeSeqIntersectIter.hpp.

Referenced by find_invalid_range(), and update_entity_sequence().

◆ mStartHandle

EntityHandle moab::RangeSeqIntersectIter::mStartHandle
private

◆ rangeIter

Range::const_pair_iterator moab::RangeSeqIntersectIter::rangeIter
private

Current position in Range.

Definition at line 135 of file RangeSeqIntersectIter.hpp.

Referenced by init(), and step().


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