Mesh Oriented datABase  (version 5.6.0)
An array-based unstructured mesh library
moab::SparseTag Class Reference

Sparse tag data. More...

#include <SparseTag.hpp>

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

Public Types

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

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. More...
 
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. More...
 
virtual ErrorCode get_data (const SequenceManager *seqman, Error *error_handler, const Range &entities, void *data) const
 Get tag value for passed entities. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual ErrorCode set_data (SequenceManager *seqman, Error *error_handler, const Range &entities, const void *data)
 Set tag value for passed entities. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual ErrorCode remove_data (SequenceManager *seqman, Error *error_handler, const EntityHandle *entities, size_t num_entities)
 Remove/clear tag data for entities. More...
 
virtual ErrorCode remove_data (SequenceManager *seqman, Error *error_handler, const Range &entities)
 Remove/clear tag data for entities. More...
 
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. More...
 
virtual ErrorCode get_tagged_entities (const SequenceManager *seqman, Range &output_entities, EntityType type=MBMAXTYPE, const Range *intersect=0) const
 Get all tagged entities. More...
 
virtual ErrorCode num_tagged_entities (const SequenceManager *seqman, size_t &output_count, EntityType type=MBMAXTYPE, const Range *intersect=0) const
 Count all tagged entities. More...
 
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. More...
 
virtual bool is_tagged (const SequenceManager *, EntityHandle h) const
 Check if entity is tagged. More...
 
virtual ErrorCode get_memory_use (const SequenceManager *seqman, unsigned long &total, unsigned long &per_entity) const
 Get memory use for tag data. More...
 
unsigned long get_number_entities ()
 get number of entities More...
 
- Public Member Functions inherited from moab::TagInfo
 TagInfo ()
 constructor More...
 
 TagInfo (const char *name, int size, DataType type, const void *default_value, int default_value_size)
 constructor that takes all parameters More...
 
virtual ~TagInfo ()
 
void set_name (const std::string &name)
 set the name of the tag More...
 
const std::string & get_name () const
 get the name of the tag More...
 
int get_default_value_size () const
 get length of default value More...
 
const void * get_default_value () const
 get the default data More...
 
bool equals_default_value (const void *data, int size=-1) const
 compare the passed value to the default value. returns false if no default value. More...
 
DataType get_data_type () const
 
int get_size () const
 get the size of the data in bytes More...
 
bool variable_length () const
 Check if variable-length tag. More...
 
bool check_valid_sizes (const int *sizes, int num_sizes) const
 
ErrorCode validate_lengths (Error *error_handler, const int *lengths, size_t num_lengths) const
 

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) More...
 
ErrorCode set_data (Error *, EntityHandle entity_handle, const void *data)
 set the tag data for an entity id More...
 
ErrorCode get_data (Error *, EntityHandle entity_handle, void *data) const
 get the tag data for an entity id More...
 
ErrorCode get_data_ptr (EntityHandle entity_handle, const void *&data, bool allocate=true) const
 get the variable-length data for an entity id More...
 
ErrorCode remove_data (Error *, EntityHandle entity_handle)
 removes the data More...
 

Private Attributes

SparseTagDataAllocator mAllocator
 allocator for this collection More...
 
MapType mData
 

Additional Inherited Members

- Static Public Member Functions inherited from moab::TagInfo
static int size_from_data_type (DataType t)
 
- Protected Member Functions inherited from moab::TagInfo
unsigned long get_memory_use () const
 

Detailed Description

Sparse tag data.

Definition at line 64 of file SparseTag.hpp.

Member Typedef Documentation

◆ MapType

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

map of entity id and tag data

Definition at line 393 of file SparseTag.hpp.

Constructor & Destructor Documentation

◆ SparseTag() [1/2]

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

Definition at line 31 of file SparseTag.cpp.

32  : TagInfo( name, size, type, default_value, size )
33 {
34 }

◆ ~SparseTag()

moab::SparseTag::~SparseTag ( )

Definition at line 36 of file SparseTag.cpp.

37 {
38  release_all_data( 0, 0, true );
39 }

References release_all_data().

◆ SparseTag() [2/2]

moab::SparseTag::SparseTag ( const SparseTag )
private

Member Function Documentation

◆ allocate_data()

void * moab::SparseTag::allocate_data ( EntityHandle  h,
MapType::const_iterator  iter,
bool  copy_default = true 
)
inlineprivate

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

Definition at line 427 of file SparseTag.hpp.

