MOAB: Mesh Oriented datABase  (version 5.4.1)
moab::RangeSetIterator Class Reference

#include <SetIterator.hpp>

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

Public Member Functions

virtual ~RangeSetIterator ()
 Destructor.
virtual ErrorCode get_next_arr (std::vector< EntityHandle > &arr, bool &atend)
 get the next chunkSize entities Return the next chunkSize entities.
virtual ErrorCode reset ()
 reset the iterator to the beginning of the set

Protected Member Functions

 RangeSetIterator (Core *core, EntityHandle ent_set, int chunk_size, EntityType ent_type, int ent_dimension, bool check_valid=false)
 Constructor.

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.

Private Attributes

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

Friends

class Core

Detailed Description

Definition at line 95 of file SetIterator.hpp.


Constructor & Destructor Documentation

Destructor.

Definition at line 40 of file SetIterator.cpp.

References numPairs, and pairPtr.

{
    if( pairPtr ) delete[] pairPtr;
    numPairs = 0;
}
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.

References build_pair_vec(), ErrorCode, and MB_SUCCESS.

    : SetIterator( core, eset, chunk_sz, ent_tp, ent_dim, check_valid ), iterPos( 0 ), pairPtr( NULL ), numPairs( 0 )
{
    if( !eset )
    {
        // special case for the root set, have to keep a local array
        ErrorCode rval = build_pair_vec();
        assert( MB_SUCCESS == rval );

        // empty statement to avoid warning
        (void)( rval );
    }
}

Member Function Documentation

Build the special pair vector for the root set.

Definition at line 46 of file SetIterator.cpp.

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

{
    // shouldn't be here unless we're iterating the root set
    assert( !entSet );

    Range all_ents;
    ErrorCode rval = myCore->get_entities_by_handle( 0, all_ents );
    if( MB_SUCCESS != rval ) return rval;

    if( pairPtr ) delete[] pairPtr;
    pairPtr = new EntityHandle[2 * all_ents.psize()];
    Range::const_pair_iterator pi;
    int i;
    for( pi = all_ents.const_pair_begin(), i = 0; pi != all_ents.const_pair_end(); ++pi, i += 2 )
    {
        pairPtr[i]     = ( *pi ).first;
        pairPtr[i + 1] = ( *pi ).second;
    }
    numPairs = all_ents.psize();

    return MB_SUCCESS;
}
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.

References build_pair_vec(), moab::SetIterator::checkValid, moab::WriteUtilIface::CONTENTS, moab::SetIterator::entDimension, moab::SetIterator::entSet, ErrorCode, moab::WriteUtilIface::get_entity_list_pointers(), 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().

{
    atend = false;

    int count;
    const EntityHandle* ptr;
    WriteUtilIface* iface;
    std::vector< EntityHandle > tmp_arr;
    std::vector< EntityHandle >* tmp_ptr = &arr;
    if( checkValid ) tmp_ptr = &tmp_arr;
    ErrorCode rval;
    if( !pairPtr )
    {
        Interface* mbImpl = dynamic_cast< Interface* >( myCore );
        rval              = mbImpl->query_interface( iface );
        if( MB_SUCCESS != rval ) return rval;

        rval = iface->get_entity_list_pointers( &entSet, 1, &ptr, WriteUtilIface::CONTENTS, &count );
        if( MB_SUCCESS != rval ) return rval;
        mbImpl->release_interface( iface );
    }
    else
    {
        if( checkValid )
        {
            rval = build_pair_vec();
            if( MB_SUCCESS != rval ) return rval;
        }
        ptr   = pairPtr;
        count = 2 * numPairs;
    }
    assert( !( count % 2 ) );
    if( !count )
    {
        atend = true;
        return MB_SUCCESS;
    }

    if( -1 == entDimension )
        rval = get_next_by_type( ptr, count, *tmp_ptr, atend );
    else
        rval = get_next_by_dimension( ptr, count, *tmp_ptr, atend );
    if( MB_SUCCESS != rval ) return rval;

    if( checkValid )
    {
        for( std::vector< EntityHandle >::iterator vit = tmp_ptr->begin(); vit != tmp_ptr->end(); ++vit )
        {
            if( myCore->is_valid( *vit ) ) arr.push_back( *vit );
        }
    }

    return MB_SUCCESS;
}
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.

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

