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

data for a single bit tag More...

#include <BitTag.hpp>

+ Inheritance diagram for moab::BitTag:
+ Collaboration diagram for moab::BitTag:

Public Types

enum  { Ln2PageSize = 12 , PageSize = ( 1u << Ln2PageSize ) }
 

Public Member Functions

virtual ~BitTag ()
 
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...
 
ErrorCode get_memory_use (const SequenceManager *seqman, unsigned long &total, unsigned long &per_entity) const
 Get memory use for tag data. More...
 
ErrorCode get_entities_with_bits (EntityType type, Range &entities, unsigned char bits) const
 Get entities for which an explicit tag of the specified value is stored. More...
 
ErrorCode get_entities_with_bits (const Range &range, EntityType type, Range &entities, unsigned char bits) const
 Get entities for which an explicit tag of the specified value is stored. 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
 

Static Public Member Functions

static BitTagcreate_tag (const char *name, int size, const void *default_value=0)
 
- Static Public Member Functions inherited from moab::TagInfo
static int size_from_data_type (DataType t)
 

Private Member Functions

 BitTag (const char *name, int size, const void *default_value)
 
 BitTag (const BitTag &)
 
BitTagoperator= (const BitTag &)
 
ErrorCode reserve (unsigned bits)
 
unsigned char default_val () const
 
void unpack (EntityHandle h, EntityType &type, size_t &page, int &offset) const
 Get indices from handle. More...
 
int ents_per_page () const
 Get the number of tag values that are stored in each BitPage. More...
 
template<class Container >
void get_tagged (EntityType type, Container &entities) const
 
template<class Container >
void get_tagged (Range::const_iterator begin, Range::const_iterator end, Container &entities) const
 
template<class Container >
void get_tagged (Container &entities, EntityType type, const Range *intersect) const
 

Private Attributes

std::vector< BitPage * > pageList [MBMAXTYPE]
 Array of BitPage instances storing actual data. More...
 
unsigned int requestedBitsPerEntity
 user-requested bits per entity More...
 
unsigned int storedBitsPerEntity
 allocated bits per entity (power of 2) More...
 
unsigned int pageShift
 log2( ents_per_page() ) More...
 

Additional Inherited Members

- Protected Member Functions inherited from moab::TagInfo
unsigned long get_memory_use () const
 

Detailed Description

data for a single bit tag

Definition at line 16 of file BitTag.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Ln2PageSize 

Constant: log2(PageSize)

PageSize 

Constant: Bytes per BitPage (power of 2)

Definition at line 347 of file BitTag.hpp.

348  {
349  Ln2PageSize = 12, //!< Constant: log2(PageSize)
350  PageSize = ( 1u << Ln2PageSize ) //!< Constant: Bytes per BitPage (power of 2)
351  };

Constructor & Destructor Documentation

◆ BitTag() [1/2]

moab::BitTag::BitTag ( const char *  name,
int  size,
const void *  default_value 
)
inlineprivate

Definition at line 19 of file BitTag.hpp.

20  : TagInfo( name, size, MB_TYPE_BIT, default_value, default_value ? 1 : 0 ), requestedBitsPerEntity( 0 ),
22  {
23  }

Referenced by create_tag().

◆ ~BitTag()

moab::BitTag::~BitTag ( )
virtual

Definition at line 14 of file BitTag.cpp.

15 {
16  release_all_data( 0, 0, true );
17 }

References release_all_data().

◆ BitTag() [2/2]

moab::BitTag::BitTag ( const BitTag )
private

Member Function Documentation

◆ clear_data() [1/2]

ErrorCode moab::BitTag::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 118 of file BitTag.cpp.

