MOAB: Mesh Oriented datABase  (version 5.2.1)
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.
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.
EntitySequencemSequence
 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.

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

Definition at line 58 of file RangeSeqIntersectIter.hpp.

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

Member Function Documentation

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.

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().

{
    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;
}

Get the EntitySequence for the current block. May be NULL for invaild handles.

Definition at line 93 of file RangeSeqIntersectIter.hpp.

References mSequence.

Referenced by moab::get_tagged(), moab::WriteDamsel::map_dense_tags(), mb_range_seq_intersect_test(), and moab::WriteDamsel::write_entities().

    {
        return mSequence;
    }

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.

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

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

{
    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.

References mEndHandle, and mLastHandle.

Referenced by mb_range_seq_intersect_test(), and step().

    {
        return mEndHandle == mLastHandle;
    }

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.

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

Referenced by moab::get_tagged(), mb_range_seq_intersect_test(), and moab::WriteDamsel::write_file().

{
    // 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
}

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.

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().

{
    // 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;
}

Member Data Documentation

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().

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().

THE EntitySequenceManager.

Definition at line 133 of file RangeSeqIntersectIter.hpp.

Referenced by find_invalid_range(), and update_entity_sequence().

Current position in Range.

Definition at line 135 of file RangeSeqIntersectIter.hpp.

Referenced by init(), and step().

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines