Array< type > Class Template Reference


Detailed Description

template<typename type>
class mudbox::Array< type >

An internal helper class, representing an array. Use the Store class instead.

Definition at line 59 of file array.h.

#include <array.h>

Inheritance diagram for Array< type >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

  Array (const char *sName)
  Array (const char *sName, unsigned int iSize)
  Array (const char *sName, const type *pArray, int iSize)
  Array (const char *sName, bool bNoObjects)
  Array (const char *sName, const Array< type > &a)
void  Clear (bool bDestruct=false)
Array< type >  Clone (void) const
bool  Copy (Array< type > &a) const
void  Set (unsigned int iStart, unsigned int iSize, unsigned char cPattern)
bool  Extend (unsigned int iElementIndex)
bool  Alloc (unsigned int iNewSize)
type &  operator[] (int iIndex)
type &  operator[] (unsigned int iIndex)
const type &  operator[] (unsigned int iIndex) const
type *  operator+ (unsigned int iIndex)
type *  operator+ (int iIndex)
void  operator= (const Array< type > &a)
  ~Array (void)
virtual long long  MemoryUsage (void) const

Protected Attributes

type *  m_pArray
unsigned int  m_iSize
bool  m_bData
const Array< type > *  m_pThis

Friends

class  Block

Constructor & Destructor Documentation

Array ( const char *  sName ) [inline]

Definition at line 63 of file array.h.

                               : Block( sName, sizeof(type) )
    { 
        m_bData = true; 
        m_iSize = 0; 
        m_pArray = 0; 
        m_pThis = this;
    };
Array ( const char *  sName,
unsigned int  iSize 
) [inline]

Definition at line 70 of file array.h.

                                                   : Block( sName, sizeof(type) ) 
    { 
        m_bData = true; 
        m_iSize = iSize;
        m_pArray = 0;
        try
        {
            if ( RegisterMemoryBlock( sizeof(type)*iSize ) )
            {
                SetAllocatorID( sName );
                m_pArray = new type[iSize];
                SetAllocatorID( 0 );
            }
            else
                throw &Error::s_cBadAlloc;
        }
        catch ( ... )
        {
            LogAll();
            throw &Error::s_cBadAlloc;
        };
        m_pThis = this;
    };
Array ( const char *  sName,
const type *  pArray,
int  iSize 
) [inline]

Definition at line 93 of file array.h.

                                                              : Block( sName, sizeof(type) )
    { 
        m_bData = true; 
        m_pArray = 0;
        try
        {
            if ( RegisterMemoryBlock( sizeof(type)*iSize ) )
            {
                SetAllocatorID( sName );
                m_pArray = new type[iSize];
                SetAllocatorID( 0 );
            }
            else
                Error::ThrowBadAlloc();
        }
        catch ( ... )
        {
            // probably std::bad_alloc
            LogAll();
            throw &Error::s_cBadAlloc;
        };
        if( !m_pArray )
            return;

        memcpy( m_pArray, pArray, sizeof(type)*iSize ); 
        m_iSize = iSize; 
        m_pThis = this;
    };
Array ( const char *  sName,
bool  bNoObjects 
) [inline]

Definition at line 121 of file array.h.

                                                : Block( sName, sizeof(type) )
    { 
        m_bData = bNoObjects; 
        m_iSize = 0; 
        m_pArray = 0; 
        m_pThis = this;
    };
Array ( const char *  sName,
const Array< type > &  a 
) [inline]

Definition at line 128 of file array.h.

                                                     : Block( sName, sizeof(type) )
    { 
        m_bData = true; 
        m_pArray = a.m_pArray; 
        m_iSize = a.m_iSize; 
        a.m_iSize = 0; 
        a.m_pArray = 0; 
        m_pThis = this;
    };
~Array ( void  ) [inline]

Definition at line 250 of file array.h.

{ MB_ASSERT( m_pThis == this ); Clear(); };

Member Function Documentation

void Clear ( bool  bDestruct = false ) [inline]

Reimplemented in Store< type >, Store< TC >, Store< Attribute * >, Store< Vector >, Store< ChordLength >, Store< float >, Store< QString >, Store< mudbox::Vector >, Store< unsigned int >, Store< VertexChange >, Store< Vertex >, Store< unsigned char >, and Store< BrushConfiguration * >.

