moab
moab::VarLenTag Class Reference

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

#include <VarLenTag.hpp>

List of all members.

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. 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 129 of file VarLenTag.hpp.


Constructor & Destructor Documentation

Definition at line 133 of file VarLenTag.hpp.

{ mData.mData.mPointer.size = 0; }
moab::VarLenTag::VarLenTag ( unsigned  size) [inline]

Definition at line 199 of file VarLenTag.hpp.

{
#ifdef VAR_LEN_TAG_ELIDE_DATA
  if (sz > VarLenTagData::INLINE_COUNT) 
#endif
    mData.mData.mPointer.array = reinterpret_cast<unsigned char*>(malloc(sz));
  mData.mData.mPointer.size = sz;
}

Definition at line 135 of file VarLenTag.hpp.

{ clear(); }
moab::VarLenTag::VarLenTag ( const VarLenTag copy) [inline]

Definition at line 219 of file VarLenTag.hpp.

  : mData( copy.mData )
{
#ifdef VAR_LEN_TAG_ELIDE_DATA
  if (size() > VarLenTagData::INLINE_COUNT)
#endif
  {
    mData.mData.mPointer.array = reinterpret_cast<unsigned char*>(malloc(size()));
    memcpy( mData.mData.mPointer.array, copy.mData.mData.mPointer.array, size() );
  }
}
moab::VarLenTag::VarLenTag ( unsigned  size,
const void *  data 
) [inline]

Definition at line 231 of file VarLenTag.hpp.

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

Member Function Documentation

void moab::VarLenTag::clear ( ) [inline]

Definition at line 208 of file VarLenTag.hpp.

{
#ifdef VAR_LEN_TAG_ELIDE_DATA
  if (size() > VarLenTagData::INLINE_COUNT)
#else
  if (size())
#endif
    free( mData.mData.mPointer.array );
  mData.mData.mPointer.size = 0;
}
unsigned char* moab::VarLenTag::data ( ) [inline]

Definition at line 141 of file VarLenTag.hpp.

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

Definition at line 157 of file VarLenTag.hpp.

    { return const_cast<VarLenTag*>(this)->data(); }
unsigned long moab::VarLenTag::mem ( ) const [inline]

Definition at line 150 of file VarLenTag.hpp.

    { return size() <= VarLenTagData::INLINE_COUNT ? 0 : size(); }
VarLenTag& moab::VarLenTag::operator= ( const VarLenTag other) [inline]

Definition at line 167 of file VarLenTag.hpp.

    { set( other.data(), other.size() ); return *this; }
unsigned char * moab::VarLenTag::resize ( unsigned  size) [inline]

Definition at line 172 of file VarLenTag.hpp.

{
#ifdef VAR_LEN_TAG_ELIDE_DATA
  if (s <= VarLenTagData::INLINE_COUNT) {
    if (size() > VarLenTagData::INLINE_COUNT) {
      unsigned char* tmp_ptr = mData.mData.mPointer.array;
      memcpy( mData.mData.mInline.array, tmp_ptr, s );
      free( tmp_ptr );
    }
    mData.mData.mInline.size = s;
    return mData.mData.mInline.array;
  }
  else if (size() <= VarLenTagData::INLINE_COUNT) {
    void* tmp_ptr = malloc(s);
    memcpy( tmp_ptr, mData.mData.mInline.array, size() );
    mData.mData.mPointer.array = reinterpret_cast<unsigned char*>(tmp_ptr);
  }
  else 
#endif
  if (size() < s) {
    void* tmp_ptr = size() ? realloc( mData.mData.mPointer.array, s ) : malloc( s );
    mData.mData.mPointer.array = reinterpret_cast<unsigned char*>(tmp_ptr);
  }
  mData.mData.mPointer.size = s;
  return mData.mData.mPointer.array;
}
void moab::VarLenTag::set ( const void *  dat,
unsigned  sz 
) [inline]

Definition at line 164 of file VarLenTag.hpp.

    { memcpy( resize(sz), dat, sz ); }
unsigned moab::VarLenTag::size ( ) const [inline]

Definition at line 139 of file VarLenTag.hpp.

{ return mData.mData.mPointer.size; }

Member Data Documentation

Definition at line 131 of file VarLenTag.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines