moab
moab::SparseTagSuperCollection Class Reference

a collection of SparseTagCollections More...

#include <SparseTagSuperCollection.hpp>

List of all members.

Public Member Functions

 SparseTagSuperCollection ()
 constructor
virtual ~SparseTagSuperCollection ()
 destructor
void reset_data ()
ErrorCode reserve_tag_id (int data_size, TagId tag_id)
 allocate new tag id
ErrorCode release_tag_id (TagId tag_id)
 releases an TagId
int tag_size (const TagId tag_id) const
 size of data tag
ErrorCode set_data (TagId tag_handle, const EntityHandle *handles, int num_handles, const void *data)
ErrorCode set_data (TagId tag_handle, const EntityHandle *handles, int num_handles, void const *const *data_pointers, const int *lengths=0, bool one_value=false)
ErrorCode set_data (TagId tag_handle, const Range &handles, const void *data)
ErrorCode set_data (TagId tag_handle, const Range &handles, void const *const *data_pointers, const int *lengths=0, bool one_value=false)
ErrorCode tag_iterate (TagId tag_handle, Range::iterator &iter, const Range::iterator &end, void *&data_ptr, const void *default_value)
 Access tag data via direct pointer into contiguous blocks.
ErrorCode get_data (TagId tag_handle, const EntityHandle *handles, int num_handles, void *data, const void *default_value) const
ErrorCode get_data (TagId tag_handle, const EntityHandle *handles, int num_handles, const void **data, int *lengths, const void *default_value, int default_value_length) const
ErrorCode get_data (TagId tag_handle, const Range &handles, void *data, const void *default_value) const
ErrorCode get_data (TagId tag_handle, const Range &handles, const void **data, int *lengths, const void *default_value, int default_value_length) const
ErrorCode remove_data (const TagId tag_handle, const EntityHandle entity_handle)
 removes data
ErrorCode get_entities (const TagId tag_handle, Range &entities)
 gets all entity handles that match a type and tag
ErrorCode get_entities (const TagId tag_handle, const EntityType type, Range &entities)
 gets all entity handles that match a tag
ErrorCode get_entities (const Range &range, const TagId tag_handle, const EntityType type, Range &entities)
 gets all entity handles that match a tag
ErrorCode get_tags (const EntityHandle entity, std::vector< Tag > &all_tags)
 gets all tags on a given entity handle
ErrorCode get_entities_with_tag_value (const TagId tag_handle, const TagInfo &tag_info, const EntityType type, Range &entities, const void *tag_value, int value_size)
 gets all entity handles that match a tag
ErrorCode get_entities_with_tag_value (const Range &range, const TagId tag_handle, const TagInfo &tag_info, const EntityType type, Range &entities, const void *tag_value, int value_size)
 gets all entity handles that match a tag
ErrorCode get_number_entities (const TagId tag_handle, const EntityType type, int &num_ent)
 gets the number of entities that match a tag
ErrorCode get_number_entities (const Range &range, const TagId tag_handle, const EntityType type, int &num_ent)
 gets the number of entities that match a tag
ErrorCode get_memory_use (TagId tag_id, unsigned long &total, unsigned long &per_entity)

Private Attributes

std::vector
< SparseTagCollection * > 
mDataTags

Detailed Description

a collection of SparseTagCollections

Definition at line 57 of file SparseTagSuperCollection.hpp.


Constructor & Destructor Documentation

constructor

Definition at line 61 of file SparseTagSuperCollection.hpp.

{}

destructor

Definition at line 43 of file SparseTagSuperCollection.cpp.

{
  std::vector<SparseTagCollection*>::iterator tag_iterator;
  for(tag_iterator = mDataTags.begin(); tag_iterator != mDataTags.end(); ++tag_iterator)
    delete *tag_iterator;
  mDataTags.clear();
}

Member Function Documentation

ErrorCode moab::SparseTagSuperCollection::get_data ( TagId  tag_handle,
const EntityHandle handles,
int  num_handles,
void *  data,
const void *  default_value 
) const

Get fixed-length tag values for array of entities Will fail with MB_VARIABLE_DATA_LENGTH if called for variable-length tag.

Definition at line 269 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
    
  const int length = coll->tag_size();
  if (length == MB_VARIABLE_LENGTH)
    return MB_VARIABLE_DATA_LENGTH;

  ErrorCode rval;
  unsigned char* ptr = reinterpret_cast<unsigned char*>(data);
  const EntityHandle *const end = handles + num_handles;
  for (const EntityHandle* i = handles; i != end; ++i, ptr += length) {
    rval = coll->get_data( *i, ptr );
    if (MB_SUCCESS != rval) {
      if (MB_TAG_NOT_FOUND == rval && default_value) 
        memcpy( ptr, default_value, length );
      else
        return rval;
    }
  }
    
  return MB_SUCCESS;
}
ErrorCode moab::SparseTagSuperCollection::get_data ( TagId  tag_handle,
const EntityHandle handles,
int  num_handles,
const void **  data,
int *  lengths,
const void *  default_value,
int  default_value_length 
) const

Get pointers to tag data for array of entities

Parameters:
tag_idThe Tag.
handlesArray of entity handles.
num_handlesLength of 'handles' array.
tag_ptrsPointers to tag values, one pointer for each input handle.
lengthsLength of each tag value. Ignored for fixed-length tags.
default_valuePointer to default value for tag, or NULL if none.
default_value_lengthLength of default tag value. Ingored for fixed-length tags.

Definition at line 299 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
  
  int junk_length;
  int length_step = 1;
  const int length = coll->tag_size();
  if (!lengths) {
    if (length == MB_VARIABLE_LENGTH)
      return MB_VARIABLE_DATA_LENGTH;
    lengths = &junk_length;
    length_step = 0;
  }
  
  
  ErrorCode rval, result = MB_SUCCESS;
  const EntityHandle *const end = handles + num_handles;
  for (const EntityHandle* i = handles; i != end; ++i, ++data, lengths += length_step) {
    void* ptr;
    rval = coll->get_data( *i, ptr, *lengths );
    if (MB_SUCCESS == rval)
      *data = ptr;
    else if (MB_TAG_NOT_FOUND == rval && default_value) {
      *data = default_value;
      *lengths = default_val_length;
    }
    else {
      *data = 0;
      *lengths = 0;
      result = rval;
    }
  }
    
  return result;
}
ErrorCode moab::SparseTagSuperCollection::get_data ( TagId  tag_handle,
const Range handles,
void *  data,
const void *  default_value 
) const

Get fixed-length tag value for an Range of entities Will fail with MB_VARIABLE_DATA_LENGTH if called for variable-length tag.

Definition at line 344 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
    
  const int length = coll->tag_size();
  if (length == MB_VARIABLE_LENGTH)
    return MB_VARIABLE_DATA_LENGTH;

  ErrorCode rval;
  unsigned char* ptr = reinterpret_cast<unsigned char*>(data);
  for (Range::const_iterator i = handles.begin(); i != handles.end(); ++i, ptr += length) {
    rval = coll->get_data( *i, ptr );
    if (MB_SUCCESS != rval) {
      if (MB_TAG_NOT_FOUND == rval && default_value) 
        memcpy( ptr, default_value, length );
      else
        return rval;
    }
  }
    
  return MB_SUCCESS;
}
ErrorCode moab::SparseTagSuperCollection::get_data ( TagId  tag_handle,
const Range handles,
const void **  data,
int *  lengths,
const void *  default_value,
int  default_value_length 
) const

Get pointers to tag data for an Range of entities.

Parameters:
tag_idThe tag.
handlesThe entities.
valuesArray of pointers of type 'const void*'. Array must be the same length as the size of 'entities'. The array will be populated with pointers to the internal storage of the tag data for each entity.
lengthsArray of integers. Will be populated with the length of the tag value for each entity. Argument is optional for fixed-length tags.
default_valueThe default value for the tag.
default_value_lengthThe length of the default tag value.

Definition at line 372 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
  
  int junk_length;
  int length_step = 1;
  const int length = coll->tag_size();
  if (!lengths) {
    if (length == MB_VARIABLE_LENGTH)
      return MB_VARIABLE_DATA_LENGTH;
    lengths = &junk_length;
    length_step = 0;
  }
  
  
  ErrorCode rval, result = MB_SUCCESS;
  for (Range::const_iterator i = handles.begin(); i != handles.end(); ++i, ++data, lengths += length_step) {
    void* ptr;
    rval = coll->get_data( *i, ptr, *lengths );
    if (MB_SUCCESS == rval) {
      *data = ptr;
    }
    else if (MB_TAG_NOT_FOUND == rval && default_value) {
      *data = default_value;
      *lengths = default_val_length;
    }
    else {
      *data = 0;
      *lengths = 0;
      result = rval;
    }
  }
    
  return result;
}
ErrorCode moab::SparseTagSuperCollection::get_entities ( const TagId  tag_handle,
Range entities 
)

gets all entity handles that match a type and tag

Definition at line 424 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  return coll ? coll->get_entities(entities) : MB_TAG_NOT_FOUND;
}
ErrorCode moab::SparseTagSuperCollection::get_entities ( const TagId  tag_handle,
const EntityType  type,
Range entities 
)

gets all entity handles that match a tag

gets all entity handles that match a type and tag

Definition at line 432 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  return coll ? coll->get_entities(type, entities) : MB_TAG_NOT_FOUND;
}
ErrorCode moab::SparseTagSuperCollection::get_entities ( const Range range,
const TagId  tag_handle,
const EntityType  type,
Range entities 
)

gets all entity handles that match a tag

gets all entity handles that match a type and tag

Definition at line 440 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
  
  Range dum_range;
  ErrorCode result = coll->get_entities(type, dum_range);

  std::set_intersection(dum_range.begin(), dum_range.end(),
                        range.begin(), range.end(),
                        range_inserter(entities));
  
  return result;
}
ErrorCode moab::SparseTagSuperCollection::get_entities_with_tag_value ( const TagId  tag_handle,
const TagInfo tag_info,
const EntityType  type,
Range entities,
const void *  tag_value,
int  value_size 
)

gets all entity handles that match a tag

gets all entity handles that match a type and tag

Definition at line 469 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
  
  return coll->get_entities_with_tag_value(tag_info, type, entities, tag_value, value_size);
}
ErrorCode moab::SparseTagSuperCollection::get_entities_with_tag_value ( const Range range,
const TagId  tag_handle,
const TagInfo tag_info,
const EntityType  type,
Range entities,
const void *  tag_value,
int  value_size 
)

gets all entity handles that match a tag

gets all entity handles that match a type and tag

Definition at line 485 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;

  Range dum_range;
  ErrorCode result = coll->get_entities_with_tag_value(
                           tag_info, type, dum_range, tag_value, value_size);

    // do this the hard way to preserve order in the vector
  std::set_intersection(range.begin(), range.end(),
                        dum_range.begin(), dum_range.end(),
                        range_inserter(entities));
  
  return result;
}
ErrorCode moab::SparseTagSuperCollection::get_memory_use ( TagId  tag_id,
unsigned long &  total,
unsigned long &  per_entity 
)

Definition at line 530 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_id);
  if (!coll)
    return MB_TAG_NOT_FOUND;

    // 3*sizeof(void*)                      - std::map RB tree node
    // sizeof(void*)*sizeof(EntityHandle) - data in std::map node
    // coll->tag_size()                     - the actual tag data
  per_entity = 4*sizeof(void*)+sizeof(EntityHandle)+coll->tag_size();
    
    // Count number of occupied slots in mDataTags vector
  unsigned num_coll =0;
  for (unsigned i = 0; i < mDataTags.size(); ++i)
    if (mDataTags[i])
      ++num_coll;

    // amortized space in mDataTags vector
  total = sizeof(SparseTagCollection*) * mDataTags.capacity() / num_coll;
    // SparseTagCollection object for this tag
  total += sizeof(SparseTagCollection);
    // Per-entity data in SparseTagCollection
  total += per_entity * coll->get_number_entities();
  return MB_SUCCESS;
}
ErrorCode moab::SparseTagSuperCollection::get_number_entities ( const TagId  tag_handle,
const EntityType  type,
int &  num_ent 
)

gets the number of entities that match a tag

gets all entity handles that match a type and tag

Definition at line 511 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  return coll ? coll->get_number_entities( type, num_entities ) : MB_TAG_NOT_FOUND;
}
ErrorCode moab::SparseTagSuperCollection::get_number_entities ( const Range range,
const TagId  tag_handle,
const EntityType  type,
int &  num_ent 
)

gets the number of entities that match a tag

gets all entity handles that match a type and tag

Definition at line 519 of file SparseTagSuperCollection.cpp.

