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

Dense storage of fixed-length tag data. More...

#include <DenseTag.hpp>

+ Inheritance diagram for moab::DenseTag:
+ Collaboration diagram for moab::DenseTag:

Public Member Functions

virtual ~DenseTag ()
 
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...
 
ErrorCode get_array (const SequenceManager *seqman, Error *error, EntityHandle h, const unsigned char *const &ptr, size_t &count) const
 Get read-only tag storage. More...
 
ErrorCode get_array (const EntitySequence *seq, const unsigned char *const &ptr) const
 Get read-only tag storage for entire sequence. 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 DenseTagcreate_tag (SequenceManager *seqman, Error *error, const char *name, int bytes, DataType type, const void *default_value)
 
- Static Public Member Functions inherited from moab::TagInfo
static int size_from_data_type (DataType t)
 

Private Member Functions

 DenseTag (int array_index, const char *name, int size, DataType type, const void *default_value)
 
 DenseTag (const DenseTag &)
 
DenseTagoperator= (const DenseTag &)
 
ErrorCode get_array_private (SequenceManager *seqman, Error *error, EntityHandle h, unsigned char *&ptr, size_t &count, bool allocate)
 Get or allocated tag storage. More...
 
ErrorCode get_array_private (const SequenceManager *seqman, Error *error, EntityHandle h, const unsigned char *&ptr, size_t &count) const
 Get tag storage. More...
 
ErrorCode get_array_private (const EntitySequence *seq, const unsigned char *&ptr) const
 Get non-read-only tag storage for entire sequence. More...
 
ErrorCode clear_data (bool allocate, SequenceManager *seqman, Error *error, const EntityHandle *entities, size_t num_entities, const void *value_ptr)
 Common implementation of public clear_data and remove_data. More...
 
ErrorCode clear_data (bool allocate, SequenceManager *seqman, Error *error, const Range &entities, const void *value_ptr)
 Common implementation of public clear_data and remove_data. More...
 

Private Attributes

int mySequenceArray
 Array index in SequenceManager used to store tag data. More...
 
unsigned char * meshValue
 

Additional Inherited Members

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

Detailed Description

Dense storage of fixed-length tag data.

Implement normal dense tag.

Definition at line 20 of file DenseTag.hpp.

Constructor & Destructor Documentation

◆ DenseTag() [1/2]

moab::DenseTag::DenseTag ( int  array_index,
const char *  name,
int  size,
DataType  type,
const void *  default_value 
)
private

Definition at line 52 of file DenseTag.cpp.

53  : TagInfo( name, size, type, default_value, size ), mySequenceArray( index ), meshValue( 0 )
54 {
55 }

Referenced by create_tag().

◆ ~DenseTag()

moab::DenseTag::~DenseTag ( )
virtual

Definition at line 77 of file DenseTag.cpp.

78 {
79  assert( mySequenceArray < 0 );
80  delete[] meshValue;
81 }

References meshValue, and mySequenceArray.

◆ DenseTag() [2/2]

moab::DenseTag::DenseTag ( const DenseTag )
private

Member Function Documentation

◆ clear_data() [1/4]

ErrorCode moab::DenseTag::clear_data ( bool  allocate,
SequenceManager seqman,
Error error,
const EntityHandle entities,
size_t  num_entities,
const void *  value_ptr 
)
private

Common implementation of public clear_data and remove_data.

Definition at line 429 of file DenseTag.cpp.

435 {
436  const EntityHandle* const end = entities + num_entities;
437  unsigned char* array = NULL;
438  size_t junk = 0;
439 
440  for( const EntityHandle* i = entities; i != end; ++i )
441  {
442  MB_CHK_ERR( get_array_private( seqman, NULL, *i, array, junk, allocate ) );
443 
444  if( array ) // Array should never be null if allocate == true
445  memcpy( array, value_ptr, get_size() );
446  }
447 
448  return MB_SUCCESS;
449 }

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

◆ clear_data() [2/4]