124 {
125  if( value_len ) return MB_INVALID_SIZE;
126 
127  ErrorCode rval = seqman->check_valid_entities( NULL, handles, num_handles, true );MB_CHK_ERR( rval );
128 
129  EntityType type;
130  size_t page;
131  int offset;
132  const unsigned char value = *reinterpret_cast< const unsigned char* >( value_ptr );
133  for( size_t i = 0; i < num_handles; ++i )
134  {
135  unpack( handles[i], type, page, offset );
136  if( pageList[type].size() <= page ) pageList[type].resize( page + 1, 0 );
137  if( !pageList[type][page] ) pageList[type][page] = new BitPage( storedBitsPerEntity, default_val() );
138  pageList[type][page]->set_bits( offset, storedBitsPerEntity, value );
139  }
140 
141  return MB_SUCCESS;
142 }

References moab::SequenceManager::check_valid_entities(), default_val(), ErrorCode, MB_CHK_ERR, MB_INVALID_SIZE, MB_SUCCESS, pageList, size, storedBitsPerEntity, and unpack().

◆ clear_data() [2/2]

ErrorCode moab::BitTag::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 232 of file BitTag.cpp.

237 {
238  if( value_len ) return MB_INVALID_SIZE;
239 
240  ErrorCode rval = seqman->check_valid_entities( NULL, handles );MB_CHK_ERR( rval );
241 
242  EntityType type;
243  EntityID count;
244  size_t page;
245  int offset, per_page = ents_per_page();
246  const unsigned char value = *reinterpret_cast< const unsigned char* >( value_ptr );
247  Range::const_pair_iterator i;
248  for( i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i )
249  {
250  unpack( i->first, type, page, offset );
251  assert( TYPE_FROM_HANDLE( i->second ) == type ); // Should be true because id of zero is never used
252  count = i->second - i->first + 1;
253 
254  while( count )
255  {
256  if( page >= pageList[type].size() ) pageList[type].resize( page + 1, 0 );
257  if( !pageList[type][page] ) pageList[type][page] = new BitPage( storedBitsPerEntity, default_val() );
258 
259  size_t pcount = std::min( (EntityID)( per_page - offset ), count );
260  pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, value );
261  count -= pcount;
262  offset = 0;
263  ++page;
264  }
265  }
266 
267  return MB_SUCCESS;
268 }

References moab::SequenceManager::check_valid_entities(), moab::Range::const_pair_begin(), moab::Range::const_pair_end(), default_val(), ents_per_page(), ErrorCode, MB_CHK_ERR, MB_INVALID_SIZE, MB_SUCCESS, pageList, size, storedBitsPerEntity, moab::TYPE_FROM_HANDLE(), and unpack().

◆ create_tag()

BitTag * moab::BitTag::create_tag ( const char *  name,
int  size,
const void *  default_value = 0 
)
static

Definition at line 24 of file BitTag.cpp.

25 {
26  BitTag* result = new BitTag( name, size, default_value );
27  if( MB_SUCCESS != result->reserve( size ) )
28  {
29  delete result;
30  result = NULL;
31  }
32 
33  return result;
34 }

References BitTag(), MB_SUCCESS, reserve(), and size.

Referenced by moab::Core::tag_get_handle().

◆ default_val()

unsigned char moab::BitTag::default_val ( ) const
inlineprivate

Definition at line 358 of file BitTag.hpp.

359  {
360  if( get_default_value() )
361  return *reinterpret_cast< const unsigned char* >( get_default_value() );
362  else
363  return 0;
364  }

References moab::TagInfo::get_default_value().

Referenced by clear_data(), get_data(), remove_data(), and set_data().

◆ ents_per_page()

int moab::BitTag::ents_per_page ( ) const
inlineprivate

Get the number of tag values that are stored in each BitPage.

Definition at line 386 of file BitTag.hpp.

387  {
388  return 8 * PageSize / storedBitsPerEntity;
389  }

References PageSize, and storedBitsPerEntity.

Referenced by clear_data(), get_data(), get_entities_with_bits(), get_tagged(), remove_data(), and set_data().

◆ find_entities_with_value()

ErrorCode moab::BitTag::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 429 of file BitTag.cpp.