{
  Range dum_range;
  ErrorCode result = get_entities(range, tag_handle, type, dum_range);
  num_entities = dum_range.size();
  return result;
}
ErrorCode moab::SparseTagSuperCollection::get_tags ( const EntityHandle  entity,
std::vector< Tag > &  all_tags 
)

gets all tags on a given entity handle

Definition at line 458 of file SparseTagSuperCollection.cpp.

{
  for (TagId id = 0; id < mDataTags.size(); ++id)
    if (mDataTags[id] && mDataTags[id]->contains(entity))
      all_tags.push_back( TAG_HANDLE_FROM_ID( id, MB_TAG_SPARSE ) );
  
  return MB_SUCCESS;
}

releases an TagId

Definition at line 80 of file SparseTagSuperCollection.cpp.

{
  if (tag_id >= mDataTags.size() || !mDataTags[tag_id])
    return MB_TAG_NOT_FOUND;
  
  delete mDataTags[tag_id];
  mDataTags[tag_id] = 0;
  return MB_SUCCESS;
}
ErrorCode moab::SparseTagSuperCollection::remove_data ( const TagId  tag_handle,
const EntityHandle  entity_handle 
)

removes data

Definition at line 415 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  return coll ? coll->remove_data( entity_handle ) : MB_TAG_NOT_FOUND;
}
ErrorCode moab::SparseTagSuperCollection::reserve_tag_id ( int  data_size,
TagId  tag_id 
)

allocate new tag id

Definition at line 65 of file SparseTagSuperCollection.cpp.

{
  if(data_size<=0 && data_size != MB_VARIABLE_LENGTH)
    return MB_FAILURE;

  if (tag_id >= mDataTags.size())
    mDataTags.resize( tag_id+1, 0 );
    
  if (mDataTags[tag_id])
    return MB_FAILURE;
    
  mDataTags[tag_id] = new SparseTagCollection(data_size);
  return MB_SUCCESS;
}

Definition at line 51 of file SparseTagSuperCollection.cpp.

{
  std::vector<SparseTagCollection*>::iterator tag_iterator;
  for(tag_iterator = mDataTags.begin(); tag_iterator != mDataTags.end(); ++tag_iterator)
  {
    if (*tag_iterator) {
      int data_size = (*tag_iterator)->tag_size();
      delete *tag_iterator;
      *tag_iterator = new SparseTagCollection(data_size);
    }
  }
  
}
ErrorCode moab::SparseTagSuperCollection::set_data ( TagId  tag_handle,
const EntityHandle handles,
int  num_handles,
const void *  data 
)

Set fixed-length tag values. Will fail for variable-length tag data.

Definition at line 97 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
    
  const int length = coll->tag_size();
  if (length == MB_VARIABLE_LENGTH)
    return MB_VARIABLE_DATA_LENGTH;

  ErrorCode rval, result = MB_SUCCESS;
  const unsigned char* ptr = reinterpret_cast<const unsigned char*>(data);
  const EntityHandle *const end = handles + num_handles;
  for (const EntityHandle* i = handles; i != end; ++i, ptr += length) {
    rval = coll->set_data( *i, ptr );
    if (MB_SUCCESS != rval)
      result = rval;
  }
    
  return result;
}
ErrorCode moab::SparseTagSuperCollection::set_data ( TagId  tag_handle,
const EntityHandle handles,
int  num_handles,
void const *const *  data_pointers,
const int *  lengths = 0,
bool  one_value = false 
)

Set tag values for array of entity handles

Parameters:
tag_idThe tag.
handlesArray of entity handles.
num_handlesLength of 'handles' array.
valuesArray of pointers to tag values, one pointer for each handle
lengthsLength of each tag value. Ignored for fixed-length tags.
one_valueIf true, tag on all entities is set to the (same) first passed tag value.

Definition at line 122 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
  
  const bool step = !one_value;
  const int length = coll->tag_size();
  int length_step;
  if (length == MB_VARIABLE_LENGTH) {
    if (!lengths)
      return MB_VARIABLE_DATA_LENGTH;
    length_step = step;
  }
  else {
    lengths = &length;
    length_step = 0;
  }

  ErrorCode rval, result = MB_SUCCESS;
  const EntityHandle *const end = handles + num_handles;
  void const* const* ptr = data_ptrs;
  for (const EntityHandle* i = handles; i != end; ++i, ptr += step, lengths += length_step) {
    rval = coll->set_data( *i, *ptr, *lengths );
    if (MB_SUCCESS != rval)
      result = rval;
  }
    
  return result;
}
ErrorCode moab::SparseTagSuperCollection::set_data ( TagId  tag_handle,
const Range handles,
const void *  data 
)

