MOAB: Mesh Oriented datABase  (version 5.2.1)
moab::SparseTag Class Reference

Sparse tag data. More...

#include <SparseTag.hpp>

+ Inheritance diagram for moab::SparseTag:
+ Collaboration diagram for moab::SparseTag:

Public Types

typedef
MOAB_UNORDERED_MAP_NS::unordered_map
< EntityHandle, void * > 
MapType
 map of entity id and tag data

Public Member Functions

 SparseTag (const char *name, int size, DataType type, const void *default_value)
 ~SparseTag ()
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.
virtual ErrorCode get_memory_use (const SequenceManager *seqman, unsigned long &total, unsigned long &per_entity) const
 Get memory use for tag data.
unsigned long get_number_entities ()
 get number of entities

Private Member Functions

 SparseTag (const SparseTag &)
SparseTagoperator= (const SparseTag &)
void * allocate_data (EntityHandle h, MapType::const_iterator iter, bool copy_default=true)
 allocate an entry for this sparse tag w/o setting its value (yet)
ErrorCode set_data (Error *, EntityHandle entity_handle, const void *data)
ErrorCode get_data (Error *, EntityHandle entity_handle, void *data) const
ErrorCode get_data_ptr (EntityHandle entity_handle, const void *&data, bool allocate=true) const
 get the variable-length data for an entity id
ErrorCode remove_data (Error *, EntityHandle entity_handle)
 removes the data

Private Attributes

SparseTagDataAllocator mAllocator
 allocator for this collection
MapType mData

Detailed Description

Sparse tag data.

Definition at line 64 of file SparseTag.hpp.


Member Typedef Documentation

typedef MOAB_UNORDERED_MAP_NS::unordered_map< EntityHandle, void* > moab::SparseTag::MapType

map of entity id and tag data

Definition at line 348 of file SparseTag.hpp.


Constructor & Destructor Documentation

moab::SparseTag::SparseTag ( const char *  name,
int  size,
DataType  type,
const void *  default_value 
)

Definition at line 31 of file SparseTag.cpp.

    : TagInfo( name, size, type, default_value, size )
{
}

Definition at line 36 of file SparseTag.cpp.

References release_all_data().

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

Member Function Documentation

void * moab::SparseTag::allocate_data ( EntityHandle  h,
MapType::const_iterator  iter,
bool  copy_default = true 
) [inline, private]

allocate an entry for this sparse tag w/o setting its value (yet)

Definition at line 382 of file SparseTag.hpp.

References moab::SparseTagDataAllocator::allocate(), moab::TagInfo::get_default_value(), moab::TagInfo::get_size(), mAllocator, and mData.

Referenced by set_data(), and tag_iterate().

{
    void* new_data = mAllocator.allocate( get_size() );
#ifdef MOAB_HAVE_UNORDERED_MAP
    mData.insert( iter, std::pair< const EntityHandle, void* >( h, new_data ) );
#else
    mData[h] = new_data;
#endif
    if( copy_default ) memcpy( new_data, get_default_value(), get_size() );
    return new_data;
}
ErrorCode moab::SparseTag::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 249 of file SparseTag.cpp.

References moab::SequenceManager::check_valid_entities(), moab::TagInfo::get_name(), moab::TagInfo::get_size(), MB_CHK_ERR, MB_INVALID_SIZE, MB_SET_ERR, MB_SUCCESS, and set_data().

{
    if( value_len && value_len != get_size() )
    {
        MB_SET_ERR( MB_INVALID_SIZE, "Invalid data size " << get_size() << " specified for sparse tag " << get_name()
                                                          << " of size " << value_len );
    }

    ErrorCode rval = seqman->check_valid_entities( NULL, entities, num_entities, true );MB_CHK_ERR( rval );

    for( size_t i = 0; i < num_entities; ++i )
    {
        rval = set_data( NULL, entities[i], value_ptr );MB_CHK_ERR( rval );
    }

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 268 of file SparseTag.cpp.

References moab::Range::begin(), moab::SequenceManager::check_valid_entities(), moab::Range::end(), moab::TagInfo::get_name(), moab::TagInfo::get_size(), MB_CHK_ERR, MB_INVALID_SIZE, MB_SET_ERR, MB_SUCCESS, and set_data().

{
    if( value_len && value_len != get_size() )
    {
        MB_SET_ERR( MB_INVALID_SIZE, "Invalid data size " << get_size() << " specified for sparse tag " << get_name()
                                                          << " of size " << value_len );
    }

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

    Range::const_iterator i;
    for( i = entities.begin(); i != entities.end(); ++i )
    {
        rval = set_data( NULL, *i, value_ptr );MB_CHK_ERR( rval );
    }

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 415 of file SparseTag.cpp.

References moab::Range::begin(), moab::CREATE_HANDLE(), moab::Range::end(), moab::Range::equal_range(), moab::find_map_values_equal(), moab::find_tag_values_equal(), moab::TagInfo::get_name(), moab::TagInfo::get_size(), MB_END_ID, MB_INVALID_SIZE, MB_SET_ERR, MB_START_ID, MB_SUCCESS, MBMAXTYPE, and mData.

{
    if( value_bytes && value_bytes != get_size() )
    {
        MB_SET_ERR( MB_INVALID_SIZE, "Invalid data size " << get_size() << " specified for sparse tag " << get_name()
                                                          << " of size " << value_bytes );
    }

    MapType::const_iterator iter, end;
#ifdef MOAB_HAVE_UNORDERED_MAP
    if( intersect_entities )
    {
        std::pair< Range::iterator, Range::iterator > r;
        if( type == MBMAXTYPE )
        {
            r.first  = intersect_entities->begin();
            r.second = intersect_entities->end();
        }
        else
        {
            r = intersect_entities->equal_range( type );
        }

        find_map_values_equal( *this, value, get_size(), r.first, r.second, mData, output_entities );
    }
    else if( type == MBMAXTYPE )
    {
        find_tag_values_equal( *this, value, get_size(), mData.begin(), mData.end(), output_entities );
    }
    else
    {
        Range tmp;
        seqman->get_entities( type, tmp );
        find_map_values_equal( *this, value, get_size(), tmp.begin(), tmp.end(), mData, output_entities );
    }
#else
    if( intersect_entities )
    {
        for( Range::const_pair_iterator p = intersect_entities->begin(); p != intersect_entities->end(); ++p )
        {
            iter = mData.lower_bound( p->first );
            end = mData.upper_bound( p->second );
            find_tag_values_equal( *this, value, get_size(), iter, end, output_entities );
        }
    }
    else
    {
        if( type == MBMAXTYPE )
        {
            iter = mData.begin();
            end = mData.end();
        }
        else
        {
            iter = mData.lower_bound( CREATE_HANDLE( type, MB_START_ID ) );
            end = mData.upper_bound( CREATE_HANDLE( type, MB_END_ID ) );
        }
        find_tag_values_equal( *this, value, get_size(), iter, end, output_entities );
    }
#endif

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 117 of file SparseTag.cpp.

References moab::TagInfo::get_size(), and MB_SUCCESS.

Referenced by get_data().

{
    ErrorCode rval;
    unsigned char* ptr = reinterpret_cast< unsigned char* >( data );
    for( size_t i = 0; i < num_entities; ++i, ptr += get_size() )
    {
        rval = get_data( NULL, entities[i], ptr );
        if( MB_SUCCESS != rval ) return rval;
    }

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 131 of file SparseTag.cpp.

References moab::Range::begin(), moab::Range::end(), get_data(), moab::TagInfo::get_size(), and MB_SUCCESS.

{
    ErrorCode rval;
    unsigned char* ptr = reinterpret_cast< unsigned char* >( data );
    Range::const_iterator i;
    for( i = entities.begin(); i != entities.end(); ++i, ptr += get_size() )
    {
        rval = get_data( NULL, *i, ptr );
        if( MB_SUCCESS != rval ) return rval;
    }

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 145 of file SparseTag.cpp.

References get_data_ptr(), moab::TagInfo::get_default_value(), moab::TagInfo::get_size(), MB_SUCCESS, MB_TAG_NOT_FOUND, and moab::SysUtil::setmem().

{
    if( data_lengths )
    {
        int len = get_size();
        SysUtil::setmem( data_lengths, &len, sizeof( int ), num_entities );
    }

    ErrorCode rval = MB_SUCCESS, rval_tmp;
    for( size_t i = 0; i < num_entities; ++i, ++pointers )
    {
        rval_tmp = get_data_ptr( entities[i], *pointers );
        if( MB_SUCCESS != rval_tmp && get_default_value() ) { *pointers = get_default_value(); }
        else if( MB_SUCCESS != rval_tmp )
        {
            return MB_TAG_NOT_FOUND;
        }
    }

    return rval;
}
ErrorCode moab::SparseTag::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 168 of file SparseTag.cpp.

References moab::Range::begin(), moab::Range::end(), get_data_ptr(), moab::TagInfo::get_default_value(), moab::TagInfo::get_size(), MB_SUCCESS, MB_TAG_NOT_FOUND, moab::SysUtil::setmem(), and moab::Range::size().

{
    if( data_lengths )
    {
        int len = get_size();
        SysUtil::setmem( data_lengths, &len, sizeof( int ), entities.size() );
    }

    ErrorCode rval = MB_SUCCESS, rval_tmp;
    Range::const_iterator i;
    for( i = entities.begin(); i != entities.end(); ++i, ++pointers )
    {
        rval_tmp = get_data_ptr( *i, *pointers );
        if( MB_SUCCESS != rval_tmp && get_default_value() ) { *pointers = get_default_value(); }
        else if( MB_SUCCESS != rval_tmp )
        {
            return MB_TAG_NOT_FOUND;
        }
    }

    return rval;
}
ErrorCode moab::SparseTag::get_data ( Error ,
EntityHandle  entity_handle,
void *  data 
) const [inline, private]

get the tag data for an entity id Will fail with MB_VARIABLE_DATA_LENGTH if called for variable-length tag.

Definition at line 88 of file SparseTag.cpp.

References get_data_ptr(), moab::TagInfo::get_default_value(), moab::TagInfo::get_size(), MB_SUCCESS, and MB_TAG_NOT_FOUND.

{
    const void* ptr = 0;
    ErrorCode rval  = get_data_ptr( entity_handle, ptr, false );
    if( MB_SUCCESS == rval )
    {
        memcpy( data, ptr, get_size() );
        return rval;
    }
    else if( get_default_value() )
    {
        memcpy( data, get_default_value(), get_size() );
        return MB_SUCCESS;
    }
    else
        return MB_TAG_NOT_FOUND;
}
ErrorCode moab::SparseTag::get_data_ptr ( EntityHandle  entity_handle,
const void *&  data,
bool  allocate = true 
) const [inline, private]

get the variable-length data for an entity id

Definition at line 74 of file SparseTag.cpp.

References moab::TagInfo::get_default_value(), MB_FAILURE, MB_SUCCESS, and mData.

Referenced by get_data(), and tag_iterate().

{
    MapType::const_iterator iter = mData.find( entity_handle );

    if( iter != mData.end() )
        ptr = iter->second;
    else if( get_default_value() && allocate )
        ptr = const_cast< SparseTag* >( this )->allocate_data( entity_handle, iter, allocate );
    else
        return MB_FAILURE;

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 491 of file SparseTag.cpp.

References moab::TagInfo::get_memory_use(), moab::TagInfo::get_size(), MB_SUCCESS, and mData.

{
    per_entity = get_size() + 4 * sizeof( void* );
    total      = ( mData.size() * per_entity ) + sizeof( *this ) + TagInfo::get_memory_use();

    return MB_SUCCESS;
}
unsigned long moab::SparseTag::get_number_entities ( ) [inline]

get number of entities

Definition at line 341 of file SparseTag.hpp.

References mData.

    {
        return mData.size();
    }

Implements moab::TagInfo.

Definition at line 41 of file SparseTag.cpp.

References MB_TAG_SPARSE.

{
    return MB_TAG_SPARSE;
}
ErrorCode moab::SparseTag::get_tagged_entities ( const SequenceManager seqman,
Range output_entities,
EntityType  type = MBMAXTYPE,
const Range intersect = 0 
) const [virtual]

Get all tagged entities.

Gets all entity handles that match a type and tag.

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 398 of file SparseTag.cpp.

References moab::get_tagged(), MB_SUCCESS, and mData.

Referenced by moab::WriteDamsel::map_sparse_tags().

{
    get_tagged( mData, output_range, type, intersect );
    return MB_SUCCESS;
}
bool moab::SparseTag::is_tagged ( const SequenceManager ,
EntityHandle  h 
) const [virtual]

Check if entity is tagged.

Implements moab::TagInfo.

Definition at line 486 of file SparseTag.cpp.

References mData.

{
    return mData.find( h ) != mData.end();
}
ErrorCode moab::SparseTag::num_tagged_entities ( const SequenceManager seqman,
size_t &  output_count,
EntityType  type = MBMAXTYPE,
const Range intersect = 0 
) const [virtual]

Count all tagged entities.

Gets all entity handles that match a type and tag.

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 406 of file SparseTag.cpp.

References moab::InsertCount::end(), moab::get_tagged(), MB_SUCCESS, and mData.

{
    InsertCount counter( output_count );
    get_tagged( mData, counter, type, intersect );
    output_count = counter.end();
    return MB_SUCCESS;
}
SparseTag& moab::SparseTag::operator= ( const SparseTag ) [private]
ErrorCode moab::SparseTag::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 46 of file SparseTag.cpp.

References moab::SparseTagDataAllocator::destroy(), mAllocator, MB_SUCCESS, and mData.

Referenced by ~SparseTag().

{
    for( MapType::iterator i = mData.begin(); i != mData.end(); ++i )
        mAllocator.destroy( i->second );
    mData.clear();
    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 288 of file SparseTag.cpp.

References MB_SUCCESS.

Referenced by remove_data().

{
    ErrorCode rval;
    for( size_t i = 0; i < num_entities; ++i )
    {
        rval = remove_data( NULL, entities[i] );
        if( MB_SUCCESS != rval ) return rval;
    }

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 301 of file SparseTag.cpp.

References moab::Range::begin(), moab::Range::end(), MB_SUCCESS, MB_TAG_NOT_FOUND, and remove_data().

{
    for( Range::const_iterator i = entities.begin(); i != entities.end(); ++i )
        if( MB_SUCCESS != remove_data( NULL, *i ) ) return MB_TAG_NOT_FOUND;

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::remove_data ( Error ,
EntityHandle  entity_handle 
) [inline, private]

removes the data

Definition at line 106 of file SparseTag.cpp.

References moab::SparseTagDataAllocator::destroy(), mAllocator, MB_SUCCESS, MB_TAG_NOT_FOUND, and mData.

{
    MapType::iterator i = mData.find( entity_handle );
    if( i == mData.end() ) return MB_TAG_NOT_FOUND;

    mAllocator.destroy( i->second );
    mData.erase( i );

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 192 of file SparseTag.cpp.

References moab::SequenceManager::check_valid_entities(), moab::TagInfo::get_size(), MB_CHK_ERR, and MB_SUCCESS.

Referenced by clear_data(), and set_data().

{
    ErrorCode rval = seqman->check_valid_entities( NULL, entities, num_entities, true );MB_CHK_ERR( rval );

    const unsigned char* ptr = reinterpret_cast< const unsigned char* >( data );
    for( size_t i = 0; i < num_entities; ++i, ptr += get_size() )
    {
        rval = set_data( NULL, entities[i], ptr );MB_CHK_ERR( rval );
    }

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 206 of file SparseTag.cpp.

References moab::Range::begin(), moab::SequenceManager::check_valid_entities(), moab::Range::end(), moab::TagInfo::get_size(), MB_CHK_ERR, MB_SUCCESS, and set_data().

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

    const unsigned char* ptr = reinterpret_cast< const unsigned char* >( data );
    Range::const_iterator i;
    for( i = entities.begin(); i != entities.end(); ++i, ptr += get_size() )
        if( MB_SUCCESS != ( rval = set_data( NULL, *i, ptr ) ) ) return rval;

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 218 of file SparseTag.cpp.

References moab::SequenceManager::check_valid_entities(), MB_CHK_ERR, MB_SUCCESS, set_data(), and moab::TagInfo::validate_lengths().

{
    ErrorCode rval = validate_lengths( NULL, lengths, num_entities );MB_CHK_ERR( rval );

    rval = seqman->check_valid_entities( NULL, entities, num_entities, true );MB_CHK_ERR( rval );

    for( size_t i = 0; i < num_entities; ++i, ++pointers )
    {
        rval = set_data( NULL, entities[i], *pointers );MB_CHK_ERR( rval );
    }

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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 233 of file SparseTag.cpp.

References moab::Range::begin(), moab::SequenceManager::check_valid_entities(), moab::Range::end(), MB_CHK_ERR, MB_SUCCESS, set_data(), moab::Range::size(), and moab::TagInfo::validate_lengths().

{
    ErrorCode rval = validate_lengths( NULL, lengths, entities.size() );MB_CHK_ERR( rval );

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

    Range::const_iterator i;
    for( i = entities.begin(); i != entities.end(); ++i, ++pointers )
    {
        rval = set_data( NULL, *i, *pointers );MB_CHK_ERR( rval );
    }

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::set_data ( Error ,
EntityHandle  entity_handle,
const void *  data 
) [inline, private]

set the tag data for an entity id Will fail with MB_VARIABLE_DATA_LENGTH if called for variable-length tag.

Definition at line 54 of file SparseTag.cpp.

References allocate_data(), moab::TagInfo::get_size(), MB_SUCCESS, and mData.

{
#ifdef MOAB_HAVE_UNORDERED_MAP
    MapType::iterator iter = mData.find( entity_handle );
#else
    MapType::iterator iter = mData.lower_bound( entity_handle );
#endif

    // Data space already exists
    if( iter != mData.end() && iter->first == entity_handle ) memcpy( iter->second, data, get_size() );
    // We need to make some data space
    else
    {
        void* new_data = allocate_data( entity_handle, iter, false );
        memcpy( new_data, data, get_size() );
    }

    return MB_SUCCESS;
}
ErrorCode moab::SparseTag::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.
allocateIf true, space for this tag will be allocated, if not it wont

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 309 of file SparseTag.cpp.

References allocate_data(), moab::SequenceManager::check_valid_entities(), get_data_ptr(), moab::TagInfo::get_default_value(), MB_CHK_ERR, MB_SUCCESS, and mData.

{
    // Note: We are asked to returning a block of contiguous storage
    //       for some block of contiguous handles for which the tag
    //       storage is also contiguous. As sparse tag storage is
    //       never contiguous, all we can do is return a pointer to the
    //       data for the first entity.

    // If asked for nothing, successfully return nothing.
    if( iter == end ) return MB_SUCCESS;

    // Note: get_data_ptr will return the default value if the
    //       handle is not found, so test to make sure that the
    //       handle is valid.
    ErrorCode rval = seqman->check_valid_entities( NULL, &*iter, 1 );MB_CHK_ERR( rval );

    // Get pointer to tag storage for entity pointed to by iter
    const void* ptr = NULL;
    rval            = get_data_ptr( *iter, ptr );
    if( MB_SUCCESS == rval )
        data_ptr = const_cast< void* >( ptr );
    else if( get_default_value() && allocate )
    {
        ptr      = allocate_data( *iter, mData.end() );
        data_ptr = const_cast< void* >( ptr );
    }
    else
    {
        // If allocation was not requested, need to increment the iterator so that
        // the count can be computed properly
        if( get_default_value() && !allocate ) ++iter;
        // return not_found(get_name(), *iter);
    }

    // Increment iterator and return
    ++iter;
    return MB_SUCCESS;
}

Member Data Documentation

allocator for this collection

Definition at line 377 of file SparseTag.hpp.

Referenced by allocate_data(), release_all_data(), and remove_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