ErrorCode moab::DenseTag::clear_data ( bool  allocate,
SequenceManager seqman,
Error error,
const Range entities,
const void *  value_ptr 
)
private

Common implementation of public clear_data and remove_data.

Definition at line 451 of file DenseTag.cpp.

456 {
457  unsigned char* array = NULL;
458  size_t avail = 0;
459 
460  for( Range::const_pair_iterator p = entities.const_pair_begin(); p != entities.const_pair_end(); ++p )
461  {
462  EntityHandle start = p->first;
463  while( start <= p->second )
464  {
465  MB_CHK_ERR( get_array_private( seqman, NULL, start, array, avail, allocate ) );
466 
467  const size_t count = std::min< size_t >( p->second - start + 1, avail );
468  if( array ) // Array should never be null if allocate == true
469  SysUtil::setmem( array, value_ptr, get_size(), count );
470  start += count;
471  }
472  }
473 
474  return MB_SUCCESS;
475 }

References moab::Range::const_pair_begin(), moab::Range::const_pair_end(), get_array_private(), moab::TagInfo::get_size(), MB_CHK_ERR, MB_SUCCESS, and moab::SysUtil::setmem().

◆ clear_data() [3/4]

ErrorCode moab::DenseTag::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 477 of file DenseTag.cpp.

483 {
484  if( value_len && value_len != get_size() ) return MB_INVALID_SIZE;
485 
486  return clear_data( true, seqman, NULL, entities, num_entities, value_ptr );
487 }

References moab::TagInfo::get_size(), and MB_INVALID_SIZE.

Referenced by clear_data(), and remove_data().

◆ clear_data() [4/4]

ErrorCode moab::DenseTag::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 489 of file DenseTag.cpp.

494 {
495  if( value_len && value_len != get_size() ) return MB_INVALID_SIZE;
496 
497  return clear_data( true, seqman, NULL, entities, value_ptr );
498 }

References clear_data(), moab::TagInfo::get_size(), and MB_INVALID_SIZE.

◆ create_tag()

DenseTag * moab::DenseTag::create_tag ( SequenceManager seqman,
Error error,
const char *  name,
int  bytes,
DataType  type,
const void *  default_value 
)
static

Definition at line 62 of file DenseTag.cpp.

68 {
69  if( bytes < 1 ) return 0;
70 
71  int index;
72  if( MB_SUCCESS != seqman->reserve_tag_array( NULL, bytes, index ) ) return 0;
73 
74  return new DenseTag( index, name, bytes, type, default_value );
75 }

References DenseTag(), moab::index, MB_SUCCESS, and moab::SequenceManager::reserve_tag_array().

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

◆ find_entities_with_value()

ErrorCode moab::DenseTag::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 588 of file DenseTag.cpp.

595 {
596  if( value_bytes && value_bytes != get_size() )
597  {
599  "Cannot compare data of size " << value_bytes << " with tag of size " << get_size() );
600  }
601 
602  if( !intersect_entities )
603  {
604  std::pair< EntityType, EntityType > range = type_range( type );
606  for( EntityType t = range.first; t != range.second; ++t )
607  {
608  const TypeSequenceManager& map = seqman->entity_map( t );
609  for( i = map.begin(); i != map.end(); ++i )
610  {
611  const void* data = ( *i )->data()->get_tag_data( mySequenceArray );
612  if( data )
613  {
614  ByteArrayIterator start( ( *i )->data()->start_handle(), data, *this );
615  ByteArrayIterator end( ( *i )->end_handle() + 1, 0, 0 );
616  start += ( *i )->start_handle() - ( *i )->data()->start_handle();
617  find_tag_values_equal( *this, value, get_size(), start, end, output_entities );
618  }
619  }
620  }
621  }
622  else
623  {
624  const unsigned char* array = NULL; // Initialize to get rid of warning
625  size_t count;
626 
627  Range::const_pair_iterator p = intersect_entities->begin();
628  if( type != MBMAXTYPE )
629  {
630  p = intersect_entities->lower_bound( type );
631  assert( TYPE_FROM_HANDLE( p->first ) == type );
632  }
633  for( ;
634  p != intersect_entities->const_pair_end() && ( MBMAXTYPE == type || TYPE_FROM_HANDLE( p->first ) == type );
635  ++p )
636  {
637  EntityHandle start = p->first;
638  while( start <= p->second )
639  {
640  MB_CHK_ERR( get_array( seqman, NULL, start, array, count ) );
641 
642  if( p->second - start < count - 1 ) count = p->second - start + 1;
643 
644  if( array )
645  {
646  ByteArrayIterator istart( start, array, *this );
647  ByteArrayIterator iend( start + count, 0, 0 );
648  find_tag_values_equal( *this, value, get_size(), istart, iend, output_entities );
649  }
650  start += count;
651  }
652  }
653  }
654 
655  return MB_SUCCESS;
656 }