{
    // iterating by dimension - type should be maxtype
    if( entType != MBMAXTYPE )
    {
        MB_SET_ERR( MB_FAILURE, "Both dimension and type should not be set on an iterator" );
    }

    unsigned int num_ret = 0;
    size_t idx           = 0;
    // initialize to first relevant handle
    while( (int)idx < count && ( iterPos > ptr[idx + 1] ||
                                 ( !iterPos && entDimension > CN::Dimension( TYPE_FROM_HANDLE( ptr[idx + 1] ) ) ) ) )
        idx += 2;
    if( (int)idx == count || CN::Dimension( TYPE_FROM_HANDLE( ptr[idx] ) ) > entDimension )
    {
        atend = true;
        return MB_SUCCESS;
    }
    if( !iterPos )
        iterPos = ptr[idx];
    else if( CN::Dimension( TYPE_FROM_HANDLE( ptr[idx] ) ) < entDimension )
        iterPos = CREATE_HANDLE( CN::TypeDimensionMap[entDimension].first, 1 );

    // idx points to start of subrange, iterPos in that subrange
    do
    {
        EntityHandle next = ptr[idx + 1];
        if( CN::Dimension( TYPE_FROM_HANDLE( next ) ) != entDimension )
            next = LAST_HANDLE( CN::TypeDimensionMap[entDimension].second );
        unsigned int this_ret = chunkSize - num_ret;
        unsigned int to_end   = next - iterPos + 1;
        if( to_end < this_ret ) this_ret = to_end;
        std::copy( MeshSet::hdl_iter( iterPos ), MeshSet::hdl_iter( iterPos + this_ret ), std::back_inserter( arr ) );
        if( this_ret == to_end )
        {
            idx += 2;
            iterPos = ( (int)idx < count ? ptr[idx] : 0 );
        }
        else
            iterPos += this_ret;

        num_ret += this_ret;
    } while( (int)idx < count && num_ret < chunkSize && iterPos &&
             CN::Dimension( TYPE_FROM_HANDLE( iterPos ) ) == entDimension );

    if( !iterPos || CN::Dimension( TYPE_FROM_HANDLE( iterPos ) ) != entDimension ) atend = true;

    return MB_SUCCESS;
}
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.

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

{
    unsigned int num_ret = 0;
    bool max_type        = ( entType == MBMAXTYPE );
    size_t idx           = 0;
    // initialize to first relevant handle
    while( (int)idx < count &&
           ( iterPos > ptr[idx + 1] ||
             ( !max_type && !iterPos && CREATE_HANDLE( entType, ID_FROM_HANDLE( iterPos ) ) > ptr[idx + 1] ) ) )
        idx += 2;
    if( (int)idx == count || TYPE_FROM_HANDLE( ptr[idx] ) > entType )
    {
        atend = true;
        return MB_SUCCESS;
    }
    if( !iterPos && max_type )
        iterPos = ptr[idx];
    else if( !iterPos && TYPE_FROM_HANDLE( ptr[idx] ) <= entType && TYPE_FROM_HANDLE( ptr[idx + 1] ) >= entType )
    {
        iterPos = std::max( CREATE_HANDLE( entType, 1 ), ptr[idx] );
    }

    // idx points to start of subrange, iterPos in that subrange
    do
    {
        EntityHandle next = ptr[idx + 1];
        if( TYPE_FROM_HANDLE( next ) != entType && !max_type ) next = LAST_HANDLE( entType );
        unsigned int this_ret = chunkSize - num_ret;
        unsigned int to_end   = next - iterPos + 1;
        if( to_end < this_ret ) this_ret = to_end;
        std::copy( MeshSet::hdl_iter( iterPos ), MeshSet::hdl_iter( iterPos + this_ret ), std::back_inserter( arr ) );
        if( this_ret == to_end )
        {
            idx += 2;
            iterPos = ( (int)idx < count ? ptr[idx] : 0 );
        }
        else
            iterPos += this_ret;

        num_ret += this_ret;
    } while( (int)idx < count && num_ret < chunkSize && iterPos &&
             ( max_type || TYPE_FROM_HANDLE( iterPos ) == entType ) );

    if( !iterPos || ( !max_type && TYPE_FROM_HANDLE( iterPos ) != entType ) ) atend = true;

    return MB_SUCCESS;
}

reset the iterator to the beginning of the set

Implements moab::SetIterator.

Definition at line 229 of file SetIterator.cpp.

References iterPos, and MB_SUCCESS.

{
    iterPos = 0;
    return MB_SUCCESS;
}

Friends And Related Function Documentation

friend class Core [friend]

Reimplemented from moab::SetIterator.

Definition at line 98 of file SetIterator.hpp.


Member Data Documentation

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

Number of range pairs.

Definition at line 147 of file SetIterator.hpp.

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

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

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