436 {
437  if( value_bytes && value_bytes != 1 )
438  {
439  MB_SET_ERR( MB_INVALID_SIZE, "Invalid tag size for bit tag: " << value_bytes << " bytes" );
440  }
441 
442  const signed char bits = *reinterpret_cast< const unsigned char* >( value );
443  if( intersect_entities )
444  return get_entities_with_bits( *intersect_entities, type, output_entities, bits );
445  else
446  return get_entities_with_bits( type, output_entities, bits );
447 }

References get_entities_with_bits(), MB_INVALID_SIZE, and MB_SET_ERR.

◆ get_data() [1/4]

ErrorCode moab::BitTag::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 298 of file BitTag.cpp.

304 {
305  MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "Operation get_data not supported for bit tags" );
306 }

References MB_SET_ERR, and MB_TYPE_OUT_OF_RANGE.

◆ get_data() [2/4]

ErrorCode moab::BitTag::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 72 of file BitTag.cpp.

77 {
78  EntityType type;
79  size_t page;
80  int offset;
81  unsigned char def = default_val();
82  unsigned char* data = reinterpret_cast< unsigned char* >( gen_data );
83  for( size_t i = 0; i < num_handles; ++i )
84  {
85  unpack( handles[i], type, page, offset );
86  if( pageList[type].size() <= page || !pageList[type][page] )
87  data[i] = def;
88  else
89  data[i] = pageList[type][page]->get_bits( offset, storedBitsPerEntity );
90  }
91 
92  return MB_SUCCESS;
93 }

References default_val(), MB_SUCCESS, pageList, size, storedBitsPerEntity, and unpack().

◆ get_data() [3/4]

ErrorCode moab::BitTag::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 308 of file BitTag.cpp.

309 {
310  MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "Operation get_data not supported for bit tags" );
311 }

References MB_SET_ERR, and MB_TYPE_OUT_OF_RANGE.

◆ get_data() [4/4]

ErrorCode moab::BitTag::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 160 of file BitTag.cpp.

161 {
162  EntityType type;
163  EntityID count;
164  size_t page;
165  int offset, per_page = ents_per_page();
166  unsigned char def = default_val();
167  unsigned char* data = reinterpret_cast< unsigned char* >( gen_data );
168  Range::const_pair_iterator i;
169  for( i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i )
170  {
171  unpack( i->first, type, page, offset );
172  assert( TYPE_FROM_HANDLE( i->second ) == type ); // Should be true because id of zero is never used
173  count = i->second - i->first + 1;
174  if( page >= pageList[type].size() )
175  {
176  memset( data, def, count );
177  data += count;
178  continue;
179  }
180 
181  while( count )
182  {
183  size_t pcount = std::min( (EntityID)( per_page - offset ), count );
184  if( pageList[type][page] )
185  pageList[type][page]->get_bits( offset, pcount, storedBitsPerEntity, data );
186  else
187  memset( data, def, pcount );
188  data += pcount;
189  count -= pcount;
190  offset = 0;
191  ++page;
192  }
193  }
194 
195  return MB_SUCCESS;
196 }

References moab::Range::const_pair_begin(), moab::Range::const_pair_end(), default_val(), ents_per_page(), MB_SUCCESS, pageList, size, storedBitsPerEntity, moab::TYPE_FROM_HANDLE(), and unpack().

◆ get_entities_with_bits() [1/2]

ErrorCode moab::BitTag::get_entities_with_bits ( const Range range,
EntityType  type,
Range entities,
unsigned char  bits 
) const

Get entities for which an explicit tag of the specified value is stored.

Definition at line 470 of file BitTag.cpp.