References moab::Range::begin(), moab::TypeSequenceManager::begin(), moab::Range::const_pair_end(), moab::ByteArrayIterator::data, moab::TypeSequenceManager::end(), moab::SequenceManager::entity_map(), moab::find_tag_values_equal(), get_array(), moab::TagInfo::get_size(), moab::Range::lower_bound(), MB_CHK_ERR, MB_INVALID_SIZE, MB_SET_ERR, MB_SUCCESS, MBMAXTYPE, mySequenceArray, moab::TYPE_FROM_HANDLE(), and moab::type_range().

◆ get_array() [1/2]

ErrorCode moab::DenseTag::get_array ( const EntitySequence seq,
const unsigned char *const &  ptr 
) const

Get read-only tag storage for entire sequence.

Parameters
seqSequence
ptrPointer to dag storage. This pointer will be set to null and MB_SUCCESS will be returned if no tag storage has been allocated.
Returns
MB_SUCCESS if sequence is valid (regardless of whether or not any tag storage is allocated).

Definition at line 134 of file DenseTag.cpp.

135 {
136  // cast away the constness; otherwise it would be infinite recursion
137  // probably we are not calling this anywhere
138  return get_array_private( seq, const_cast< const unsigned char*& >( ptr ) );
139 }

References get_array_private().

◆ get_array() [2/2]

ErrorCode moab::DenseTag::get_array ( const SequenceManager seqman,
Error error,
EntityHandle  h,
const unsigned char *const &  ptr,
size_t &  count 
) const

Get read-only tag storage.

Parameters
seqmanSequence manager
errorError object through which to report errors
hFirst entity for which to return storage.
ptrPointer to dag storage. This pointer will be set to null and MB_SUCCESS will be returned if the handle is valid but no tag storage has been allocated.
countNumber of consecutive entities for which tag storage is returned. This value will be valid even if null is returned for ptr and indicates the number of consecutive entities for which no tag storage has been allocated.
Returns
MB_SUCCESS if handle is valid (regardless of whether or not any tag storage is allocated).

Definition at line 90 of file DenseTag.cpp.

95 {
96  // cast away the const-ness; do we really want to do this?
97  // probably we are not calling this anywhere;
98  // clang compiler found this
99  return get_array_private( seqman, NULL, h, const_cast< const unsigned char*& >( ptr ), count );
100 }

References get_array_private().

Referenced by find_entities_with_value(), get_data(), is_tagged(), and moab::WriteDamsel::map_dense_tags().

◆ get_array_private() [1/3]

ErrorCode moab::DenseTag::get_array_private ( const EntitySequence seq,
const unsigned char *&  ptr 
) const
private

Get non-read-only tag storage for entire sequence.

Parameters
seqSequence
ptrPointer to dag storage. This pointer will be set to null and MB_SUCCESS will be returned if no tag storage has been allocated.
Returns
MB_SUCCESS if sequence is valid (regardless of whether or not any tag storage is allocated).

Definition at line 141 of file DenseTag.cpp.