Set fixed-length tag value for an Range of entities Will fail for variable-length tag data

Definition at line 159 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
    
  const int length = coll->tag_size();
  if (length == MB_VARIABLE_LENGTH)
    return MB_VARIABLE_DATA_LENGTH;

  ErrorCode rval, result = MB_SUCCESS;
  const unsigned char* ptr = reinterpret_cast<const unsigned char*>(data);
  for (Range::const_iterator i = handles.begin(); i != handles.end(); ++i, ptr += length) {
    rval = coll->set_data( *i, ptr );
    if (MB_SUCCESS != rval)
      result = rval;
  }
    
  return result;
}
ErrorCode moab::SparseTagSuperCollection::set_data ( TagId  tag_handle,
const Range handles,
void const *const *  data_pointers,
const int *  lengths = 0,
bool  one_value = false 
)

Set tag data for an Range of entities.

Parameters:
tag_idThe tag
handlesThe entities
valuesAn array of pointers, one per entity, pointing to the tag value for the corresponding entity.
lengthsAn array of integers, one per entity, indicating the length of the tag value for each entity. Ingored for fixed-length tags.
one_valueIf true, tag on all entities is set to the (same) first passed tag value.

Definition at line 182 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
  
  const bool step = !one_value;
  const int length = coll->tag_size();
  int length_step;
  if (length == MB_VARIABLE_LENGTH) {
    if (!lengths)
      return MB_VARIABLE_DATA_LENGTH;
    length_step = step;
  }
  else {
    lengths = &length;
    length_step = 0;
  }

  ErrorCode rval, result = MB_SUCCESS;
  void const* const* ptr = data_ptrs;
  for (Range::const_iterator i = handles.begin(); i != handles.end(); ++i, ptr += step, lengths += length_step) {
    rval = coll->set_data( *i, *ptr, *lengths );
    if (MB_SUCCESS != rval)
      result = rval;
  }
    
  return result;
}
ErrorCode moab::SparseTagSuperCollection::tag_iterate ( TagId  tag_handle,
Range::iterator iter,
const Range::iterator end,
void *&  data_ptr,
const void *  default_value 
)

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:
tag_handleThe handle of the tag for which to access data
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.

Definition at line 216 of file SparseTagSuperCollection.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;

  SparseTagCollection* coll = get_collection(tag_handle);
  if (!coll)
    return MB_TAG_NOT_FOUND;
    
    // not supported for variable-length tags
  const int length = coll->tag_size();
  if (length == MB_VARIABLE_LENGTH)
    return MB_VARIABLE_DATA_LENGTH;

    // get pointer to tag storage for entity pointed to by iter
  int junk;
  ErrorCode rval = coll->get_data( *iter, data_ptr_out, junk );
  if (MB_SUCCESS != rval) {
      // if no tag value but default_value, then set tag to
      // default_value and return the new tag storage.  Note:
      // it is not sufficient to return the passed default_value
      // pointer because we are returning an non-const pointer that
      // could be modified by the caller.
    if (MB_TAG_NOT_FOUND == rval && default_value) {
      rval = coll->set_data( *iter, default_value );
      if (MB_SUCCESS != rval)
        return rval;
      rval = coll->get_data( *iter, data_ptr_out, junk );
      if (MB_SUCCESS != rval)
        return rval;
    }
    else {
      return rval;
    }
  }
    
    // increment iterator and return
  ++iter;
  return MB_SUCCESS;
}
int moab::SparseTagSuperCollection::tag_size ( const TagId  tag_id) const

size of data tag

Definition at line 90 of file SparseTagSuperCollection.cpp.

{
  SparseTagCollection* coll = get_collection(tag_id);
  return coll ? coll->tag_size() : 0;
}

Member Data Documentation

std::vector<SparseTagCollection*> moab::SparseTagSuperCollection::mDataTags [private]

Definition at line 263 of file SparseTagSuperCollection.hpp.


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