474 {
475  if( MBMAXTYPE == in_type )
476  {
477  ErrorCode rval;
478  for( --in_type; in_type >= MBVERTEX; --in_type )
479  {
480  rval = get_entities_with_bits( range, in_type, entities, bits );MB_CHK_ERR( rval );
481  }
482  return MB_SUCCESS;
483  }
484 
485  EntityType type;
486  EntityID count;
487  size_t page;
488  int offset, per_page = ents_per_page();
489  Range::const_iterator i, end;
490  std::pair< Range::iterator, Range::iterator > r = range.equal_range( in_type );
491  i = r.first;
492  end = r.second;
493  EntityHandle h;
494  while( i != end )
495  {
496  h = *i;
497  unpack( h, type, page, offset );
498  assert( MBMAXTYPE == in_type || type == in_type );
499 
500  i = i.end_of_block();
501  count = *i - h + 1;
502  ++i;
503  while( count > 0 )
504  {
505  EntityID pcount = std::min( count, (EntityID)( per_page - offset ) );
506  if( page < pageList[type].size() && pageList[type][page] )
507  pageList[type][page]->search( bits, offset, pcount, storedBitsPerEntity, entities, h );
508 
509  count -= pcount;
510  h += pcount;
511  assert( TYPE_FROM_HANDLE( h ) == type );
512  offset = 0;
513  ++page;
514  }
515  }
516 
517  return MB_SUCCESS;
518 }

References moab::Range::const_iterator::end_of_block(), entities, ents_per_page(), moab::Range::equal_range(), ErrorCode, get_entities_with_bits(), MB_CHK_ERR, MB_SUCCESS, MBMAXTYPE, MBVERTEX, pageList, size, storedBitsPerEntity, moab::TYPE_FROM_HANDLE(), and unpack().

◆ get_entities_with_bits() [2/2]

ErrorCode moab::BitTag::get_entities_with_bits ( EntityType  type,
Range entities,
unsigned char  bits 
) const

Get entities for which an explicit tag of the specified value is stored.

Definition at line 449 of file BitTag.cpp.

450 {
451  std::pair< EntityType, EntityType > r = type_range( type );
452  const int per_page = ents_per_page();
453  for( EntityType t = r.first; t != r.second; ++t )
454  {
455  for( size_t i = 0; i < pageList[t].size(); ++i )
456  {
457  if( pageList[t][i] )
458  {
459  EntityID id = i * per_page;
460  EntityHandle h = CREATE_HANDLE( t, id );
461  int off = !i; // Never zero ID
462  pageList[t][i]->search( bits, off, per_page - off, storedBitsPerEntity, entities, h + off );
463  }
464  }
465  }
466 
467  return MB_SUCCESS;
468 }

References moab::CREATE_HANDLE(), entities, ents_per_page(), MB_SUCCESS, pageList, storedBitsPerEntity, t, and moab::type_range().

Referenced by find_entities_with_value(), and get_entities_with_bits().

◆ get_memory_use()

ErrorCode moab::BitTag::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 520 of file BitTag.cpp.

521 {
522  per_entity = ( storedBitsPerEntity > 4 ); // Cannot return fraction of bytes, so round
523  total = 0;
524  for( EntityType t = (EntityType)0; t < MBMAXTYPE; ++t )
525  {
526  total += pageList[t].capacity() * sizeof( BitPage* );
527  for( size_t i = 0; i < pageList[t].size(); ++i )
528  if( pageList[t][i] ) total += sizeof( BitPage );
529  }
530 
531  return MB_SUCCESS;
532 }

References MB_SUCCESS, MBMAXTYPE, pageList, storedBitsPerEntity, and t.

◆ get_storage_type()

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

Implements moab::TagInfo.

Definition at line 19 of file BitTag.cpp.

20 {
21  return MB_TAG_BIT;
22 }

References MB_TAG_BIT.

◆ get_tagged() [1/3]

template<class Container >
void moab::BitTag::get_tagged ( Container &  entities,
EntityType  type,
const Range intersect 
) const
inlineprivate

Definition at line 395 of file BitTag.cpp.

397 {
398  if( !intersect )
399  get_tagged< Container >( type, entities );
400  else if( MBMAXTYPE == type )
401  get_tagged< Container >( intersect->begin(), intersect->end(), entities );
402  else
403  {
404  std::pair< Range::iterator, Range::iterator > r = intersect->equal_range( type );
405  get_tagged< Container >( r.first, r.second, entities );
406  }
407 }

References entities, moab::intersect(), and MBMAXTYPE.