434 {
435  void* new_data = mAllocator.allocate( get_size() );
436 #ifdef MOAB_HAVE_UNORDERED_MAP
437  mData.insert( iter, std::pair< const EntityHandle, void* >( h, new_data ) );
438 #else
439  mData[h] = new_data;
440 #endif
441  if( copy_default ) memcpy( new_data, get_default_value(), get_size() );
442  return new_data;
443 }

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

Referenced by get_data_ptr(), set_data(), and tag_iterate().

◆ clear_data() [1/2]

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

264 {
265  if( value_len && value_len != get_size() )
266  {
267  MB_SET_ERR( MB_INVALID_SIZE, "Invalid data size " << get_size() << " specified for sparse tag " << get_name()
268  << " of size " << value_len );
269  }
270 
271  MB_CHK_ERR( seqman->check_valid_entities( NULL, entities, num_entities, true ) );
272 
273  for( size_t i = 0; i < num_entities; ++i )
274  MB_CHK_ERR( set_data( NULL, entities[i], value_ptr ) );
275 
276  return MB_SUCCESS;
277 }

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

◆ clear_data() [2/2]

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

284 {
285  if( value_len && value_len != get_size() )
286  {
287  MB_SET_ERR( MB_INVALID_SIZE, "Invalid data size " << get_size() << " specified for sparse tag " << get_name()
288  << " of size " << value_len );
289  }
290 
291  MB_CHK_ERR( seqman->check_valid_entities( NULL, entities ) );
292 
293  Range::const_iterator i;
294  for( i = entities.begin(); i != entities.end(); ++i )
295  {
296  MB_CHK_ERR( set_data( NULL, *i, value_ptr ) );
297  }
298 
299  return MB_SUCCESS;
300 }

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

◆ find_entities_with_value()

ErrorCode moab::SparseTag::find_entities_with_value ( const SequenceManager seqman,
Error error_handler,
Range output_entities,
const void *  value,
int  value_bytes = 0,
EntityType  type = MBMAXTYPE,
const Range intersect_entities = 0 
) const
virtual

Get all tagged entities with tag value.

Get the list of entities which have the specified tag value.

Parameters
seqmanPointer to entity storage database
output_entitiesResults appended to this range
valuePointer to tag value
value_bytesSize of tag value in bytes.
typeOptional entity type. If specified, search is limited to entities of specified type.
intersect_entitiesOptional intersect list. If specified, search is restricted to entities in this list.

Implements moab::TagInfo.

Definition at line 438 of file SparseTag.cpp.

450 {
451  if( value_bytes && value_bytes != get_size() )
452  {
453  MB_SET_ERR( MB_INVALID_SIZE, "Invalid data size " << get_size() << " specified for sparse tag " << get_name()
454  << " of size " << value_bytes );
455  }
456 
457  MapType::const_iterator iter, end;
458 #ifdef MOAB_HAVE_UNORDERED_MAP
459  if( intersect_entities )
460  {
461  std::pair< Range::iterator, Range::iterator > r;
462  if( type == MBMAXTYPE )
463  {
464  r.first = intersect_entities->begin();
465  r.second = intersect_entities->end();
466  }
467  else
468  {
469  r = intersect_entities->equal_range( type );
470  }
471 
472  find_map_values_equal( *this, value, get_size(), r.first, r.second, mData, output_entities );
473  }
474  else if( type == MBMAXTYPE )
475  {
476  find_tag_values_equal( *this, value, get_size(), mData.begin(), mData.end(), output_entities );
477  }
478  else
479  {
480  Range tmp;
481  seqman->get_entities( type, tmp );
482  find_map_values_equal( *this, value, get_size(), tmp.begin(), tmp.end(), mData, output_entities );
483  }
484 #else
485  if( intersect_entities )
486  {
487  for( Range::const_pair_iterator p = intersect_entities->begin(); p != intersect_entities->end(); ++p )
488  {
489  iter = mData.lower_bound( p->first );
490  end = mData.upper_bound( p->second );
491  find_tag_values_equal( *this, value, get_size(), iter, end, output_entities );
492  }
493  }
494  else
495  {
496  if( type == MBMAXTYPE )
497  {
498  iter = mData.begin();
499  end = mData.end();
500  }
501  else
502  {
503  iter = mData.lower_bound( CREATE_HANDLE( type, MB_START_ID ) );
504  end = mData.upper_bound( CREATE_HANDLE( type, MB_END_ID ) );
505  }
506  find_tag_values_equal( *this, value, get_size(), iter, end, output_entities );
507  }
508 #endif
509 
510  return MB_SUCCESS;
511 }

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

◆ get_data() [1/5]

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

149 {
150  if( data_lengths )
151  {
152  int len = get_size();
153  SysUtil::setmem( data_lengths, &len, sizeof( int ), num_entities );
154  }
155 
156  for( size_t i = 0; i < num_entities; ++i, ++pointers )
157  {
158  if( MB_SUCCESS != get_data_ptr( entities[i], *pointers ) )
159  {
160  if( get_default_value() )
161  *pointers = get_default_value();
162  else
163  return MB_TAG_NOT_FOUND;
164  }
165  }
166 
167  return MB_SUCCESS;
168 }

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

◆ get_data() [2/5]

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.

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

121 {
122  unsigned char* ptr = reinterpret_cast< unsigned char* >( data );
123  for( size_t i = 0; i < num_entities; ++i, ptr += get_size() )
124  {
125  MB_CHK_ERR( get_data( NULL, entities[i], ptr ) );
126  }
127 
128  return MB_SUCCESS;
129 }

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

Referenced by get_data().

◆ get_data() [3/5]

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

175 {
176  if( data_lengths )
177  {
178  int len = get_size();
179  SysUtil::setmem( data_lengths, &len, sizeof( int ), entities.size() );
180  }
181 
182  Range::const_iterator i;
183  for( i = entities.begin(); i != entities.end(); ++i, ++pointers )
184  {
185  if( MB_SUCCESS != get_data_ptr( *i, *pointers ) )
186  {
187  if( get_default_value() )
188  *pointers = get_default_value();
189  else
190  return MB_TAG_NOT_FOUND;
191  }
192  }
193 
194  return MB_SUCCESS;
195 }

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

◆ get_data() [4/5]

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.

Note
Will fail for variable-length data.
Parameters
seqmanPointer to mesh entity database
entitiesEntity handles for which to retrieve tag data
dataPointer to memory in which to store consecutive tag values, one for each passed entity.

Implements moab::TagInfo.

Definition at line 131 of file SparseTag.cpp.

132 {
133  unsigned char* ptr = reinterpret_cast< unsigned char* >( data );
134  Range::const_iterator i;
135  for( i = entities.begin(); i != entities.end(); ++i, ptr += get_size() )
136  {
137  MB_CHK_ERR( get_data( NULL, *i, ptr ) );
138  }
139 
140  return MB_SUCCESS;
141 }

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

◆ get_data() [5/5]

ErrorCode moab::SparseTag::get_data ( Error ,
EntityHandle  entity_handle,
void *  data 
) const
inlineprivate

get the tag data for an entity id

Note
Will fail with MB_VARIABLE_DATA_LENGTH if called for variable-length tag.

Definition at line 88 of file SparseTag.cpp.

89 {
90  const void* ptr = 0;
91  if( MB_SUCCESS == get_data_ptr( entity_handle, ptr, false ) )
92  {
93  memcpy( data, ptr, get_size() );
94  return MB_SUCCESS;
95  }
96  else if( get_default_value() )
97  {
98  memcpy( data, get_default_value(), get_size() );
99  return MB_SUCCESS;
100  }
101  else
102  return MB_TAG_NOT_FOUND;
103 }

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

◆ get_data_ptr()

ErrorCode moab::SparseTag::get_data_ptr ( EntityHandle  entity_handle,
const void *&  data,
bool  allocate = true 
) const
inlineprivate

get the variable-length data for an entity id

Definition at line 74 of file SparseTag.cpp.

75 {
76  MapType::const_iterator iter = mData.find( entity_handle );
77 
78  if( iter != mData.end() )
79  ptr = iter->second;
80  else if( get_default_value() && allocate )
81  ptr = const_cast< SparseTag* >( this )->allocate_data( entity_handle, iter, allocate );
82  else
83  return MB_FAILURE;
84 
85  return MB_SUCCESS;
86 }

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

Referenced by get_data(), and tag_iterate().

◆ get_memory_use()

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

520 {
521  per_entity = get_size() + 4 * sizeof( void* );
522  total = ( mData.size() * per_entity ) + sizeof( *this ) + TagInfo::get_memory_use();
523 
524  return MB_SUCCESS;
525 }

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

◆ get_number_entities()

unsigned long moab::SparseTag::get_number_entities ( )
inline

get number of entities