142 {
143  ptr = reinterpret_cast< const unsigned char* >( seq->data()->get_tag_data( mySequenceArray ) );
144  if( ptr ) ptr += get_size() * ( seq->start_handle() - seq->data()->start_handle() );
145 
146  return MB_SUCCESS;
147 }

References moab::EntitySequence::data(), moab::TagInfo::get_size(), moab::SequenceData::get_tag_data(), MB_SUCCESS, mySequenceArray, moab::EntitySequence::start_handle(), and moab::SequenceData::start_handle().

◆ get_array_private() [2/3]

ErrorCode moab::DenseTag::get_array_private ( const SequenceManager seqman,
Error error,
EntityHandle  h,
const unsigned char *&  ptr,
size_t &  count 
) const
inlineprivate

Get tag storage.

Parameters
hFirst entity for which to return storage.
ptrPointer to dag storage. This pointer will be set to null and MB_SUCCESS will be returned if the handle is valid but no tag storage has been allocated.
countNumber of consecutive entities for which tag storage is returned. This value will be valid even if null is returned for ptr and indicates the number of consecutive entities for which no tag storage has been allocated.
Returns
MB_SUCCESS if handle is valid (regardless of whether or not any tag storage is allocated).

Definition at line 102 of file DenseTag.cpp.

107 {
108  const EntitySequence* seq = 0;
109  ErrorCode rval = seqman->find( h, seq );
110  if( MB_SUCCESS != rval )
111  {
112  if( !h )
113  { // Root set
114  ptr = meshValue;
115  count = 1;
116  return MB_SUCCESS;
117  }
118  else
119  { // Not root set
120  ptr = 0;
121  count = 0;
122  return ent_not_found( get_name(), h );
123  }
124  }
125 
126  const void* mem = seq->data()->get_tag_data( mySequenceArray );
127  ptr = reinterpret_cast< const unsigned char* >( mem );
128  count = seq->data()->end_handle() - h + 1;
129  if( ptr ) ptr += get_size() * ( h - seq->data()->start_handle() );
130 
131  return MB_SUCCESS;
132 }

References moab::EntitySequence::data(), moab::SequenceData::end_handle(), moab::ent_not_found(), ErrorCode, moab::SequenceManager::find(), moab::TagInfo::get_name(), moab::TagInfo::get_size(), moab::SequenceData::get_tag_data(), MB_SUCCESS, meshValue, mySequenceArray, and moab::SequenceData::start_handle().

◆ get_array_private() [3/3]

ErrorCode moab::DenseTag::get_array_private ( SequenceManager seqman,
Error error,
EntityHandle  h,
unsigned char *&  ptr,
size_t &  count,
bool  allocate 
)
inlineprivate

Get or allocated tag storage.

Parameters
hFirst entity for which to return storage.
ptrPointer to dag storage. This pointer will be set to null and MB_SUCCESS will be returned if the handle is valid but no tag storage has been allocated.
countNumber of consecutive entities for which tag storage is returned. This value will be valid even if null is returned for ptr and indicates the number of consecutive entities for which no tag storage has been allocated.
allocateIf true storage will be allocated and initialized if it has not already been allocated.
Returns
MB_SUCCESS if handle is valid (regardless of whether or not any tag storage is allocated).

Definition at line 149 of file DenseTag.cpp.

155 {
156  EntitySequence* seq = 0;
157  ErrorCode rval = seqman->find( h, seq );
158  if( MB_SUCCESS != rval )
159  {
160  if( !h )
161  { // Root set
162  if( !meshValue && allocate ) meshValue = new unsigned char[get_size()];
163  ptr = meshValue;
164  count = 1;
165  return MB_SUCCESS;
166  }
167  else
168  { // Not root set
169  ptr = 0;
170  count = 0;
171  return ent_not_found( get_name(), h );
172  }
173  }
174 
175  void* mem = seq->data()->get_tag_data( mySequenceArray );
176  if( !mem && allocate )
177  {
178  mem = seq->data()->allocate_tag_array( mySequenceArray, get_size(), get_default_value() );
179  if( !mem )
180  {
181  MB_SET_ERR( MB_MEMORY_ALLOCATION_FAILED, "Memory allocation for dense tag data failed" );
182  }
183 
184  if( !get_default_value() ) memset( mem, 0, get_size() * seq->data()->size() );
185  }
186 
187  ptr = reinterpret_cast< unsigned char* >( mem );
188  count = seq->data()->end_handle() - h + 1;
189  if( ptr ) ptr += get_size() * ( h - seq->data()->start_handle() );
190  return MB_SUCCESS;
191 }

References moab::SequenceData::allocate_tag_array(), moab::EntitySequence::data(), moab::SequenceData::end_handle(), moab::ent_not_found(), ErrorCode, moab::SequenceManager::find(), moab::TagInfo::get_default_value(), moab::TagInfo::get_name(), moab::TagInfo::get_size(), moab::SequenceData::get_tag_data(), MB_MEMORY_ALLOCATION_FAILED, MB_SET_ERR, MB_SUCCESS, meshValue, mySequenceArray, moab::SequenceData::size(), and moab::SequenceData::start_handle().

Referenced by clear_data(), get_array(), set_data(), and tag_iterate().

◆ get_data() [1/4]

ErrorCode moab::DenseTag::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 250 of file DenseTag.cpp.

256 {
257  ErrorCode result;
258  const EntityHandle* const end = entities + num_entities;
259  size_t junk = 0;
260  const unsigned char* ptr = NULL; // Initialize to get rid of warning
261 
262  if( data_lengths )
263  {
264  const int len = get_size();
265  SysUtil::setmem( data_lengths, &len, sizeof( int ), num_entities );
266  }
267 
268  for( const EntityHandle* i = entities; i != end; ++i, ++pointers )
269  {
270  result = get_array( seqman, NULL, *i, ptr, junk );
271  MB_CHK_ERR( result );
272 
273  if( ptr )
274  *pointers = ptr;
275  else if( get_default_value() )
276  *pointers = get_default_value();
277  else
278  return not_found( get_name(), *i );
279  }
280 
281  return MB_SUCCESS;
282 }

References ErrorCode, get_array(), moab::TagInfo::get_default_value(), moab::TagInfo::get_name(), moab::TagInfo::get_size(), MB_CHK_ERR, MB_SUCCESS, moab::not_found(), and moab::SysUtil::setmem().

◆ get_data() [2/4]

ErrorCode moab::DenseTag::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 193 of file DenseTag.cpp.

198 {
199  size_t junk = 0;
200  unsigned char* ptr = reinterpret_cast< unsigned char* >( adata );
201  const EntityHandle* const end = entities + num_entities;
202  for( const EntityHandle* i = entities; i != end; ++i, ptr += get_size() )
203  {
204  const unsigned char* data = 0;
205  MB_CHK_ERR( get_array( seqman, NULL, *i, data, junk ) );
206 
207  if( data )
208  memcpy( ptr, data, get_size() );
209  else if( get_default_value() )
210  memcpy( ptr, get_default_value(), get_size() );
211  else
212  return not_found( get_name(), *i );
213  }
214 
215  return MB_SUCCESS;
216 }

References get_array(), moab::TagInfo::get_default_value(), moab::TagInfo::get_name(), moab::TagInfo::get_size(), MB_CHK_ERR, MB_SUCCESS, and moab::not_found().

◆ get_data() [3/4]

ErrorCode moab::DenseTag::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 284 of file DenseTag.cpp.