◆ get_tagged() [2/3]

template<class Container >
void moab::BitTag::get_tagged ( EntityType  type,
Container &  entities 
) const
inlineprivate

Definition at line 339 of file BitTag.cpp.

340 {
341  std::pair< EntityType, EntityType > r = type_range( type );
342  typename Container::iterator hint = entities.begin();
343  const int per_page = ents_per_page();
344  for( EntityType t = r.first; t != r.second; ++t )
345  {
346  for( size_t i = 0; i < pageList[t].size(); ++i )
347  {
348  if( pageList[t][i] )
349  {
350  EntityID id = i * per_page;
351  EntityHandle h = CREATE_HANDLE( t, id );
352  EntityHandle last = h + per_page - 1;
353  // Never zero ID
354  if( 0 == id ) ++h;
355  hint = entities.insert( hint, h, last );
356  }
357  }
358  }
359 }

References moab::CREATE_HANDLE(), entities, ents_per_page(), pageList, t, and moab::type_range().

◆ get_tagged() [3/3]

template<class Container >
void moab::BitTag::get_tagged ( Range::const_iterator  begin,
Range::const_iterator  end,
Container &  entities 
) const
inlineprivate

Definition at line 362 of file BitTag.cpp.

363 {
364  EntityType type;
365  EntityID count;
366  size_t page;
367  int offset, per_page = ents_per_page();
368  typename Container::iterator hint = entities.begin();
369  EntityHandle h;
370  Range::const_iterator i = begin;
371  while( i != end )
372  {
373  h = *i;
374  unpack( h, type, page, offset );
375 
376  i = i.end_of_block();
377  count = *i - h + 1;
378  ++i;
379  while( count > 0 )
380  {
381  EntityID pcount = std::min( count, (EntityID)( per_page - offset ) );
382  if( page < pageList[type].size() && pageList[type][page] )
383  hint = entities.insert( hint, h, h + pcount - 1 );
384 
385  count -= pcount;
386  h += pcount;
387  assert( TYPE_FROM_HANDLE( h ) == type );
388  offset = 0;
389  ++page;
390  }
391  }
392 }

References moab::Range::const_iterator::end_of_block(), entities, ents_per_page(), pageList, size, moab::TYPE_FROM_HANDLE(), and unpack().

◆ get_tagged_entities()

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

Get all tagged entities.

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 409 of file BitTag.cpp.

413 {
414  get_tagged< Range >( entities, type, intersect );
415  return MB_SUCCESS;
416 }

References entities, moab::intersect(), and MB_SUCCESS.

◆ is_tagged()

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

Check if entity is tagged.

Implements moab::TagInfo.

Definition at line 534 of file BitTag.cpp.

535 {
536  EntityType type;
537  size_t page;
538  int offset;
539  unpack( h, type, page, offset );
540  return page < pageList[type].size() && pageList[type][page];
541 }

References pageList, and unpack().

◆ num_tagged_entities()

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

Count all tagged entities.

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 418 of file BitTag.cpp.

422 {
423  InsertCount counter( count );
424  get_tagged< InsertCount >( counter, type, intersect );
425  count = counter.end();
426  return MB_SUCCESS;
427 }

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

◆ operator=()

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

◆ release_all_data()

ErrorCode moab::BitTag::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 60 of file BitTag.cpp.

61 {
62  for( EntityType t = (EntityType)0; t != MBMAXTYPE; ++t )
63  {
64  for( size_t i = 0; i < pageList[t].size(); ++i )
65  delete pageList[t][i];
66  pageList[t].clear();
67  }
68 
69  return MB_SUCCESS;
70 }

References MB_SUCCESS, MBMAXTYPE, pageList, and t.

Referenced by ~BitTag().

◆ remove_data() [1/2]

ErrorCode moab::BitTag::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 144 of file BitTag.cpp.

145 {
146  EntityType type;
147  size_t page;
148  int offset;
149  const unsigned char val = default_val();
150  for( size_t i = 0; i < num_handles; ++i )
151  {
152  unpack( handles[i], type, page, offset );
153  if( pageList[type].size() > page && pageList[type][page] )
154  pageList[type][page]->set_bits( offset, storedBitsPerEntity, val );
155  }
156 
157  return MB_SUCCESS;
158 }

References default_val(), MB_SUCCESS, pageList, size, storedBitsPerEntity, and unpack().

◆ remove_data() [2/2]

ErrorCode moab::BitTag::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 270 of file BitTag.cpp.

271 {
272  EntityType type;
273  EntityID count;
274  size_t page;
275  int offset, per_page = ents_per_page();
276  unsigned char val = default_val();
277  Range::const_pair_iterator i;
278  for( i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i )
279  {
280  unpack( i->first, type, page, offset );
281  assert( TYPE_FROM_HANDLE( i->second ) == type ); // Should be true because id of zero is never used
282  count = i->second - i->first + 1;
283 
284  while( count )
285  {
286  size_t pcount = std::min( (EntityID)( per_page - offset ), count );
287  if( page < pageList[type].size() && pageList[type][page] )
288  pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, val );
289  count -= pcount;
290  offset = 0;
291  ++page;
292  }
293  }
294 
295  return MB_SUCCESS;
296 }

References moab::Range::const_pair_begin(), moab::Range::const_pair_end(), default_val(), ents_per_page(), MB_SUCCESS, pageList, size, storedBitsPerEntity, moab::TYPE_FROM_HANDLE(), and unpack().

◆ reserve()

ErrorCode moab::BitTag::reserve ( unsigned  bits)
private

Definition at line 36 of file BitTag.cpp.

37 {
38  if( bits > 8 ) return MB_FAILURE;
39 
41  // Store smallest power of two greater than or
42  // equal to the number of bits
44  unsigned ln2storedbits = 0;
45  while( storedBitsPerEntity < bits )
46  {
48  ++ln2storedbits;
49  }
50 
51  // pageShift = log2(ents_per_page())
52  // = log2(8 * pageSize / storedBitsPerEntity )
53  // = log2(8) + log2(pageSize) - log2(storedBitsPerEntity)
54  // = 3 + Ln2PageSize - ln2storedbits;
55  pageShift = 3 + Ln2PageSize - ln2storedbits;
56 
57  return MB_SUCCESS;
58 }

References Ln2PageSize, MB_SUCCESS, pageShift, requestedBitsPerEntity, and storedBitsPerEntity.

Referenced by create_tag().

◆ set_data() [1/4]

ErrorCode moab::BitTag::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 95 of file BitTag.cpp.

100 {
101  ErrorCode rval = seqman->check_valid_entities( NULL, handles, num_handles, true );MB_CHK_ERR( rval );
102 
103  EntityType type;
104  size_t page;
105  int offset;
106  const unsigned char* data = reinterpret_cast< const unsigned char* >( gen_data );
107  for( size_t i = 0; i < num_handles; ++i )
108  {
109  unpack( handles[i], type, page, offset );
110  if( pageList[type].size() <= page ) pageList[type].resize( page + 1, 0 );
111  if( !pageList[type][page] ) pageList[type][page] = new BitPage( storedBitsPerEntity, default_val() );
112  pageList[type][page]->set_bits( offset, storedBitsPerEntity, data[i] );
113  }
114 
115  return MB_SUCCESS;
116 }

References moab::SequenceManager::check_valid_entities(), default_val(), ErrorCode, MB_CHK_ERR, MB_SUCCESS, pageList, size, storedBitsPerEntity, and unpack().

◆ set_data() [2/4]

ErrorCode moab::BitTag::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 313 of file BitTag.cpp.

319 {
320  MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "Operation set_data not supported for bit tags" );
321 }

References MB_SET_ERR, and MB_TYPE_OUT_OF_RANGE.

◆ set_data() [3/4]

ErrorCode moab::BitTag::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 198 of file BitTag.cpp.

