Mesh Oriented datABase  (version 5.5.1)
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 433 of file DenseTag.cpp.

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

References entities, ErrorCode, 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 456 of file DenseTag.cpp.

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

References entities, ErrorCode, 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 483 of file DenseTag.cpp.

489 {
490  if( value_len && value_len != get_size() ) return MB_INVALID_SIZE;
491 
492  return clear_data( true, seqman, NULL, entities, num_entities, value_ptr );
493 }

References entities, 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 495 of file DenseTag.cpp.

500 {
501  if( value_len && value_len != get_size() ) return MB_INVALID_SIZE;
502 
503  return clear_data( true, seqman, NULL, entities, value_ptr );
504 }

References clear_data(), entities, 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(), 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 594 of file DenseTag.cpp.

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

References moab::Range::begin(), moab::TypeSequenceManager::begin(), moab::Range::const_pair_end(), moab::ByteArrayIterator::data, moab::TypeSequenceManager::end(), moab::SequenceManager::entity_map(), ErrorCode, 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 251 of file DenseTag.cpp.

257 {
258  ErrorCode result;
259  const EntityHandle* const end = entities + num_entities;
260  size_t junk = 0;
261  const unsigned char* ptr = NULL; // Initialize to get rid of warning
262 
263  if( data_lengths )
264  {
265  const int len = get_size();
266  SysUtil::setmem( data_lengths, &len, sizeof( int ), num_entities );
267  }
268 
269  for( const EntityHandle* i = entities; i != end; ++i, ++pointers )
270  {
271  result = get_array( seqman, NULL, *i, ptr, junk );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 entities, 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  ErrorCode rval = get_array( seqman, NULL, *i, data, junk );MB_CHK_ERR( rval );
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 entities, ErrorCode, 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  ErrorCode rval;
291  size_t avail = 0;
292  const unsigned char* array = NULL;
293 
294  if( data_lengths )
295  {
296  int len = get_size();
297  SysUtil::setmem( data_lengths, &len, sizeof( int ), entities.size() );
298  }
299 
300  for( Range::const_pair_iterator p = entities.const_pair_begin(); p != entities.const_pair_end(); ++p )
301  {
302  EntityHandle start = p->first;
303  while( start <= p->second )
304  {
305  rval = get_array( seqman, NULL, start, array, avail );MB_CHK_ERR( rval );
306 
307  const size_t count = std::min< size_t >( p->second - start + 1, avail );
308  if( array )
309  {
310  for( EntityHandle end = start + count; start != end; ++start )
311  {
312  *pointers = array;
313  array += get_size();
314  ++pointers;
315  }
316  }
317  else if( const void* val = get_default_value() )
318  {
319  SysUtil::setmem( pointers, &val, sizeof( void* ), count );
320  pointers += count;
321  start += count;
322  }
323  else
324  {
325  return not_found( get_name(), start );
326  }
327  }
328  }
329 
330  return MB_SUCCESS;
331 }

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

References entities, 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_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 672 of file DenseTag.cpp.

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

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 559 of file DenseTag.cpp.

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

References moab::TypeSequenceManager::begin(), moab::TypeSequenceManager::end(), entities, moab::SequenceManager::entity_map(), 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 665 of file DenseTag.cpp.

666 {
667  const unsigned char* ptr = NULL; // Initialize to get rid of warning
668  size_t count;
669  return ( MB_SUCCESS == get_array( seqman, 0, h, ptr, count ) ) && ( NULL != ptr );
670 }

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 582 of file DenseTag.cpp.

586 {
587  Range tmp;
588  ErrorCode rval = get_tagged_entities( seqman, tmp, type, intersect );
589  output_count += tmp.size();
590 
591  return rval;
592 }

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 506 of file DenseTag.cpp.

510 {
511  std::vector< unsigned char > zeros;
512  const void* value = get_default_value();
513  if( !value )
514  {
515  zeros.resize( get_size(), 0 );
516  value = &zeros[0];
517  }
518 
519  return clear_data( false, seqman, NULL, entities, num_entities, value );
520 }

References clear_data(), entities, 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 522 of file DenseTag.cpp.

523 {
524  std::vector< unsigned char > zeros;
525  const void* value = get_default_value();
526  if( !value )
527  {
528  zeros.resize( get_size(), 0 );
529  value = &zeros[0];
530  }
531 
532  return clear_data( false, seqman, NULL, entities, value );
533 }

References clear_data(), entities, 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 333 of file DenseTag.cpp.

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

References entities, ErrorCode, 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 379 of file DenseTag.cpp.

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

References entities, ErrorCode, 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 355 of file DenseTag.cpp.

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

References entities, ErrorCode, 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 402 of file DenseTag.cpp.

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

References entities, ErrorCode, 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 535 of file DenseTag.cpp.

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

References moab::Range::const_iterator::end_of_block(), ErrorCode, 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: