moab
moab::SparseTag Class Reference

Sparse tag data. More...

#include <SparseTag.hpp>

Inheritance diagram for moab::SparseTag:
moab::TagInfo

List of all members.

Public Types

typedef std::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 59 of file SparseTag.hpp.


Member Typedef Documentation

typedef std::map<EntityHandle,void*> moab::SparseTag::MapType

map of entity id and tag data

Definition at line 415 of file SparseTag.hpp.


Constructor & Destructor Documentation

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

Definition at line 50 of file SparseTag.cpp.

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

Definition at line 57 of file SparseTag.cpp.

  { 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 452 of file SparseTag.hpp.

{
  void* new_data = mAllocator.allocate(get_size());
#ifdef 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 291 of file SparseTag.cpp.

{
  if (value_len && value_len != get_size())
    return invalid_size( error, get_name(), get_size(), value_len );
    
  ErrorCode rval = seqman->check_valid_entities( error, entities, num_entities, true );
  if (MB_SUCCESS != rval)
    return rval;
  
  for (size_t i = 0; i < num_entities; ++i)
    if (MB_SUCCESS != (rval = set_data(error, entities[i], value_ptr)))
      return 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 311 of file SparseTag.cpp.

{
  if (value_len && value_len != get_size())
    return invalid_size( error, get_name(), get_size(), value_len );
    
  ErrorCode rval = seqman->check_valid_entities( error, entities );
  if (MB_SUCCESS != rval)
    return rval;
  
  Range::const_iterator i;
  for (i = entities.begin(); i != entities.end(); ++i)
    if (MB_SUCCESS != (rval = set_data(error, *i, value_ptr)))
      return 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_entitiesOpotional intersect list. If specified, search is restricted to entities in this list.

Implements moab::TagInfo.

Definition at line 473 of file SparseTag.cpp.

{
  if (value_bytes && value_bytes != get_size())
    return invalid_size( error, get_name(), get_size(), value_bytes );
  
  MapType::const_iterator iter, end;
#ifdef 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 135 of file SparseTag.cpp.

{
  ErrorCode rval;
  unsigned char* ptr = reinterpret_cast<unsigned char*>(data);
  for (size_t i = 0; i < num_entities; ++i, ptr += get_size())
    if (MB_SUCCESS != (rval = get_data(error, entities[i], ptr)))
      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 149 of file SparseTag.cpp.

{
  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())
    if (MB_SUCCESS != (rval = get_data(error, *i, ptr)))
      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 163 of file SparseTag.cpp.

{
  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) {
      rval = not_found(error, get_name(), entities[i]);
    }
  }
  
  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 189 of file SparseTag.cpp.

{
  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) {
      rval = not_found(error, get_name(), *i);
    }
  }
  
  return rval;
}
ErrorCode moab::SparseTag::get_data ( Error 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 108 of file SparseTag.cpp.

{
  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 not_found(error, get_name(), entity_handle);;    
}
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 94 of file SparseTag.cpp.

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

{
  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 407 of file SparseTag.hpp.

    { return mData.size(); }

Implements moab::TagInfo.

Definition at line 60 of file SparseTag.cpp.

  { 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.
intersectOpotional intersect list. If specified, search is restricted to entities in this list.

Implements moab::TagInfo.

Definition at line 452 of file SparseTag.cpp.

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

{
  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.
intersectOpotional intersect list. If specified, search is restricted to entities in this list.

Implements moab::TagInfo.

Definition at line 462 of file SparseTag.cpp.

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

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

{
  ErrorCode rval;
  for (size_t i = 0; i < num_entities; ++i)
    if (MB_SUCCESS != (rval = remove_data(error, entities[i])))
      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 343 of file SparseTag.cpp.

{
  for (Range::const_iterator i = entities.begin(); i != entities.end(); ++i)
    if (MB_SUCCESS != remove_data(error,*i))
      return MB_TAG_NOT_FOUND;
  return MB_SUCCESS;
}
ErrorCode moab::SparseTag::remove_data ( Error error,
EntityHandle  entity_handle 
) [inline, private]

removes the data

Definition at line 124 of file SparseTag.cpp.

{
  MapType::iterator i = mData.find(entity_handle);
  if (i == mData.end()) 
    return not_found(error, get_name(), entity_handle);
  
  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 215 of file SparseTag.cpp.

{
  ErrorCode rval = seqman->check_valid_entities( error, entities, num_entities, true );
  if (MB_SUCCESS != rval)
    return rval;

  const unsigned char* ptr = reinterpret_cast<const unsigned char*>(data);
  for (size_t i = 0; i < num_entities; ++i, ptr += get_size())
    if (MB_SUCCESS != (rval = set_data(error, entities[i], ptr)))
      return 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 232 of file SparseTag.cpp.

{
  ErrorCode rval = seqman->check_valid_entities( error, entities );
  if (MB_SUCCESS != rval)
    return 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(error, *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 249 of file SparseTag.cpp.

{
  ErrorCode rval = validate_lengths( error, lengths, num_entities );
  if (MB_SUCCESS != rval)
    return rval;
    
  rval = seqman->check_valid_entities( error, entities, num_entities, true );
  if (MB_SUCCESS != rval)
    return rval;
  
  for (size_t i = 0; i < num_entities; ++i, ++pointers)
    if (MB_SUCCESS != (rval = set_data(error, entities[i], *pointers)))
      return 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 270 of file SparseTag.cpp.

{
  ErrorCode rval = validate_lengths( error, lengths, entities.size() );
  if (MB_SUCCESS != rval)
    return rval;
    
  rval = seqman->check_valid_entities( error, entities );
  if (MB_SUCCESS != rval)
    return rval;
  
  Range::const_iterator i;
  for (i = entities.begin(); i != entities.end(); ++i, ++pointers)
    if (MB_SUCCESS != (rval = set_data(error, *i, *pointers)))
      return 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 71 of file SparseTag.cpp.

{
#ifdef 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 353 of file SparseTag.cpp.

{
    // 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 contigous, 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( error, &*iter, 1 );
  if (MB_SUCCESS != rval) 
    return 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());
  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( error, get_name(), *iter );;
  }
  
    // increment iterator and return
  ++iter;
  return MB_SUCCESS;
}

Member Data Documentation

allocator for this collection

Definition at line 447 of file SparseTag.hpp.

Definition at line 449 of file SparseTag.hpp.


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