moab
|
a collection of SparseTagCollections More...
#include <SparseTagSuperCollection.hpp>
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 |
a collection of SparseTagCollections
Definition at line 57 of file SparseTagSuperCollection.hpp.
destructor
Definition at line 43 of file SparseTagSuperCollection.cpp.
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
tag_id | The Tag. |
handles | Array of entity handles. |
num_handles | Length of 'handles' array. |
tag_ptrs | Pointers to tag values, one pointer for each input handle. |
lengths | Length of each tag value. Ignored for fixed-length tags. |
default_value | Pointer to default value for tag, or NULL if none. |
default_value_length | Length 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.
tag_id | The tag. |
handles | The entities. |
values | Array 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. |
lengths | Array of integers. Will be populated with the length of the tag value for each entity. Argument is optional for fixed-length tags. |
default_value | The default value for the tag. |
default_value_length | The 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; }
ErrorCode moab::SparseTagSuperCollection::release_tag_id | ( | TagId | tag_id | ) |
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.
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
tag_id | The tag. |
handles | Array of entity handles. |
num_handles | Length of 'handles' array. |
values | Array of pointers to tag values, one pointer for each handle |
lengths | Length of each tag value. Ignored for fixed-length tags. |
one_value | If 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.
tag_id | The tag |
handles | The entities |
values | An array of pointers, one per entity, pointing to the tag value for the corresponding entity. |
lengths | An array of integers, one per entity, indicating the length of the tag value for each entity. Ingored for fixed-length tags. |
one_value | If 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.
tag_handle | The handle of the tag for which to access data |
iter | As input, the first entity for which to return data. As output, one past the last entity for which data was returned. |
end | One past the last entity for which data is desired |
data_ptr | Output: 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; }
std::vector<SparseTagCollection*> moab::SparseTagSuperCollection::mDataTags [private] |
Definition at line 263 of file SparseTagSuperCollection.hpp.