Definition at line 137 of file array.h.

    { 
        bDestruct = bDestruct;

        if ( m_pArray ) 
        {   
            UnregisterMemoryBlock( (long long)(sizeof(type)*m_iSize) );
//          if ( bDestruct )
                delete [] m_pArray; 
//          else
//              delete m_pArray;
            m_pArray = 0; 
        }; 
        m_iSize = 0; 
    };
bool Copy ( Array< type > &  a ) const [inline]

Definition at line 153 of file array.h.

    { 
        if ( !a.Alloc( m_iSize ) )
            return false; 
        memcpy( a.m_pArray, m_pArray, sizeof(type)*a.m_iSize ); 
        return true;
    };
void Set ( unsigned int  iStart,
unsigned int  iSize,
unsigned char  cPattern 
) [inline]

Definition at line 160 of file array.h.

{ MB_ASSERT( m_pThis == this ); MB_ASSERT( iStart+iSize <= m_iSize ); memset( m_pArray+iStart, int(cPattern), sizeof(type)*iSize ); };
bool Extend ( unsigned int  iElementIndex ) [inline]

Reimplemented in Store< type >, Store< TC >, Store< Attribute * >, Store< Vector >, Store< ChordLength >, Store< float >, Store< QString >, Store< mudbox::Vector >, Store< unsigned int >, Store< VertexChange >, Store< Vertex >, Store< unsigned char >, and Store< BrushConfiguration * >.

Definition at line 161 of file array.h.

    {
        if ( iElementIndex == 0xffffffff )
            return true;
        unsigned int iNewSize = m_iSize;
        while ( iElementIndex >= iNewSize )
            iNewSize = iNewSize*2+1;
        if( iNewSize > m_iSize )
            return Alloc( iNewSize );
        return true;
    };
bool Alloc ( unsigned int  iNewSize ) [inline]

Definition at line 172 of file array.h.

    {
        if ( iNewSize == m_iSize )
            return true;
        MB_ASSERT( m_pThis == this ); 
        type *pNew = 0;
        try
        {
            if ( RegisterMemoryBlock( sizeof(type)*iNewSize ) )
            {
                SetAllocatorID( m_sName );
                pNew = new type[iNewSize];
                SetAllocatorID( 0 );
            }
            else
                throw &Error::s_cBadAlloc;      
        }
        catch ( Error * )
        {
            LogAll();
            return false;
        }
        catch ( ... )
        {
            // probably std::bad_alloc
            LogAll();
            throw &Error::s_cBadAlloc;
        };
        if( pNew == 0 )
            return false;
        if( m_iSize )
        {
            UnregisterMemoryBlock( sizeof(type)*m_iSize );
            if ( m_bData )          
                CopyMemoryBlock( pNew, m_pArray, Min( iNewSize, m_iSize )*sizeof(type) );
            else
                for ( unsigned int i = 0; i < Min( iNewSize, m_iSize ); i++ )
                    pNew[i] = m_pArray[i];
            delete [] m_pArray;
        };
        m_pArray = pNew;
        m_iSize = iNewSize;
        return true;
    };
type& operator[] ( int  iIndex ) [inline]
type& operator[] ( unsigned int  iIndex ) [inline]
const type& operator[] ( unsigned int  iIndex ) const [inline]
void operator= ( const Array< type > &  a ) [inline]

Definition at line 240 of file array.h.

{ MB_ASSERT( m_pThis == this && a.m_pThis == &a ); Clear(); m_iSize = a.m_iSize; m_pArray = a.m_pArray; a.m_iSize = 0; a.m_pArray = 0; };
virtual long long MemoryUsage ( void  ) const [inline, virtual]

Definition at line 251 of file array.h.

{ return m_iSize*sizeof(type); };

Friends And Related Function Documentation

friend class Block [friend]

Definition at line 61 of file array.h.


Member Data Documentation

type* m_pArray [mutable, protected]

Definition at line 240 of file array.h.

bool m_bData [mutable, protected]

Definition at line 246 of file array.h.

const Array<type>* m_pThis [mutable, protected]

Definition at line 247 of file array.h.


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