moab
moab::VarLenSparseTag Class Reference

Sparse tag variable-length data. More...

#include <VarLenSparseTag.hpp>

Inheritance diagram for moab::VarLenSparseTag:
moab::TagInfo

List of all members.

Public Types

typedef std::map< EntityHandle,
VarLenTag
MapType
 map of entity id and tag data

Public Member Functions

 VarLenSparseTag (const char *name, DataType type, const void *default_value, int default_value_bytes)
 ~VarLenSparseTag ()
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

 VarLenSparseTag (const VarLenSparseTag &)
VarLenSparseTagoperator= (const VarLenSparseTag &)
ErrorCode get_data_ptr (Error *error_handler, EntityHandle entity_handle, const void *&data, int &size) const
 get the variable-length data for an entity id

Private Attributes

MapType mData

Detailed Description

Sparse tag variable-length data.

Definition at line 45 of file VarLenSparseTag.hpp.


Member Typedef Documentation

map of entity id and tag data

Definition at line 400 of file VarLenSparseTag.hpp.


Constructor & Destructor Documentation

moab::VarLenSparseTag::VarLenSparseTag ( const char *  name,
DataType  type,
const void *  default_value,
int  default_value_bytes 
)

Definition at line 48 of file VarLenSparseTag.cpp.

  : TagInfo( name, MB_VARIABLE_LENGTH, type, default_value, default_value_bytes )
  { }

Definition at line 55 of file VarLenSparseTag.cpp.

  { release_all_data(0,0,true); }

Member Function Documentation

ErrorCode moab::VarLenSparseTag::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 214 of file VarLenSparseTag.cpp.

{
  if (0 == value_len) {
    remove_data( seqman, 0, entities, num_entities );
    return MB_SUCCESS;
  }

  ErrorCode rval = validate_lengths( error, &value_len, 1 );
  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)
    mData[entities[i]].set( value_ptr, value_len );
  return MB_SUCCESS;
}
ErrorCode moab::VarLenSparseTag::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 239 of file VarLenSparseTag.cpp.

{
  if (0 == value_len) {
    remove_data( seqman, 0, entities );
    return MB_SUCCESS;
  }

  ErrorCode rval = validate_lengths( error, &value_len, 1 );
  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)
    mData[*i].set( value_ptr, value_len );

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

{
  if (value_bytes && value_bytes != get_size())
    return MB_INVALID_SIZE;
  
  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_varlen_values_equal( *this, value, get_size(), 
                                  r.first, r.second,
                                  mData, output_entities );
  }
  else if (type == MBMAXTYPE) {
    find_tag_varlen_values_equal( *this, value, get_size(), 
                                  mData.begin(), mData.end(), 
                                  output_entities );
  }
  else {
    Range tmp;
    seqman->get_entities( type, tmp );
    find_map_varlen_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_varlen_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_varlen_values_equal( *this, value, get_size(), iter, end, 
                                  output_entities);
  }
#endif
  
  return MB_SUCCESS;
}
ErrorCode moab::VarLenSparseTag::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 88 of file VarLenSparseTag.cpp.

{
  return not_var_len(error, get_name());
}
ErrorCode moab::VarLenSparseTag::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 97 of file VarLenSparseTag.cpp.

{
  return not_var_len(error, get_name());
}
ErrorCode moab::VarLenSparseTag::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 105 of file VarLenSparseTag.cpp.

{
  if (!lengths)
    return not_var_len(error, get_name());

  ErrorCode rval;
  for (size_t i = 0; i < num_entities; ++i)
    if (MB_SUCCESS != (rval = get_data_ptr(error, entities[i], pointers[i], lengths[i])))
      return rval;
  return MB_SUCCESS;
}
ErrorCode moab::VarLenSparseTag::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 122 of file VarLenSparseTag.cpp.

{
  if (!lengths)
    return not_var_len(error, get_name());

  ErrorCode rval;
  Range::const_iterator i;
  for (i = entities.begin(); i != entities.end(); ++i, ++pointers, ++lengths)
    if (MB_SUCCESS != (rval = get_data_ptr(error, *i, *pointers, *lengths)))
      return rval;
  return MB_SUCCESS;
}
ErrorCode moab::VarLenSparseTag::get_data_ptr ( Error error_handler,
EntityHandle  entity_handle,
const void *&  data,
int &  size 
) const [inline, private]

