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

Class for storing variable-length tag data. More...

#include <VarLenTag.hpp>

+ Collaboration diagram for moab::VarLenTag:

Public Member Functions

 VarLenTag ()
 
 VarLenTag (unsigned size)
 
 ~VarLenTag ()
 
 VarLenTag (const VarLenTag &copy)
 
 VarLenTag (unsigned size, const void *data)
 
unsigned size () const
 
unsigned char * data ()
 
unsigned long mem () const
 
const unsigned char * data () const
 
unsigned char * resize (unsigned size)
 
void clear ()
 
void set (const void *dat, unsigned sz)
 
VarLenTagoperator= (const VarLenTag &other)
 

Protected Attributes

VarLenTagData mData
 

Detailed Description

Class for storing variable-length tag data.

Class for managing variable-length tag data. \NOTE This class must behave as if it were initialized to empty if it is memset to zero w/out invoking any constructor.

Definition at line 152 of file VarLenTag.hpp.

Constructor & Destructor Documentation

◆ VarLenTag() [1/4]

moab::VarLenTag::VarLenTag ( )
inline

Definition at line 158 of file VarLenTag.hpp.

159  {
160  mData.mData.mPointer.size = 0;
161  }

References moab::VarLenTagData::mData, mData, and moab::VarLenTagData::mPointer.

◆ VarLenTag() [2/4]

moab::VarLenTag::VarLenTag ( unsigned  size)
inline

Definition at line 249 of file VarLenTag.hpp.

250 {
251 #ifdef VAR_LEN_TAG_ELIDE_DATA
252  if( sz > VarLenTagData::INLINE_COUNT )
253 #endif
254  mData.mData.mPointer.array = reinterpret_cast< unsigned char* >( malloc( sz ) );
255  mData.mData.mPointer.size = sz;
256 }

References moab::VarLenTagData::INLINE_COUNT, moab::VarLenTagData::mData, mData, and moab::VarLenTagData::mPointer.

◆ ~VarLenTag()

moab::VarLenTag::~VarLenTag ( )
inline

Definition at line 163 of file VarLenTag.hpp.

164  {
165  clear();
166  }

References clear().

◆ VarLenTag() [3/4]

moab::VarLenTag::VarLenTag ( const VarLenTag copy)
inline

Definition at line 269 of file VarLenTag.hpp.

269  : mData( copy.mData )
270 {
271 #ifdef VAR_LEN_TAG_ELIDE_DATA
273 #endif
274  {
275  mData.mData.mPointer.array = reinterpret_cast< unsigned char* >( malloc( size() ) );
276  memcpy( mData.mData.mPointer.array, copy.mData.mData.mPointer.array, size() );
277  }
278 }

References moab::VarLenTagData::INLINE_COUNT, moab::VarLenTagData::mData, mData, moab::VarLenTagData::mPointer, and size().

◆ VarLenTag() [4/4]

moab::VarLenTag::VarLenTag ( unsigned  size,
const void *  data 
)
inline

Definition at line 280 of file VarLenTag.hpp.

281 {
282  mData.mData.mPointer.size = 0;
283  if( sz ) memcpy( resize( sz ), dat, sz );
284 }

References moab::VarLenTagData::mData, mData, moab::VarLenTagData::mPointer, and resize().

Member Function Documentation

◆ clear()

void moab::VarLenTag::clear ( )
inline

Definition at line 258 of file VarLenTag.hpp.

259 {
260 #ifdef VAR_LEN_TAG_ELIDE_DATA
262 #else
263  if( size() )
264 #endif
265  free( mData.mData.mPointer.array );
266  mData.mData.mPointer.size = 0;
267 }

References moab::VarLenTagData::INLINE_COUNT, moab::VarLenTagData::mData, mData, moab::VarLenTagData::mPointer, and size().

Referenced by moab::SequenceData::release_tag_data(), moab::VarLenDenseTag::remove_data(), and ~VarLenTag().

◆ data() [1/2]

◆ data() [2/2]

const unsigned char* moab::VarLenTag::data ( ) const
inline

Definition at line 197 of file VarLenTag.hpp.

198  {
199  return const_cast< VarLenTag* >( this )->data();
200  }

References data().

◆ mem()

unsigned long moab::VarLenTag::mem ( ) const
inline

Definition at line 186 of file VarLenTag.hpp.

188  {
189  return size() <= VarLenTagData::INLINE_COUNT ? 0 : size();
190  }

References moab::VarLenTagData::INLINE_COUNT, and size().

Referenced by moab::VarLenDenseTag::get_memory_use().

◆ operator=()

VarLenTag& moab::VarLenTag::operator= ( const VarLenTag other)
inline

Definition at line 211 of file VarLenTag.hpp.

212  {
213  set( other.data(), other.size() );
214  return *this;
215  }

References data(), set(), and size().

◆ resize()

unsigned char * moab::VarLenTag::resize ( unsigned  size)
inline

Definition at line 218 of file VarLenTag.hpp.

219 {
220 #ifdef VAR_LEN_TAG_ELIDE_DATA
221  if( s <= VarLenTagData::INLINE_COUNT )
222  {
224  {
225  unsigned char* tmp_ptr = mData.mData.mPointer.array;
226  memcpy( mData.mData.mInline.array, tmp_ptr, s );
227  free( tmp_ptr );
228  }
229  mData.mData.mInline.size = s;
230  return mData.mData.mInline.array;
231  }
232  else if( size() <= VarLenTagData::INLINE_COUNT )
233  {
234  void* tmp_ptr = malloc( s );
235  memcpy( tmp_ptr, mData.mData.mInline.array, size() );
236  mData.mData.mPointer.array = reinterpret_cast< unsigned char* >( tmp_ptr );
237  }
238  else
239 #endif
240  if( size() < s )
241  {
242  void* tmp_ptr = size() ? realloc( mData.mData.mPointer.array, s ) : malloc( s );
243  mData.mData.mPointer.array = reinterpret_cast< unsigned char* >( tmp_ptr );
244  }
245  mData.mData.mPointer.size = s;
246  return mData.mData.mPointer.array;
247 }

References moab::VarLenTagData::INLINE_COUNT, moab::VarLenTagData::mData, mData, moab::VarLenTagData::mInline, moab::VarLenTagData::mPointer, and size().

Referenced by set(), and VarLenTag().

◆ set()

void moab::VarLenTag::set ( const void *  dat,
unsigned  sz 
)
inline

Definition at line 206 of file VarLenTag.hpp.

207  {
208  memcpy( resize( sz ), dat, sz );
209  }

References resize().

Referenced by operator=(), and moab::VarLenDenseTag::set_data().

◆ size()

Member Data Documentation

◆ mData

VarLenTagData moab::VarLenTag::mData
protected

Definition at line 155 of file VarLenTag.hpp.

Referenced by clear(), data(), resize(), size(), and VarLenTag().


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