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

data for a single bit tag More...

#include <BitTag.hpp>

+ Inheritance diagram for moab::BitTag:
+ Collaboration diagram for moab::BitTag:

Public Types

enum  { Ln2PageSize = 12, PageSize = ( 1u << Ln2PageSize ) }

Public Member Functions

virtual ~BitTag ()
virtual TagType get_storage_type () const
virtual ErrorCode release_all_data (SequenceManager *seqman, Error *error_handler, bool delete_pending)
 Remove/clear tag data for all entities.
virtual ErrorCode get_data (const SequenceManager *seqman, Error *error_handler, const EntityHandle *entities, size_t num_entities, void *data) const
 Get tag value for passed entities.
virtual ErrorCode get_data (const SequenceManager *seqman, Error *error_handler, const Range &entities, void *data) const
 Get tag value for passed entities.
virtual ErrorCode get_data (const SequenceManager *seqman, Error *error_handler, const EntityHandle *entities, size_t num_entities, const void **data_ptrs, int *data_lengths) const
 Get tag value for passed entities.
virtual ErrorCode get_data (const SequenceManager *seqman, Error *error_handler, const Range &entities, const void **data_ptrs, int *data_lengths) const
 Get tag value for passed entities.
virtual ErrorCode set_data (SequenceManager *seqman, Error *error_handler, const EntityHandle *entities, size_t num_entities, const void *data)
 Set tag value for passed entities.
virtual ErrorCode set_data (SequenceManager *seqman, Error *error_handler, const Range &entities, const void *data)
 Set tag value for passed entities.
virtual ErrorCode set_data (SequenceManager *seqman, Error *error_handler, const EntityHandle *entities, size_t num_entities, void const *const *data_ptrs, const int *data_lengths)
 Set tag value for passed entities.
virtual ErrorCode set_data (SequenceManager *seqman, Error *error_handler, const Range &entities, void const *const *data_ptrs, const int *data_lengths)
 Set tag value for passed entities.
virtual ErrorCode clear_data (SequenceManager *seqman, Error *error_handler, const EntityHandle *entities, size_t num_entities, const void *value_ptr, int value_len=0)
 Set tag value for passed entities.
virtual ErrorCode clear_data (SequenceManager *seqman, Error *error_handler, const Range &entities, const void *value_ptr, int value_len=0)
 Set tag value for passed entities.
virtual ErrorCode remove_data (SequenceManager *seqman, Error *error_handler, const EntityHandle *entities, size_t num_entities)
 Remove/clear tag data for entities.
virtual ErrorCode remove_data (SequenceManager *seqman, Error *error_handler, const Range &entities)
 Remove/clear tag data for entities.
virtual ErrorCode tag_iterate (SequenceManager *seqman, Error *error_handler, Range::iterator &iter, const Range::iterator &end, void *&data_ptr, bool allocate=true)
 Access tag data via direct pointer into contiguous blocks.
virtual ErrorCode get_tagged_entities (const SequenceManager *seqman, Range &output_entities, EntityType type=MBMAXTYPE, const Range *intersect=0) const
 Get all tagged entities.
virtual ErrorCode num_tagged_entities (const SequenceManager *seqman, size_t &output_count, EntityType type=MBMAXTYPE, const Range *intersect=0) const
 Count all tagged entities.
virtual ErrorCode find_entities_with_value (const SequenceManager *seqman, Error *error_handler, Range &output_entities, const void *value, int value_bytes=0, EntityType type=MBMAXTYPE, const Range *intersect_entities=0) const
 Get all tagged entities with tag value.
virtual bool is_tagged (const SequenceManager *, EntityHandle h) const
 Check if entity is tagged.
ErrorCode get_memory_use (const SequenceManager *seqman, unsigned long &total, unsigned long &per_entity) const
 Get memory use for tag data.
ErrorCode get_entities_with_bits (EntityType type, Range &entities, unsigned char bits) const
 Get entities for which an explicit tag of the specified value is stored.
ErrorCode get_entities_with_bits (const Range &range, EntityType type, Range &entities, unsigned char bits) const
 Get entities for which an explicit tag of the specified value is stored.

Static Public Member Functions

static BitTagcreate_tag (const char *name, int size, const void *default_value=0)

Private Member Functions

 BitTag (const char *name, int size, const void *default_value)
 BitTag (const BitTag &)
BitTagoperator= (const BitTag &)
ErrorCode reserve (unsigned bits)
unsigned char default_val () const
void unpack (EntityHandle h, EntityType &type, size_t &page, int &offset) const
 Get indices from handle.