289 {
290  size_t avail = 0;
291  const unsigned char* array = NULL;
292 
293  if( data_lengths )
294  {
295  int len = get_size();
296  SysUtil::setmem( data_lengths, &len, sizeof( int ), entities.size() );
297  }
298 
299  for( Range::const_pair_iterator p = entities.const_pair_begin(); p != entities.const_pair_end(); ++p )
300  {
301  EntityHandle start = p->first;
302  while( start <= p->second )
303  {
304  MB_CHK_ERR( get_array( seqman, NULL, start, array, avail ) );
305 
306  const size_t count = std::min< size_t >( p->second - start + 1, avail );
307  if( array )
308  {
309  for( EntityHandle end = start + count; start != end; ++start )
310  {
311  *pointers = array;
312  array += get_size();
313  ++pointers;
314  }
315  }
316  else if( const void* val = get_default_value() )
317  {
318  SysUtil::setmem( pointers, &val, sizeof( void* ), count );
319  pointers += count;
320  start += count;
321  }
322  else
323  {
324  return not_found( get_name(), start );
325  }
326  }
327  }
328 
329  return MB_SUCCESS;
330 }

References moab::Range::const_pair_begin(), moab::Range::const_pair_end(), get_array(), moab::TagInfo::get_default_value(), moab::TagInfo::get_name(), moab::TagInfo::get_size(), MB_CHK_ERR, MB_SUCCESS, moab::not_found(), moab::SysUtil::setmem(), and moab::Range::size().

◆ get_data() [4/4]

ErrorCode moab::DenseTag::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 218 of file DenseTag.cpp.

222 {
223  size_t avail = 0;
224  const unsigned char* array = NULL; // Initialize to get rid of warning
225  unsigned char* data = reinterpret_cast< unsigned char* >( values );
226 
227  for( Range::const_pair_iterator p = entities.const_pair_begin(); p != entities.const_pair_end(); ++p )
228  {
229  EntityHandle start = p->first;
230  while( start <= p->second )
231  {
232  MB_CHK_ERR( get_array( seqman, NULL, start, array, avail ) );
233 
234  const size_t count = std::min< size_t >( p->second - start + 1, avail );
235  if( array )
236  memcpy( data, array, get_size() * count );
237  else if( get_default_value() )
238  SysUtil::setmem( data, get_default_value(), get_size(), count );
239  else
240  return not_found( get_name(), start );
241 
242  data += get_size() * count;
243  start += count;
244  }
245  }
246 
247  return MB_SUCCESS;
248 }

References moab::Range::const_pair_begin(), moab::Range::const_pair_end(), get_array(), moab::TagInfo::get_default_value(), moab::TagInfo::get_name(), moab::TagInfo::get_size(), MB_CHK_ERR, MB_SUCCESS, moab::not_found(), and moab::SysUtil::setmem().

◆ get_memory_use()

ErrorCode moab::DenseTag::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 665 of file DenseTag.cpp.

668 {
669  per_entity = get_size();
670  total = TagInfo::get_memory_use() + sizeof( *this );
671  for( EntityType t = MBVERTEX; t <= MBENTITYSET; ++t )
672  {
673  const TypeSequenceManager& map = seqman->entity_map( t );
674  const SequenceData* prev_data = 0;
675  for( TypeSequenceManager::const_iterator i = map.begin(); i != map.end(); ++i )
676  {
677  if( ( *i )->data() != prev_data && ( *i )->data()->get_tag_data( mySequenceArray ) )
678  {
679  prev_data = ( *i )->data();
680  total += get_size() * ( *i )->data()->size();
681  }
682  }
683  }
684 
685  return MB_SUCCESS;
686 }

References moab::TypeSequenceManager::begin(), moab::TypeSequenceManager::end(), moab::SequenceManager::entity_map(), moab::TagInfo::get_memory_use(), moab::TagInfo::get_size(), moab::SequenceData::get_tag_data(), MB_SUCCESS, MBENTITYSET, MBVERTEX, and mySequenceArray.

◆ get_storage_type()

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

Implements moab::TagInfo.

Definition at line 57 of file DenseTag.cpp.

58 {
59  return MB_TAG_DENSE;
60 }

References MB_TAG_DENSE.

◆ get_tagged_entities()

ErrorCode moab::DenseTag::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 553 of file DenseTag.cpp.

557 {
558  Range tmp;
559  Range* entities = intersect_list ? &tmp : &entities_in;
560  Range::iterator hint = entities->begin();
561  std::pair< EntityType, EntityType > range = type_range( type );
563  for( EntityType t = range.first; t != range.second; ++t )
564  {
565  const TypeSequenceManager& map = seqman->entity_map( t );
566  for( i = map.begin(); i != map.end(); ++i )
567  if( ( *i )->data()->get_tag_data( mySequenceArray ) )
568  hint = entities->insert( hint, ( *i )->start_handle(), ( *i )->end_handle() );
569  }
570 
571  if( intersect_list ) entities_in = intersect( *entities, *intersect_list );
572 
573  return MB_SUCCESS;
574 }

References moab::Range::begin(), moab::TypeSequenceManager::begin(), moab::TypeSequenceManager::end(), moab::SequenceManager::entity_map(), moab::Range::insert(), moab::intersect(), MB_SUCCESS, mySequenceArray, and moab::type_range().

Referenced by num_tagged_entities().

◆ is_tagged()

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

Check if entity is tagged.

Implements moab::TagInfo.

Definition at line 658 of file DenseTag.cpp.

659 {
660  const unsigned char* ptr = NULL; // Initialize to get rid of warning
661  size_t count;
662  return ( MB_SUCCESS == get_array( seqman, 0, h, ptr, count ) ) && ( NULL != ptr );
663 }

References get_array(), and MB_SUCCESS.

◆ num_tagged_entities()

ErrorCode moab::DenseTag::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 576 of file DenseTag.cpp.

580 {
581  Range tmp;
582  ErrorCode rval = get_tagged_entities( seqman, tmp, type, intersect );
583  output_count += tmp.size();
584 
585  return rval;
586 }

References ErrorCode, get_tagged_entities(), moab::intersect(), and moab::Range::size().

◆ operator=()

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

◆ release_all_data()

ErrorCode moab::DenseTag::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 83 of file DenseTag.cpp.

84 {
85  ErrorCode result = seqman->release_tag_array( NULL, mySequenceArray, delete_pending );
86  if( MB_SUCCESS == result && delete_pending ) mySequenceArray = -1;
87  return result;
88 }

References ErrorCode, MB_SUCCESS, mySequenceArray, and moab::SequenceManager::release_tag_array().

◆ remove_data() [1/2]

ErrorCode moab::DenseTag::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 500 of file DenseTag.cpp.

504 {
505  std::vector< unsigned char > zeros;
506  const void* value = get_default_value();
507  if( !value )
508  {
509  zeros.resize( get_size(), 0 );
510  value = &zeros[0];
511  }
512 
513  return clear_data( false, seqman, NULL, entities, num_entities, value );
514 }

References clear_data(), moab::TagInfo::get_default_value(), and moab::TagInfo::get_size().

◆ remove_data() [2/2]

ErrorCode moab::DenseTag::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 516 of file DenseTag.cpp.

517 {
518  std::vector< unsigned char > zeros;
519  const void* value = get_default_value();
520  if( !value )
521  {
522  zeros.resize( get_size(), 0 );
523  value = &zeros[0];
524  }
525 
526  return clear_data( false, seqman, NULL, entities, value );
527 }

References clear_data(), moab::TagInfo::get_default_value(), and moab::TagInfo::get_size().

◆ set_data() [1/4]

ErrorCode moab::DenseTag::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 332 of file DenseTag.cpp.

337 {
338  const unsigned char* ptr = reinterpret_cast< const unsigned char* >( data );
339  const EntityHandle* const end = entities + num_entities;
340  unsigned char* array = NULL;
341  size_t junk = 0;
342 
343  for( const EntityHandle* i = entities; i != end; ++i, ptr += get_size() )
344  {
345  MB_CHK_ERR( get_array_private( seqman, NULL, *i, array, junk, true ) );
346 
347  memcpy( array, ptr, get_size() );
348  }
349 
350  return MB_SUCCESS;
351 }

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

◆ set_data() [2/4]

ErrorCode moab::DenseTag::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 376 of file DenseTag.cpp.