get the variable-length data for an entity id

Definition at line 67 of file VarLenSparseTag.cpp.

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

  if (iter != mData.end()) {
    ptr = iter->second.data();
    length = iter->second.size();
  }
  else if (get_default_value()) {
    ptr = get_default_value();
    length = get_default_value_size();
  }
  else 
    return not_found(error, get_name(), entity_handle);
  
  return MB_SUCCESS;
}
ErrorCode moab::VarLenSparseTag::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 463 of file VarLenSparseTag.cpp.

{
  total = mData.size() * (3*sizeof(void*) + sizeof(VarLenTag));
  for (MapType::const_iterator i = mData.begin(); i != mData.end(); ++i)
    total += i->second.mem();
  if (mData.size())
    per_entity = total / mData.size();
  total += sizeof(*this) + TagInfo::get_memory_use();
      
  return MB_SUCCESS;
}
unsigned long moab::VarLenSparseTag::get_number_entities ( ) [inline]

get number of entities

Definition at line 392 of file VarLenSparseTag.hpp.

    { return mData.size(); }

Implements moab::TagInfo.

Definition at line 58 of file VarLenSparseTag.cpp.

  { return MB_TAG_SPARSE; }
ErrorCode moab::VarLenSparseTag::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 369 of file VarLenSparseTag.cpp.

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

Check if entity is tagged.

Implements moab::TagInfo.

Definition at line 458 of file VarLenSparseTag.cpp.

{
  return mData.find(h) != mData.end();
}
ErrorCode moab::VarLenSparseTag::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 379 of file VarLenSparseTag.cpp.

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

{
  mData.clear();
  return MB_SUCCESS;
}
ErrorCode moab::VarLenSparseTag::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 265 of file VarLenSparseTag.cpp.

{
  ErrorCode result = MB_SUCCESS;
  for (size_t i = 0; i < num_entities; ++i) {
    MapType::iterator p = mData.find(entities[i]);
    if (p == mData.end())
      result = not_found(error, get_name(), entities[i]);
    else {
      p->second.clear();
      mData.erase(p);
    }
  }
  return result;
}
ErrorCode moab::VarLenSparseTag::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 283 of file VarLenSparseTag.cpp.

{
  ErrorCode result = MB_SUCCESS;
  for (Range::iterator i = entities.begin(); i != entities.end(); ++i) {
    MapType::iterator p = mData.find(*i);
    if (p == mData.end())
      result = not_found(error, get_name(), *i);
    else {
      p->second.clear();
      mData.erase(p);
    }
  }
  return result;
}
ErrorCode moab::VarLenSparseTag::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 139 of file VarLenSparseTag.cpp.

{
  return not_var_len(error, get_name());
}
ErrorCode moab::VarLenSparseTag::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 148 of file VarLenSparseTag.cpp.

{
  return not_var_len(error, get_name());
}
ErrorCode moab::VarLenSparseTag::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 156 of file VarLenSparseTag.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) {
    if (lengths[i])
      mData[entities[i]].set( pointers[i], lengths[i] );
    else {
      MapType::iterator iter = mData.find(entities[i]);
      if (iter != mData.end()) {
        iter->second.clear();
        mData.erase(iter);
      }
    }
  }
  return MB_SUCCESS;
}
ErrorCode moab::VarLenSparseTag::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 185 of file VarLenSparseTag.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, ++lengths) {
    if (*lengths)
      mData[*i].set( *pointers, *lengths );
    else {
      MapType::iterator iter = mData.find(*i);
      if (iter != mData.end()) {
        iter->second.clear();
        mData.erase(iter);
      }
    }
  }
  return MB_SUCCESS;
}
ErrorCode moab::VarLenSparseTag::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 300 of file VarLenSparseTag.cpp.

{
  error->set_last_error( "Cannot iterate over variable-length tag data" );
  return MB_VARIABLE_DATA_LENGTH;
}

Member Data Documentation

Definition at line 415 of file VarLenSparseTag.hpp.


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