int ents_per_page () const
 Get the number of tag values that are stored in each BitPage.
template<class Container >
void get_tagged (EntityType type, Container &entities) const
template<class Container >
void get_tagged (Range::const_iterator begin, Range::const_iterator end, Container &entities) const
template<class Container >
void get_tagged (Container &entities, EntityType type, const Range *intersect) const

Private Attributes

std::vector< BitPage * > pageList [MBMAXTYPE]
 Array of BitPage instances storing actual data.
unsigned int requestedBitsPerEntity
 user-requested bits per entity
unsigned int storedBitsPerEntity
 allocated bits per entity (power of 2)
unsigned int pageShift
 log2( ents_per_page() )

Detailed Description

data for a single bit tag

Definition at line 16 of file BitTag.hpp.


Member Enumeration Documentation

anonymous enum
Enumerator:
Ln2PageSize 

Constant: log2(PageSize)

PageSize 

Constant: Bytes per BitPage (power of 2)

Definition at line 347 of file BitTag.hpp.

    {
        Ln2PageSize = 12,                    //!< Constant: log2(PageSize)
        PageSize    = ( 1u << Ln2PageSize )  //!< Constant: Bytes per BitPage (power of 2)
    };

Constructor & Destructor Documentation

moab::BitTag::BitTag ( const char *  name,
int  size,
const void *  default_value 
) [inline, private]

Definition at line 19 of file BitTag.hpp.

Referenced by create_tag().

moab::BitTag::~BitTag ( ) [virtual]

Definition at line 14 of file BitTag.cpp.

References release_all_data().

{
    release_all_data( 0, 0, true );
}
moab::BitTag::BitTag ( const BitTag ) [private]

Member Function Documentation

ErrorCode moab::BitTag::clear_data ( SequenceManager seqman,
Error error_handler,
const EntityHandle entities,
size_t  num_entities,
const void *  value_ptr,
int  value_len = 0 
) [virtual]

Set tag value for passed entities.

Store tag data or update stored tag values.

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to store tag data
num_entitiesLength of entities array
value_ptrPointer to a single tag value which is to be stored for each of the passed entities.
value_lenLength of tag value in bytes. Ignored for fixed-length tags. Required for variable- length tags.

Implements moab::TagInfo.

Definition at line 118 of file BitTag.cpp.

References moab::SequenceManager::check_valid_entities(), default_val(), ErrorCode, MB_CHK_ERR, MB_INVALID_SIZE, MB_SUCCESS, pageList, size, storedBitsPerEntity, and unpack().

{
    if( value_len ) return MB_INVALID_SIZE;

    ErrorCode rval = seqman->check_valid_entities( NULL, handles, num_handles, true );MB_CHK_ERR( rval );

    EntityType type;
    size_t page;
    int offset;
    const unsigned char value = *reinterpret_cast< const unsigned char* >( value_ptr );
    for( size_t i = 0; i < num_handles; ++i )
    {
        unpack( handles[i], type, page, offset );
        if( pageList[type].size() <= page ) pageList[type].resize( page + 1, 0 );
        if( !pageList[type][page] ) pageList[type][page] = new BitPage( storedBitsPerEntity, default_val() );
        pageList[type][page]->set_bits( offset, storedBitsPerEntity, value );
    }

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::clear_data ( SequenceManager seqman,
Error error_handler,
const Range entities,
const void *  value_ptr,
int  value_len = 0 
) [virtual]

Set tag value for passed entities.

Store tag data or update stored tag values.

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to store tag data
value_ptrPointer to a single tag value which is to be stored for each of the passed entities.
value_lenLength of tag value in bytes. Ignored for fixed-length tags. Required for variable- length tags.

Implements moab::TagInfo.

Definition at line 232 of file BitTag.cpp.

References moab::SequenceManager::check_valid_entities(), moab::Range::const_pair_begin(), moab::Range::const_pair_end(), default_val(), ents_per_page(), ErrorCode, MB_CHK_ERR, MB_INVALID_SIZE, MB_SUCCESS, pageList, size, storedBitsPerEntity, moab::TYPE_FROM_HANDLE(), and unpack().

{
    if( value_len ) return MB_INVALID_SIZE;

    ErrorCode rval = seqman->check_valid_entities( NULL, handles );MB_CHK_ERR( rval );

    EntityType type;
    EntityID count;
    size_t page;
    int offset, per_page = ents_per_page();
    const unsigned char value = *reinterpret_cast< const unsigned char* >( value_ptr );
    Range::const_pair_iterator i;
    for( i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i )
    {
        unpack( i->first, type, page, offset );
        assert( TYPE_FROM_HANDLE( i->second ) == type );  // Should be true because id of zero is never used
        count = i->second - i->first + 1;

        while( count )
        {
            if( page >= pageList[type].size() ) pageList[type].resize( page + 1, 0 );
            if( !pageList[type][page] ) pageList[type][page] = new BitPage( storedBitsPerEntity, default_val() );

            size_t pcount = std::min( (EntityID)( per_page - offset ), count );
            pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, value );
            count -= pcount;
            offset = 0;
            ++page;
        }
    }

    return MB_SUCCESS;
}
BitTag * moab::BitTag::create_tag ( const char *  name,
int  size,
const void *  default_value = 0 
) [static]