Definition at line 386 of file SparseTag.hpp.

387  {
388  return mData.size();
389  }

References mData.

◆ get_storage_type()

TagType moab::SparseTag::get_storage_type ( ) const
virtual

Implements moab::TagInfo.

Definition at line 41 of file SparseTag.cpp.

42 {
43  return MB_TAG_SPARSE;
44 }

References MB_TAG_SPARSE.

◆ get_tagged_entities()

ErrorCode moab::SparseTag::get_tagged_entities ( const SequenceManager seqman,
Range output_entities,
EntityType  type = MBMAXTYPE,
const Range intersect = 0 
) const
virtual

Get all tagged entities.

Gets all entity handles that match a type and tag.

Get the list of entities for which the a tag value has been set, or a close approximation if the tag storage scheme cannot accurately determine exactly which entities have explicit values.

Parameters
seqmanPointer to entity storage database
output_entitiesResults appended to this range
typeOptional entity type. If specified, search is limited to entities of specified type.
intersectOptional intersect list. If specified, search is restricted to entities in this list.

Implements moab::TagInfo.

Definition at line 417 of file SparseTag.cpp.

421 {
422  get_tagged( mData, output_range, type, intersect );
423  return MB_SUCCESS;
424 }

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

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

◆ is_tagged()

bool moab::SparseTag::is_tagged ( const SequenceManager ,
EntityHandle  h 
) const
virtual

Check if entity is tagged.

Implements moab::TagInfo.

Definition at line 513 of file SparseTag.cpp.

514 {
515  return mData.find( h ) != mData.end();
516 }

References mData.

◆ num_tagged_entities()

ErrorCode moab::SparseTag::num_tagged_entities ( const SequenceManager seqman,
size_t &  output_count,
EntityType  type = MBMAXTYPE,
const Range intersect = 0 
) const
virtual

Count all tagged entities.

Gets all entity handles that match a type and tag.

Count the entities for which the a tag value has been set, or a close approximation if the tag storage scheme cannot accurately determine exactly which entities have explicit values.

Parameters
seqmanPointer to entity storage database
output_countThis is incremented for each detected entity.
typeOptional entity type. If specified, search is limited to entities of specified type.
intersectOptional intersect list. If specified, search is restricted to entities in this list.

Implements moab::TagInfo.

Definition at line 427 of file SparseTag.cpp.

431 {
432  InsertCount counter( output_count );
433  get_tagged( mData, counter, type, intersect );
434  output_count = counter.end();
435  return MB_SUCCESS;
436 }

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

◆ operator=()

SparseTag& moab::SparseTag::operator= ( const SparseTag )
private

◆ release_all_data()

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.
Note
Invalidates tag if tag_delete_pending is true. The only valid method that can be invoked that is is the destructor.
Parameters
seqmanPointer to mesh entity database

Implements moab::TagInfo.

Definition at line 46 of file SparseTag.cpp.

47 {
48  for( MapType::iterator i = mData.begin(); i != mData.end(); ++i )
49  mAllocator.destroy( i->second );
50  mData.clear();
51  return MB_SUCCESS;
52 }

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

Referenced by ~SparseTag().

◆ remove_data() [1/3]

ErrorCode moab::SparseTag::remove_data ( Error ,
EntityHandle  entity_handle 
)
inlineprivate

removes the data

Definition at line 105 of file SparseTag.cpp.

106 {
107  MapType::iterator i = mData.find( entity_handle );
108  if( i == mData.end() ) return MB_TAG_NOT_FOUND;
109 
110  mAllocator.destroy( i->second );
111  mData.erase( i );
112 
113  return MB_SUCCESS;
114 }

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

◆ remove_data() [2/3]

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

306 {
307  for( size_t i = 0; i < num_entities; ++i )
308  MB_CHK_ERR( remove_data( NULL, entities[i] ) );
309 
310  return MB_SUCCESS;
311 }

References MB_CHK_ERR, and MB_SUCCESS.

Referenced by remove_data().

◆ remove_data() [3/3]

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

314 {
315  for( Range::const_iterator i = entities.begin(); i != entities.end(); ++i )
316  if( MB_SUCCESS != remove_data( NULL, *i ) ) return MB_TAG_NOT_FOUND;
317 
318  return MB_SUCCESS;
319 }

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

◆ set_data() [1/5]

ErrorCode moab::SparseTag::set_data ( Error ,
EntityHandle  entity_handle,
const void *  data 
)
inlineprivate

set the tag data for an entity id

Note
Will fail with MB_VARIABLE_DATA_LENGTH if called for variable-length tag.

Definition at line 54 of file SparseTag.cpp.

55 {
56 #ifdef MOAB_HAVE_UNORDERED_MAP
57  MapType::iterator iter = mData.find( entity_handle );
58 #else
59  MapType::iterator iter = mData.lower_bound( entity_handle );
60 #endif
61 
62  // Data space already exists
63  if( iter != mData.end() && iter->first == entity_handle ) memcpy( iter->second, data, get_size() );
64  // We need to make some data space
65  else
66  {
67  void* new_data = allocate_data( entity_handle, iter, false );
68  memcpy( new_data, data, get_size() );
69  }
70 
71  return MB_SUCCESS;
72 }

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

◆ set_data() [2/5]

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

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

202 {
203  MB_CHK_ERR( seqman->check_valid_entities( NULL, entities, num_entities, true ) );
204 
205  const unsigned char* ptr = reinterpret_cast< const unsigned char* >( data );
206  for( size_t i = 0; i < num_entities; ++i, ptr += get_size() )
207  MB_CHK_ERR( set_data( NULL, entities[i], ptr ) );
208 
209  return MB_SUCCESS;
210 }

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

Referenced by clear_data(), and set_data().

◆ set_data() [3/5]

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

230 {
231  MB_CHK_ERR( validate_lengths( NULL, lengths, num_entities ) );
232 
233  MB_CHK_ERR( seqman->check_valid_entities( NULL, entities, num_entities, true ) );
234 
235  for( size_t i = 0; i < num_entities; ++i, ++pointers )
236  MB_CHK_ERR( set_data( NULL, entities[i], *pointers ) );
237 
238  return MB_SUCCESS;
239 }

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

◆ set_data() [4/5]

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

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

213 {
214  MB_CHK_ERR( seqman->check_valid_entities( NULL, entities ) );
215 
216  const unsigned char* ptr = reinterpret_cast< const unsigned char* >( data );
217  Range::const_iterator i;
218  for( i = entities.begin(); i != entities.end(); ++i, ptr += get_size() )
219  MB_CHK_ERR( set_data( NULL, *i, ptr ) );
220 
221  return MB_SUCCESS;
222 }

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

◆ set_data() [5/5]

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

246 {
247  MB_CHK_ERR( validate_lengths( NULL, lengths, entities.size() ) );
248 
249  MB_CHK_ERR( seqman->check_valid_entities( NULL, entities ) );
250 
251  Range::const_iterator i;
252  for( i = entities.begin(); i != entities.end(); ++i, ++pointers )
253  MB_CHK_ERR( set_data( NULL, *i, *pointers ) );
254 
255  return MB_SUCCESS;
256 }

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

◆ tag_iterate()

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

327 {
328  // Note: We are asked to returning a block of contiguous storage
329  // for some block of contiguous handles for which the tag
330  // storage is also contiguous. As sparse tag storage is
331  // never contiguous, all we can do is return a pointer to the
332  // data for the first entity.
333 
334  // If asked for nothing, successfully return nothing.
335  if( iter == end ) return MB_SUCCESS;
336 
337  // Note: get_data_ptr will return the default value if the
338  // handle is not found, so test to make sure that the
339  // handle is valid.
340  MB_CHK_ERR( seqman->check_valid_entities( NULL, &*iter, 1 ) );
341 
342  // Get pointer to tag storage for entity pointed to by iter
343  const void* ptr = NULL;
344  if( MB_SUCCESS == get_data_ptr( *iter, ptr ) )
345  data_ptr = const_cast< void* >( ptr );
346  else if( get_default_value() && allocate )
347  {
348  ptr = allocate_data( *iter, mData.end() );
349  data_ptr = const_cast< void* >( ptr );
350  }
351  else
352  {
353  // If allocation was not requested, need to increment the iterator so that
354  // the count can be computed properly
355  if( get_default_value() && !allocate ) ++iter;
356  // return not_found(get_name(), *iter);
357  }
358 
359  // Increment iterator and return
360  ++iter;
361  return MB_SUCCESS;
362 }

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

Member Data Documentation

◆ mAllocator

SparseTagDataAllocator moab::SparseTag::mAllocator
private

allocator for this collection

Definition at line 422 of file SparseTag.hpp.

Referenced by allocate_data(), release_all_data(), and remove_data().

◆ mData


The documentation for this class was generated from the following files: