moab
|
Iterate over the blocks of EntityHandles in an Range that are in the same EntitySequence. More...
#include <RangeSeqIntersectIter.hpp>
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. | |
EntitySequence * | get_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 | |
SequenceManager * | mSequenceManager |
THE EntitySequenceManager. | |
EntitySequence * | mSequence |
EntitySequence corresponding to current location. | |
Range::const_pair_iterator | rangeIter |
Current position in Range. | |
EntityHandle | mStartHandle |
EntityHandle | mEndHandle |
Subset of current EntitySequence. | |
EntityHandle | mLastHandle |
The last of the list of all handles in the Range. |
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:
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 54 of file RangeSeqIntersectIter.hpp.
moab::RangeSeqIntersectIter::RangeSeqIntersectIter | ( | SequenceManager * | sequences | ) | [inline] |
Definition at line 57 of file RangeSeqIntersectIter.hpp.
: mSequenceManager( sequences ), mSequence( 0 ), mStartHandle( 0 ), mEndHandle( 0 ), mLastHandle( 0 ) { }
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.
Definition at line 115 of file RangeSeqIntersectIter.cpp.
{ assert(!mSequence); // no more entities in current range if (mStartHandle == mEndHandle) return MB_ENTITY_NOT_FOUND; // Find the next EntitySequence EntityType type = TYPE_FROM_HANDLE(mStartHandle); const TypeSequenceManager& map = mSequenceManager->entity_map( type ); TypeSequenceManager::const_iterator iter = map.upper_bound( mStartHandle ); // If no next sequence of the same type if (iter == map.end()) { // If end type not the same as start type, split on type if (type != TYPE_FROM_HANDLE( mEndHandle )) { int junk; mEndHandle = CREATE_HANDLE( type, MB_END_ID, junk ); } } // otherwise invalid range ends at min(mEndHandle, sequence start handle - 1) else if ((*iter)->start_handle() <= mEndHandle) { mEndHandle = (*iter)->start_handle()-1; } return MB_ENTITY_NOT_FOUND; }
EntityHandle moab::RangeSeqIntersectIter::get_end_handle | ( | ) | const [inline] |
Get last handle in block
Definition at line 99 of file RangeSeqIntersectIter.hpp.
{ return mEndHandle; }
EntitySequence* moab::RangeSeqIntersectIter::get_sequence | ( | ) | const [inline] |
Get the EntitySequence for the current block. May be NULL for invaild handles.
Definition at line 91 of file RangeSeqIntersectIter.hpp.
{ return mSequence; }
EntityHandle moab::RangeSeqIntersectIter::get_start_handle | ( | ) | const [inline] |
Get first handle in block
Definition at line 95 of file RangeSeqIntersectIter.hpp.
{ return mStartHandle; }
ErrorCode moab::RangeSeqIntersectIter::init | ( | Range::const_iterator | start, |
Range::const_iterator | end | ||
) |
Initialize iterator to first valid subset
Definition at line 28 of file RangeSeqIntersectIter.cpp.
{ mSequence = 0; rangeIter = start; // special case : nothing to iterate over if (start == end) { mStartHandle = mEndHandle = mLastHandle = 0; return MB_FAILURE; } // normal case mStartHandle = *start; --end; mLastHandle = *end; mEndHandle = (*rangeIter).second; if (mEndHandle > mLastHandle) mEndHandle = mLastHandle; #if MB_RANGE_SEQ_INTERSECT_ITER_STATS ErrorCode result = update_entity_sequence(); update_stats(mEndHandle - mStartHandle + 1); return result; #else return update_entity_sequence(); #endif }
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.
{ return mEndHandle == mLastHandle; }
Step iterator to next range.
Definition at line 58 of file RangeSeqIntersectIter.cpp.
{ // If at end, return MB_FAILURE if (is_at_end()) return MB_FAILURE; // If the last block was at the end of the rangeIter pair, // then advance the iterator and set the next block else if (mEndHandle == (*rangeIter).second) { ++rangeIter; mStartHandle = (*rangeIter).first; } // Otherwise start with next entity in the pair else { mStartHandle = mEndHandle + 1; } // Always take the remaining entities in the rangeIter pair. // will trim up the end of the range in update_entity_sequence(). mEndHandle = (*rangeIter).second; if (mEndHandle > mLastHandle) mEndHandle = mLastHandle; // Now trim up the range (decrease mEndHandle) as necessary // for the corresponding EntitySquence #if MB_RANGE_SEQ_INTERSECT_ITER_STATS ErrorCode result = update_entity_sequence(); update_stats(mEndHandle - mStartHandle + 1); return result; #else return update_entity_sequence(); #endif }
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 90 of file RangeSeqIntersectIter.cpp.
{ // mStartHandle to mEndHandle is a subset of the Range. // Update sequence data as necessary and trim that subset // (reduce mEndHandle) for the current EntitySequence. // Need to update the sequence pointer? if (!mSequence || mStartHandle > mSequence->end_handle()) { // Check that the mStartHandle is valid if (TYPE_FROM_HANDLE(mStartHandle) >= MBMAXTYPE) return MB_TYPE_OUT_OF_RANGE; if (MB_SUCCESS != mSequenceManager->find( mStartHandle, mSequence )) return find_invalid_range(); } // if mEndHandle is past end of sequence or block of used // handles within sequence, shorten it. if(mEndHandle > mSequence->end_handle()) mEndHandle = mSequence->end_handle(); return MB_SUCCESS; }
Subset of current EntitySequence.
Definition at line 127 of file RangeSeqIntersectIter.hpp.
The last of the list of all handles in the Range.
Definition at line 128 of file RangeSeqIntersectIter.hpp.
EntitySequence corresponding to current location.
Definition at line 125 of file RangeSeqIntersectIter.hpp.
THE EntitySequenceManager.
Definition at line 124 of file RangeSeqIntersectIter.hpp.
Definition at line 127 of file RangeSeqIntersectIter.hpp.
Current position in Range.
Definition at line 126 of file RangeSeqIntersectIter.hpp.