Definition at line 24 of file BitTag.cpp.

References BitTag(), MB_SUCCESS, and reserve().

Referenced by moab::Core::tag_get_handle().

{
    BitTag* result = new BitTag( name, size, default_value );
    if( MB_SUCCESS != result->reserve( size ) )
    {
        delete result;
        result = NULL;
    }

    return result;
}
unsigned char moab::BitTag::default_val ( ) const [inline, private]

Definition at line 358 of file BitTag.hpp.

References moab::TagInfo::get_default_value().

Referenced by clear_data(), get_data(), remove_data(), and set_data().

    {
        if( get_default_value() )
            return *reinterpret_cast< const unsigned char* >( get_default_value() );
        else
            return 0;
    }
int moab::BitTag::ents_per_page ( ) const [inline, private]

Get the number of tag values that are stored in each BitPage.

Definition at line 386 of file BitTag.hpp.

References PageSize, and storedBitsPerEntity.

Referenced by clear_data(), get_data(), get_entities_with_bits(), get_tagged(), remove_data(), and set_data().

    {
        return 8 * PageSize / storedBitsPerEntity;
    }
ErrorCode moab::BitTag::find_entities_with_value ( const SequenceManager seqman,
Error error_handler,
Range output_entities,
const void *  value,
int  value_bytes = 0,
EntityType  type = MBMAXTYPE,
const Range intersect_entities = 0 
) const [virtual]

Get all tagged entities with tag value.

Get the list of entities which have the specified tag value.

Parameters:
seqmanPointer to entity storage database
output_entitiesResults *appended* to this range
valuePointer to tag value
value_bytesSize of tag value in bytes.
typeOptional entity type. If specified, search is limited to entities of specified type.
intersect_entitiesOptional intersect list. If specified, search is restricted to entities in this list.

Implements moab::TagInfo.

Definition at line 429 of file BitTag.cpp.

References get_entities_with_bits(), MB_INVALID_SIZE, and MB_SET_ERR.

{
    if( value_bytes && value_bytes != 1 )
    {
        MB_SET_ERR( MB_INVALID_SIZE, "Invalid tag size for bit tag: " << value_bytes << " bytes" );
    }

    const signed char bits = *reinterpret_cast< const unsigned char* >( value );
    if( intersect_entities )
        return get_entities_with_bits( *intersect_entities, type, output_entities, bits );
    else
        return get_entities_with_bits( type, output_entities, bits );
}
ErrorCode moab::BitTag::get_data ( const SequenceManager seqman,
Error error_handler,
const EntityHandle entities,
size_t  num_entities,
void *  data 
) const [virtual]

Get tag value for passed entities.

Get tag values for specified entities.

Will fail for variable-length data.

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to retrieve tag data
num_entitiesLength of entities array
dataPointer to memory in which to store consecutive tag values, one for each passed entity.

Implements moab::TagInfo.

Definition at line 72 of file BitTag.cpp.

References default_val(), MB_SUCCESS, pageList, size, storedBitsPerEntity, and unpack().

