Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
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. 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

Definition at line 158 of file VarLenTag.hpp.

References moab::VarLenTagData::mData.

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

Definition at line 249 of file VarLenTag.hpp.

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

{
#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 163 of file VarLenTag.hpp.

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

Definition at line 269 of file VarLenTag.hpp.

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

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

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

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

Member Function Documentation

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

Definition at line 258 of file VarLenTag.hpp.

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

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

{
#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;
}
const unsigned char* moab::VarLenTag::data ( ) const [inline]

Definition at line 197 of file VarLenTag.hpp.

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

Definition at line 211 of file VarLenTag.hpp.

References data(), and size().

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

Definition at line 218 of file VarLenTag.hpp.

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

Referenced by VarLenTag().

{
#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 206 of file VarLenTag.hpp.

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

    {
        memcpy( resize( sz ), dat, sz );
    }

Member Data Documentation

Definition at line 155 of file VarLenTag.hpp.

Referenced by VarLenTag().

List of all members.


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