199 {
200  ErrorCode rval = seqman->check_valid_entities( NULL, handles );MB_CHK_ERR( rval );
201 
202  EntityType type;
203  EntityID count;
204  size_t page;
205  int offset, per_page = ents_per_page();
206  unsigned char def = default_val();
207  const unsigned char* data = reinterpret_cast< const unsigned char* >( gen_data );
208  Range::const_pair_iterator i;
209  for( i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i )
210  {
211  unpack( i->first, type, page, offset );
212  assert( TYPE_FROM_HANDLE( i->second ) == type ); // Should be true because id of zero is never used
213  count = i->second - i->first + 1;
214 
215  while( count )
216  {
217  if( page >= pageList[type].size() ) pageList[type].resize( page + 1, 0 );
218  if( !pageList[type][page] ) pageList[type][page] = new BitPage( storedBitsPerEntity, def );
219 
220  size_t pcount = std::min( (EntityID)( per_page - offset ), count );
221  pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, data );
222  data += pcount;
223  count -= pcount;
224  offset = 0;
225  ++page;
226  }
227  }
228 
229  return MB_SUCCESS;
230 }

References moab::SequenceManager::check_valid_entities(), moab::Range::const_pair_begin(), moab::Range::const_pair_end(), default_val(), ents_per_page(), ErrorCode, MB_CHK_ERR, MB_SUCCESS, pageList, size, storedBitsPerEntity, moab::TYPE_FROM_HANDLE(), and unpack().

◆ set_data() [4/4]

ErrorCode moab::BitTag::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 323 of file BitTag.cpp.

324 {
325  MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "Operation set_data not supported for bit tags" );
326 }

References MB_SET_ERR, and MB_TYPE_OUT_OF_RANGE.

◆ tag_iterate()

ErrorCode moab::BitTag::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.

\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 328 of file BitTag.cpp.

334 {
335  MB_SET_ERR( MB_TYPE_OUT_OF_RANGE, "Operation tag_iterate not supported for bit tags" );
336 }

References MB_SET_ERR, and MB_TYPE_OUT_OF_RANGE.

◆ unpack()

void moab::BitTag::unpack ( EntityHandle  h,
EntityType &  type,
size_t &  page,
int &  offset 
) const
inlineprivate

Get indices from handle.

Parameters
typeOutput: entity type
pageOutput: index into pageList[type]
offsetOutput: index into pageList[type][page]

Definition at line 377 of file BitTag.hpp.

378  {
379  type = TYPE_FROM_HANDLE( h );
380  h = ID_FROM_HANDLE( h );
381  page = ( (size_t)h ) >> pageShift; // h / ents_per_page()
382  offset = h & ( ( 1u << pageShift ) - 1u ); // h % ends_per_page()
383  }

References moab::ID_FROM_HANDLE(), pageShift, and moab::TYPE_FROM_HANDLE().

Referenced by clear_data(), get_data(), get_entities_with_bits(), get_tagged(), is_tagged(), remove_data(), and set_data().

Member Data Documentation

◆ pageList

std::vector< BitPage* > moab::BitTag::pageList[MBMAXTYPE]
private

Array of BitPage instances storing actual data.

Definition at line 366 of file BitTag.hpp.

Referenced by clear_data(), get_data(), get_entities_with_bits(), get_memory_use(), get_tagged(), is_tagged(), release_all_data(), remove_data(), and set_data().

◆ pageShift

unsigned int moab::BitTag::pageShift
private

log2( ents_per_page() )

Definition at line 369 of file BitTag.hpp.

Referenced by reserve(), and unpack().

◆ requestedBitsPerEntity

unsigned int moab::BitTag::requestedBitsPerEntity
private

user-requested bits per entity

Definition at line 367 of file BitTag.hpp.

Referenced by reserve().

◆ storedBitsPerEntity

unsigned int moab::BitTag::storedBitsPerEntity
private

allocated bits per entity (power of 2)

Definition at line 368 of file BitTag.hpp.

Referenced by clear_data(), ents_per_page(), get_data(), get_entities_with_bits(), get_memory_use(), remove_data(), reserve(), and set_data().


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