{
    EntityType type;
    size_t page;
    int offset;
    unsigned char def   = default_val();
    unsigned char* data = reinterpret_cast< unsigned char* >( gen_data );
    for( size_t i = 0; i < num_handles; ++i )
    {
        unpack( handles[i], type, page, offset );
        if( pageList[type].size() <= page || !pageList[type][page] )
            data[i] = def;
        else
            data[i] = pageList[type][page]->get_bits( offset, storedBitsPerEntity );
    }

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::get_data ( const SequenceManager seqman,
Error error_handler,
const Range entities,
void *  data 
) const [virtual]

Get tag value for passed entities.

Get tag values for specified entities.

Will fail for variable-length data.

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to retrieve tag data
dataPointer to memory in which to store consecutive tag values, one for each passed entity.

Implements moab::TagInfo.

Definition at line 160 of file BitTag.cpp.

References moab::Range::const_pair_begin(), moab::Range::const_pair_end(), default_val(), ents_per_page(), MB_SUCCESS, pageList, size, storedBitsPerEntity, moab::TYPE_FROM_HANDLE(), and unpack().

{
    EntityType type;
    EntityID count;
    size_t page;
    int offset, per_page = ents_per_page();
    unsigned char def   = default_val();
    unsigned char* data = reinterpret_cast< unsigned char* >( gen_data );
    Range::const_pair_iterator i;
    for( i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i )
    {
        unpack( i->first, type, page, offset );
        assert( TYPE_FROM_HANDLE( i->second ) == type );  // Should be true because id of zero is never used
        count = i->second - i->first + 1;
        if( page >= pageList[type].size() )
        {
            memset( data, def, count );
            data += count;
            continue;
        }

        while( count )
        {
            size_t pcount = std::min( (EntityID)( per_page - offset ), count );
            if( pageList[type][page] )
                pageList[type][page]->get_bits( offset, pcount, storedBitsPerEntity, data );
            else
                memset( data, def, pcount );
            data += pcount;
            count -= pcount;
            offset = 0;
            ++page;
        }
    }

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::get_data ( const SequenceManager seqman,
Error error_handler,
const EntityHandle entities,
size_t  num_entities,
const void **  data_ptrs,
int *  data_lengths 
) const [virtual]

Get tag value for passed entities.

Get tag values for specified entities.

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to retrieve tag data
num_entitiesLength of entities array
data_ptrsArray of pointers to tag values, one pointer for each passed entity.
data_lengthsOne value for each entity specifying the length of the tag value for the corresponding entity.

Implements moab::TagInfo.

Definition at line 298 of file BitTag.cpp.

References MB_SET_ERR, and MB_TYPE_OUT_OF_RANGE.

{
    MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "Operation get_data not supported for bit tags" );
}
ErrorCode moab::BitTag::get_data ( const SequenceManager seqman,
Error error_handler,
const Range entities,
const void **  data_ptrs,
int *  data_lengths 
) const [virtual]

Get tag value for passed entities.

Get tag values for specified entities.

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to retrieve tag data
data_ptrsArray of pointers to tag values, one pointer for each passed entity.
data_lengthsOne value for each entity specifying the length of the tag value for the corresponding entity.

Implements moab::TagInfo.

Definition at line 308 of file BitTag.cpp.

References MB_SET_ERR, and MB_TYPE_OUT_OF_RANGE.

{
    MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "Operation get_data not supported for bit tags" );
}
ErrorCode moab::BitTag::get_entities_with_bits ( EntityType  type,
Range entities,
unsigned char  bits 
) const

Get entities for which an explicit tag of the specified value is stored.

Definition at line 449 of file BitTag.cpp.

References moab::CREATE_HANDLE(), ents_per_page(), MB_SUCCESS, pageList, storedBitsPerEntity, t, and moab::type_range().

Referenced by find_entities_with_value(), and get_entities_with_bits().

{
    std::pair< EntityType, EntityType > r = type_range( type );
    const int per_page                    = ents_per_page();
    for( EntityType t = r.first; t != r.second; ++t )
    {
        for( size_t i = 0; i < pageList[t].size(); ++i )
        {
            if( pageList[t][i] )
            {
                EntityID id    = i * per_page;
                EntityHandle h = CREATE_HANDLE( t, id );
                int off        = !i;  // Never zero ID
                pageList[t][i]->search( bits, off, per_page - off, storedBitsPerEntity, entities, h + off );
            }
        }
    }

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::get_entities_with_bits ( const Range range,
EntityType  type,
Range entities,
unsigned char  bits 
) const

Get entities for which an explicit tag of the specified value is stored.

Definition at line 470 of file BitTag.cpp.

References moab::Range::const_iterator::end_of_block(), ents_per_page(), moab::Range::equal_range(), ErrorCode, get_entities_with_bits(), MB_CHK_ERR, MB_SUCCESS, MBMAXTYPE, MBVERTEX, pageList, size, storedBitsPerEntity, moab::TYPE_FROM_HANDLE(), and unpack().

{
    if( MBMAXTYPE == in_type )
    {
        ErrorCode rval;
        for( --in_type; in_type >= MBVERTEX; --in_type )
        {
            rval = get_entities_with_bits( range, in_type, entities, bits );MB_CHK_ERR( rval );
        }
        return MB_SUCCESS;
    }

    EntityType type;
    EntityID count;
    size_t page;
    int offset, per_page = ents_per_page();
    Range::const_iterator i, end;
    std::pair< Range::iterator, Range::iterator > r = range.equal_range( in_type );
    i                                               = r.first;
    end                                             = r.second;
    EntityHandle h;
    while( i != end )
    {
        h = *i;
        unpack( h, type, page, offset );
        assert( MBMAXTYPE == in_type || type == in_type );

        i     = i.end_of_block();
        count = *i - h + 1;
        ++i;
        while( count > 0 )
        {
            EntityID pcount = std::min( count, (EntityID)( per_page - offset ) );
            if( page < pageList[type].size() && pageList[type][page] )
                pageList[type][page]->search( bits, offset, pcount, storedBitsPerEntity, entities, h );

            count -= pcount;
            h += pcount;
            assert( TYPE_FROM_HANDLE( h ) == type );
            offset = 0;
            ++page;
        }
    }

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::get_memory_use ( const SequenceManager seqman,
unsigned long &  total,
unsigned long &  per_entity 
) const [virtual]

Get memory use for tag data.

Implements moab::TagInfo.

Definition at line 520 of file BitTag.cpp.

References MB_SUCCESS, MBMAXTYPE, pageList, storedBitsPerEntity, and t.

{
    per_entity = ( storedBitsPerEntity > 4 );  // Cannot return fraction of bytes, so round
    total      = 0;
    for( EntityType t = (EntityType)0; t < MBMAXTYPE; ++t )
    {
        total += pageList[t].capacity() * sizeof( BitPage* );
        for( size_t i = 0; i < pageList[t].size(); ++i )
            if( pageList[t][i] ) total += sizeof( BitPage );
    }

    return MB_SUCCESS;
}

Implements moab::TagInfo.

Definition at line 19 of file BitTag.cpp.

References MB_TAG_BIT.

{
    return MB_TAG_BIT;
}
template<class Container >
void moab::BitTag::get_tagged ( EntityType  type,
Container &  entities 
) const [inline, private]

Definition at line 339 of file BitTag.cpp.

References moab::CREATE_HANDLE(), ents_per_page(), pageList, t, and moab::type_range().

{
    std::pair< EntityType, EntityType > r = type_range( type );
    typename Container::iterator hint     = entities.begin();
    const int per_page                    = ents_per_page();
    for( EntityType t = r.first; t != r.second; ++t )
    {
        for( size_t i = 0; i < pageList[t].size(); ++i )
        {
            if( pageList[t][i] )
            {
                EntityID id       = i * per_page;
                EntityHandle h    = CREATE_HANDLE( t, id );
                EntityHandle last = h + per_page - 1;
                // Never zero ID
                if( 0 == id ) ++h;
                hint = entities.insert( hint, h, last );
            }
        }
    }
}
template<class Container >
void moab::BitTag::get_tagged ( Range::const_iterator  begin,
Range::const_iterator  end,
Container &  entities 
) const [inline, private]

Definition at line 362 of file BitTag.cpp.

References moab::Range::const_iterator::end_of_block(), ents_per_page(), pageList, size, moab::TYPE_FROM_HANDLE(), and unpack().

{
    EntityType type;
    EntityID count;
    size_t page;
    int offset, per_page = ents_per_page();
    typename Container::iterator hint = entities.begin();
    EntityHandle h;
    Range::const_iterator i = begin;
    while( i != end )
    {
        h = *i;
        unpack( h, type, page, offset );

        i     = i.end_of_block();
        count = *i - h + 1;
        ++i;
        while( count > 0 )
        {
            EntityID pcount = std::min( count, (EntityID)( per_page - offset ) );
            if( page < pageList[type].size() && pageList[type][page] )
                hint = entities.insert( hint, h, h + pcount - 1 );

            count -= pcount;
            h += pcount;
            assert( TYPE_FROM_HANDLE( h ) == type );
            offset = 0;
            ++page;
        }
    }
}
template<class Container >
void moab::BitTag::get_tagged ( Container &  entities,
EntityType  type,
const Range intersect 
) const [inline, private]

Definition at line 395 of file BitTag.cpp.

References moab::Range::begin(), moab::Range::end(), entities, moab::Range::equal_range(), and MBMAXTYPE.

{
    if( !intersect )
        get_tagged< Container >( type, entities );
    else if( MBMAXTYPE == type )
        get_tagged< Container >( intersect->begin(), intersect->end(), entities );
    else
    {
        std::pair< Range::iterator, Range::iterator > r = intersect->equal_range( type );
        get_tagged< Container >( r.first, r.second, entities );
    }
}
ErrorCode moab::BitTag::get_tagged_entities ( const SequenceManager seqman,
Range output_entities,
EntityType  type = MBMAXTYPE,
const Range intersect = 0 
) const [virtual]

Get all tagged entities.

Get the list of entities for which the a tag value has been set, or a close approximation if the tag storage scheme cannot accurately determine exactly which entities have explicit values.

Parameters:
seqmanPointer to entity storage database
output_entitiesResults *appended* to this range
typeOptional entity type. If specified, search is limited to entities of specified type.
intersectOptional intersect list. If specified, search is restricted to entities in this list.

Implements moab::TagInfo.

Definition at line 409 of file BitTag.cpp.

References entities, moab::intersect(), and MB_SUCCESS.

{
    get_tagged< Range >( entities, type, intersect );
    return MB_SUCCESS;
}
bool moab::BitTag::is_tagged ( const SequenceManager ,
EntityHandle  h 
) const [virtual]

Check if entity is tagged.

Implements moab::TagInfo.

Definition at line 534 of file BitTag.cpp.

References pageList, and unpack().

{
    EntityType type;
    size_t page;
    int offset;
    unpack( h, type, page, offset );
    return page < pageList[type].size() && pageList[type][page];
}
ErrorCode moab::BitTag::num_tagged_entities ( const SequenceManager seqman,
size_t &  output_count,
EntityType  type = MBMAXTYPE,
const Range intersect = 0 
) const [virtual]

Count all tagged entities.

Count the entities for which the a tag value has been set, or a close approximation if the tag storage scheme cannot accurately determine exactly which entities have explicit values.

Parameters:
seqmanPointer to entity storage database
output_countThis is *incremented* for each detected entity.
typeOptional entity type. If specified, search is limited to entities of specified type.
intersectOptional intersect list. If specified, search is restricted to entities in this list.

Implements moab::TagInfo.

Definition at line 418 of file BitTag.cpp.

References moab::intersect(), and MB_SUCCESS.

{
    InsertCount counter( count );
    get_tagged< InsertCount >( counter, type, intersect );
    count = counter.end();
    return MB_SUCCESS;
}
BitTag& moab::BitTag::operator= ( const BitTag ) [private]
ErrorCode moab::BitTag::release_all_data ( SequenceManager seqman,
Error error_handler,
bool  delete_pending 
) [virtual]

Remove/clear tag data for all entities.

Remove tag values from entities.

Parameters:
delete_pendingIf true, then release any global data associated with the tag in preparation for deleting the tag itself.

Invalidates tag if tag_delete_pending is true. The only valid method that can be invoked that is is the destructor.

Parameters:
seqmanPointer to mesh entity database

Implements moab::TagInfo.

Definition at line 60 of file BitTag.cpp.

References MB_SUCCESS, MBMAXTYPE, pageList, and t.

Referenced by ~BitTag().

{
    for( EntityType t = (EntityType)0; t != MBMAXTYPE; ++t )
    {
        for( size_t i = 0; i < pageList[t].size(); ++i )
            delete pageList[t][i];
        pageList[t].clear();
    }

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::remove_data ( SequenceManager seqman,
Error error_handler,
const EntityHandle entities,
size_t  num_entities 
) [virtual]

Remove/clear tag data for entities.

Remove tag values from entities.

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to store tag data
num_entitiesLength of entities array

Implements moab::TagInfo.

Definition at line 144 of file BitTag.cpp.

References default_val(), MB_SUCCESS, pageList, size, storedBitsPerEntity, and unpack().

{
    EntityType type;
    size_t page;
    int offset;
    const unsigned char val = default_val();
    for( size_t i = 0; i < num_handles; ++i )
    {
        unpack( handles[i], type, page, offset );
        if( pageList[type].size() > page && pageList[type][page] )
            pageList[type][page]->set_bits( offset, storedBitsPerEntity, val );
    }

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::remove_data ( SequenceManager seqman,
Error error_handler,
const Range entities 
) [virtual]

Remove/clear tag data for entities.

Remove tag values from entities.

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to store tag data

Implements moab::TagInfo.

Definition at line 270 of file BitTag.cpp.

References moab::Range::const_pair_begin(), moab::Range::const_pair_end(), default_val(), ents_per_page(), MB_SUCCESS, pageList, size, storedBitsPerEntity, moab::TYPE_FROM_HANDLE(), and unpack().

{
    EntityType type;
    EntityID count;
    size_t page;
    int offset, per_page = ents_per_page();
    unsigned char val = default_val();
    Range::const_pair_iterator i;
    for( i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i )
    {
        unpack( i->first, type, page, offset );
        assert( TYPE_FROM_HANDLE( i->second ) == type );  // Should be true because id of zero is never used
        count = i->second - i->first + 1;

        while( count )
        {
            size_t pcount = std::min( (EntityID)( per_page - offset ), count );
            if( page < pageList[type].size() && pageList[type][page] )
                pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, val );
            count -= pcount;
            offset = 0;
            ++page;
        }
    }

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::reserve ( unsigned  bits) [private]

Definition at line 36 of file BitTag.cpp.

References Ln2PageSize, MB_SUCCESS, pageShift, requestedBitsPerEntity, and storedBitsPerEntity.

Referenced by create_tag().

{
    if( bits > 8 ) return MB_FAILURE;

    requestedBitsPerEntity = bits;
    // Store smallest power of two greater than or
    // equal to the number of bits
    storedBitsPerEntity    = 1;
    unsigned ln2storedbits = 0;
    while( storedBitsPerEntity < bits )
    {
        storedBitsPerEntity *= 2;
        ++ln2storedbits;
    }

    // pageShift = log2(ents_per_page())
    //           = log2(8 * pageSize / storedBitsPerEntity )
    //           = log2(8) + log2(pageSize) - log2(storedBitsPerEntity)
    //           = 3 + Ln2PageSize - ln2storedbits;
    pageShift = 3 + Ln2PageSize - ln2storedbits;

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::set_data ( SequenceManager seqman,
Error error_handler,
const EntityHandle entities,
size_t  num_entities,
const void *  data 
) [virtual]

Set tag value for passed entities.

Store tag data or update stored tag values Will fail for variable-length data.

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to store tag data
num_entitiesLength of entities array
dataPointer to memory holding consecutive tag values, one for each passed entity.

Implements moab::TagInfo.

Definition at line 95 of file BitTag.cpp.

References moab::SequenceManager::check_valid_entities(), default_val(), ErrorCode, MB_CHK_ERR, MB_SUCCESS, pageList, size, storedBitsPerEntity, and unpack().

{
    ErrorCode rval = seqman->check_valid_entities( NULL, handles, num_handles, true );MB_CHK_ERR( rval );

    EntityType type;
    size_t page;
    int offset;
    const unsigned char* data = reinterpret_cast< const unsigned char* >( gen_data );
    for( size_t i = 0; i < num_handles; ++i )
    {
        unpack( handles[i], type, page, offset );
        if( pageList[type].size() <= page ) pageList[type].resize( page + 1, 0 );
        if( !pageList[type][page] ) pageList[type][page] = new BitPage( storedBitsPerEntity, default_val() );
        pageList[type][page]->set_bits( offset, storedBitsPerEntity, data[i] );
    }

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::set_data ( SequenceManager seqman,
Error error_handler,
const Range entities,
const void *  data 
) [virtual]

Set tag value for passed entities.

Store tag data or update stored tag values Will fail for variable-length data.

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to store tag data
dataPointer to memory holding consecutive tag values, one for each passed entity.

Implements moab::TagInfo.

Definition at line 198 of file BitTag.cpp.

References moab::SequenceManager::check_valid_entities(), moab::Range::const_pair_begin(), moab::Range::const_pair_end(), default_val(), ents_per_page(), ErrorCode, MB_CHK_ERR, MB_SUCCESS, pageList, size, storedBitsPerEntity, moab::TYPE_FROM_HANDLE(), and unpack().

{
    ErrorCode rval = seqman->check_valid_entities( NULL, handles );MB_CHK_ERR( rval );

    EntityType type;
    EntityID count;
    size_t page;
    int offset, per_page = ents_per_page();
    unsigned char def         = default_val();
    const unsigned char* data = reinterpret_cast< const unsigned char* >( gen_data );
    Range::const_pair_iterator i;
    for( i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i )
    {
        unpack( i->first, type, page, offset );
        assert( TYPE_FROM_HANDLE( i->second ) == type );  // Should be true because id of zero is never used
        count = i->second - i->first + 1;

        while( count )
        {
            if( page >= pageList[type].size() ) pageList[type].resize( page + 1, 0 );
            if( !pageList[type][page] ) pageList[type][page] = new BitPage( storedBitsPerEntity, def );

            size_t pcount = std::min( (EntityID)( per_page - offset ), count );
            pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, data );
            data += pcount;
            count -= pcount;
            offset = 0;
            ++page;
        }
    }

    return MB_SUCCESS;
}
ErrorCode moab::BitTag::set_data ( SequenceManager seqman,
Error error_handler,
const EntityHandle entities,
size_t  num_entities,
void const *const *  data_ptrs,
const int *  data_lengths 
) [virtual]

Set tag value for passed entities.

Store tag data or update stored tag values

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to store tag data
num_entitiesLength of entities array
data_ptrsArray of pointers to tag values, one pointer for each passed entity.
data_lengthsOne value for each entity specifying the length of the tag value for the corresponding entity. Array is required for variable-length tags and is ignored for fixed-length tags.

Implements moab::TagInfo.

Definition at line 313 of file BitTag.cpp.

References MB_SET_ERR, and MB_TYPE_OUT_OF_RANGE.

{
    MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "Operation set_data not supported for bit tags" );
}
ErrorCode moab::BitTag::set_data ( SequenceManager seqman,
Error error_handler,
const Range entities,
void const *const *  data_ptrs,
const int *  data_lengths 
) [virtual]

Set tag value for passed entities.

Store tag data or update stored tag values

Parameters:
seqmanPointer to mesh entity database
entitiesEntity handles for which to store tag data
data_ptrsArray of pointers to tag values, one pointer for each passed entity.
data_lengthsOne value for each entity specifying the length of the tag value for the corresponding entity. Array is required for variable-length tags and is ignored for fixed-length tags.

Implements moab::TagInfo.

Definition at line 323 of file BitTag.cpp.

References MB_SET_ERR, and MB_TYPE_OUT_OF_RANGE.

{
    MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "Operation set_data not supported for bit tags" );
}
ErrorCode moab::BitTag::tag_iterate ( SequenceManager seqman,
Error error_handler,
Range::iterator iter,
const Range::iterator end,
void *&  data_ptr,
bool  allocate = true 
) [virtual]

Access tag data via direct pointer into contiguous blocks.

Iteratively obtain direct access to contiguous blocks of tag storage. This function cannot be used with bit tags because of the compressed bit storage. This function cannot be used with variable length tags because it does not provide a mechanism to determine the length of the value for each entity. This function may be used with sparse tags, but if it is used, it will return data for a single entity at a time.

Parameters:
iterAs input, the first entity for which to return data. As output, one past the last entity for which data was returned.
endOne past the last entity for which data is desired
data_ptrOutput: pointer to tag storage.

If this function is called for entities for which no tag value has been set, but for which a default value exists, it will force the allocation of explicit storage for each such entity even though MOAB would normally not explicitly store tag values for such entities.

Implements moab::TagInfo.

Definition at line 328 of file BitTag.cpp.

References MB_SET_ERR, and MB_TYPE_OUT_OF_RANGE.

{
    MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "Operation tag_iterate not supported for bit tags" );
}
void moab::BitTag::unpack ( EntityHandle  h,
EntityType &  type,
size_t &  page,
int &  offset 
) const [inline, private]

Get indices from handle.

Parameters:
typeOutput: entity type
pageOutput: index into pageList[type]
offsetOutput: index into pageList[type][page]

Definition at line 377 of file BitTag.hpp.

References moab::ID_FROM_HANDLE(), pageShift, and moab::TYPE_FROM_HANDLE().

Referenced by clear_data(), get_data(), get_entities_with_bits(), get_tagged(), is_tagged(), remove_data(), and set_data().

    {
        type   = TYPE_FROM_HANDLE( h );
        h      = ID_FROM_HANDLE( h );
        page   = ( (size_t)h ) >> pageShift;        // h / ents_per_page()
        offset = h & ( ( 1u << pageShift ) - 1u );  // h % ends_per_page()
    }

Member Data Documentation

std::vector< BitPage* > moab::BitTag::pageList[MBMAXTYPE] [private]

Array of BitPage instances storing actual data.

Definition at line 366 of file BitTag.hpp.

Referenced by clear_data(), get_data(), get_entities_with_bits(), get_memory_use(), get_tagged(), is_tagged(), release_all_data(), remove_data(), and set_data().

unsigned int moab::BitTag::pageShift [private]

log2( ents_per_page() )

Definition at line 369 of file BitTag.hpp.

Referenced by reserve(), and unpack().

unsigned int moab::BitTag::requestedBitsPerEntity [private]

user-requested bits per entity

Definition at line 367 of file BitTag.hpp.

Referenced by reserve().

unsigned int moab::BitTag::storedBitsPerEntity [private]

allocated bits per entity (power of 2)

Definition at line 368 of file BitTag.hpp.

Referenced by clear_data(), ents_per_page(), get_data(), get_entities_with_bits(), get_memory_use(), remove_data(), reserve(), and set_data().

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