382 {
383  MB_CHK_ERR( validate_lengths( NULL, data_lengths, num_entities ) );
384 
385  const EntityHandle* const end = entities + num_entities;
386  unsigned char* array = NULL;
387  size_t junk = 0;
388 
389  for( const EntityHandle* i = entities; i != end; ++i, ++pointers )
390  {
391  MB_CHK_ERR( get_array_private( seqman, NULL, *i, array, junk, true ) );
392 
393  memcpy( array, *pointers, get_size() );
394  }
395 
396  return MB_SUCCESS;
397 }

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

◆ set_data() [3/4]

ErrorCode moab::DenseTag::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 353 of file DenseTag.cpp.

354 {
355  const char* data = reinterpret_cast< const char* >( values );
356  unsigned char* array = NULL;
357  size_t avail = 0;
358 
359  for( Range::const_pair_iterator p = entities.const_pair_begin(); p != entities.const_pair_end(); ++p )
360  {
361  EntityHandle start = p->first;
362  while( start <= p->second )
363  {
364  MB_CHK_ERR( get_array_private( seqman, NULL, start, array, avail, true ) );
365 
366  const size_t count = std::min< size_t >( p->second - start + 1, avail );
367  memcpy( array, data, get_size() * count );
368  data += get_size() * count;
369  start += count;
370  }
371  }
372 
373  return MB_SUCCESS;
374 }

References moab::Range::const_pair_begin(), moab::Range::const_pair_end(), get_array_private(), moab::TagInfo::get_size(), MB_CHK_ERR, and MB_SUCCESS.

◆ set_data() [4/4]

ErrorCode moab::DenseTag::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 399 of file DenseTag.cpp.

404 {
405  unsigned char* array = NULL;
406  size_t avail = 0;
407 
408  for( Range::const_pair_iterator p = entities.const_pair_begin(); p != entities.const_pair_end(); ++p )
409  {
410  EntityHandle start = p->first;
411  while( start <= p->second )
412  {
413  MB_CHK_ERR( get_array_private( seqman, NULL, start, array, avail, true ) );
414 
415  const EntityHandle end = std::min< EntityHandle >( p->second + 1, start + avail );
416  while( start != end )
417  {
418  memcpy( array, *pointers, get_size() );
419  ++start;
420  ++pointers;
421  array += get_size();
422  }
423  }
424  }
425 
426  return MB_SUCCESS;
427 }

References moab::Range::const_pair_begin(), moab::Range::const_pair_end(), get_array_private(), moab::TagInfo::get_size(), MB_CHK_ERR, and MB_SUCCESS.

◆ tag_iterate()

ErrorCode moab::DenseTag::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 529 of file DenseTag.cpp.

535 {
536  // If asked for nothing, successfully return nothing.
537  if( iter == end ) return MB_SUCCESS;
538 
539  unsigned char* array = NULL;
540  size_t avail = 0;
541  MB_CHK_ERR( get_array_private( seqman, NULL, *iter, array, avail, allocate ) );
542  data_ptr = array;
543 
544  size_t count = std::min< size_t >( avail, *( iter.end_of_block() ) - *iter + 1 );
545  if( 0 != *end && *end <= *( iter.end_of_block() ) )
546  iter = end;
547  else
548  iter += count;
549 
550  return MB_SUCCESS;
551 }

References moab::Range::const_iterator::end_of_block(), get_array_private(), MB_CHK_ERR, and MB_SUCCESS.

Member Data Documentation

◆ meshValue

unsigned char* moab::DenseTag::meshValue
private

Definition at line 25 of file DenseTag.hpp.

Referenced by get_array_private(), and ~DenseTag().

◆ mySequenceArray

int moab::DenseTag::mySequenceArray
private

Array index in SequenceManager used to store tag data.

Definition at line 23 of file DenseTag.hpp.

Referenced by find_entities_with_value(), get_array_private(), get_memory_use(), get_tagged_entities(), release_all_data(), and ~DenseTag().


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