mudbox::Array< type > Class Template Reference

#include <array.h>

Inheritance diagram for mudbox::Array< type >:

Inheritance graph
[legend]
List of all members.

Detailed Description

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

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

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

template<typename type>
mudbox::Array< type >::Array const char *  sName  )  [inline]
 
00066                                : Block( sName, sizeof(type) )
00067     { 
00068         m_bData = true; 
00069         m_iSize = 0; 
00070         m_pArray = 0; 
00071         m_pThis = this;
00072     };
template<typename type>
mudbox::Array< type >::Array const char *  sName,
unsigned int  iSize
[inline]
 
00073                                                    : Block( sName, sizeof(type) ) 
00074     { 
00075         m_bData = true; 
00076         m_iSize = iSize;
00077         m_pArray = 0;
00078         try
00079         {
00080             if ( RegisterMemoryBlock( sizeof(type)*iSize ) )
00081             {
00082                 SetAllocatorID( sName );
00083                 m_pArray = new type[iSize];
00084                 SetAllocatorID( 0 );
00085             }
00086             else
00087                 throw &Error::s_cBadAlloc;
00088         }
00089         catch ( ... )
00090         {
00091             LogAll();
00092             throw &Error::s_cBadAlloc;
00093         };
00094         m_pThis = this;
00095     };
template<typename type>
mudbox::Array< type >::Array const char *  sName,
const type *  pArray,
int  iSize
[inline]
 
00096                                                               : Block( sName, sizeof(type) )
00097     { 
00098         m_bData = true; 
00099         m_pArray = 0;
00100         try
00101         {
00102             if ( RegisterMemoryBlock( sizeof(type)*iSize ) )
00103             {
00104                 SetAllocatorID( sName );
00105                 m_pArray = new type[iSize];
00106                 SetAllocatorID( 0 );
00107             }
00108             else
00109                 Error::ThrowBadAlloc();
00110         }
00111         catch ( ... )
00112         {
00113             // probably std::bad_alloc
00114             LogAll();
00115             throw &Error::s_cBadAlloc;
00116         };
00117         if( !m_pArray )
00118             return;
00119 
00120         memcpy( m_pArray, pArray, sizeof(type)*iSize ); 
00121         m_iSize = iSize; 
00122         m_pThis = this;
00123     };
template<typename type>
mudbox::Array< type >::Array const char *  sName,
bool  bNoObjects
[inline]
 
00124                                                 : Block( sName, sizeof(type) )
00125     { 
00126         m_bData = bNoObjects; 
00127         m_iSize = 0; 
00128         m_pArray = 0; 
00129         m_pThis = this;
00130     };
template<typename type>
mudbox::Array< type >::Array const char *  sName,
const Array< type > &  a
[inline]
 
00131                                                      : Block( sName, sizeof(type) )
00132     { 
00133         m_bData = true; 
00134         m_pArray = a.m_pArray; 
00135         m_iSize = a.m_iSize; 
00136         a.m_iSize = 0; 
00137         a.m_pArray = 0; 
00138         m_pThis = this;
00139     };
template<typename type>
mudbox::Array< type >::~Array void   )  [inline]
 
00253 { MB_ASSERT( m_pThis == this ); Clear(); };

Member Function Documentation

template<typename type>
void mudbox::Array< type >::Clear bool  bDestruct = false  )  [inline]
 

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

00141     { 
00142         bDestruct = bDestruct;
00143 
00144         if ( m_pArray ) 
00145         {   
00146             UnregisterMemoryBlock( (long long)(sizeof(type)*m_iSize) );
00147 //          if ( bDestruct )
00148                 delete [] m_pArray; 
00149 //          else
00150 //              delete m_pArray;
00151             m_pArray = 0; 
00152         }; 
00153         m_iSize = 0; 
00154     };
template<typename type>
Array<type> mudbox::Array< type >::Clone void   )  const [inline]
 

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

00155 { Array<type> a; Copy( a ); return a; };
template<typename type>
bool mudbox::Array< type >::Copy Array< type > &  a  )  const [inline]
 
00157     { 
00158         if ( !a.Alloc( m_iSize ) )
00159             return false; 
00160         memcpy( a.m_pArray, m_pArray, sizeof(type)*a.m_iSize ); 
00161         return true;
00162     };
template<typename type>
void mudbox::Array< type >::Set unsigned int  iStart,
unsigned int  iSize,
unsigned char  cPattern
[inline]
 
00163 { MB_ASSERT( m_pThis == this ); MB_ASSERT( iStart+iSize <= m_iSize ); memset( m_pArray+iStart, int(cPattern), sizeof(type)*iSize ); };
template<typename type>
bool mudbox::Array< type >::Extend unsigned int  iElementIndex  )  [inline]
 

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

00165     {
00166         if ( iElementIndex == 0xffffffff )
00167             return true;
00168         unsigned int iNewSize = m_iSize;
00169         while ( iElementIndex >= iNewSize )
00170             iNewSize = iNewSize*2+1;
00171         if( iNewSize > m_iSize )
00172             return Alloc( iNewSize );
00173         return true;
00174     };
template<typename type>
bool mudbox::Array< type >::Alloc unsigned int  iNewSize  )  [inline]
 
00176     {
00177         if ( iNewSize == m_iSize )
00178             return true;
00179         MB_ASSERT( m_pThis == this ); 
00180         type *pNew = 0;
00181         try
00182         {
00183             if ( RegisterMemoryBlock( sizeof(type)*iNewSize ) )
00184             {
00185                 SetAllocatorID( m_sName );
00186                 pNew = new type[iNewSize];
00187                 SetAllocatorID( 0 );
00188             }
00189             else
00190                 throw &Error::s_cBadAlloc;      
00191         }
00192         catch ( Error * )
00193         {
00194             LogAll();
00195             return false;
00196         }
00197         catch ( ... )
00198         {
00199             // probably std::bad_alloc
00200             LogAll();
00201             throw &Error::s_cBadAlloc;
00202         };
00203         if( pNew == 0 )
00204             return false;
00205         if( m_iSize )
00206         {
00207             UnregisterMemoryBlock( sizeof(type)*m_iSize );
00208             if ( m_bData )          
00209                 CopyMemoryBlock( pNew, m_pArray, Min( iNewSize, m_iSize )*sizeof(type) );
00210             else
00211                 for ( unsigned int i = 0; i < Min( iNewSize, m_iSize ); i++ )
00212                     pNew[i] = m_pArray[i];
00213             delete [] m_pArray;
00214         };
00215         m_pArray = pNew;
00216         m_iSize = iNewSize;
00217         return true;
00218     };
template<typename type>
type& mudbox::Array< type >::operator[] int  iIndex  )  [inline]
 

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

00221     { 
00222         MB_ASSERT( m_pThis == this ); 
00223         MB_ONBUG( (unsigned int)(iIndex) >= m_iSize )
00224             return m_pArray[0];
00225         return m_pArray[iIndex]; 
00226     };
template<typename type>
type& mudbox::Array< type >::operator[] unsigned int  iIndex  )  [inline]
 

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

00228     { 
00229         MB_ASSERT( m_pThis == this ); 
00230         MB_ONBUG( iIndex >= m_iSize ) 
00231             return m_pArray[0];
00232         return m_pArray[iIndex];
00233     };
template<typename type>
const type& mudbox::Array< type >::operator[] unsigned int  iIndex  )  const [inline]
 

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

00235     { 
00236         MB_ASSERT( m_pThis == this ); 
00237         MB_ONBUG( iIndex >= m_iSize )
00238             return m_pArray[0];
00239         return m_pArray[iIndex]; 
00240     };
template<typename type>
type* mudbox::Array< type >::operator+ unsigned int  iIndex  )  [inline]
 

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

00241 { MB_ASSERT( m_pThis == this ); return &operator[]( iIndex ); };
template<typename type>
type* mudbox::Array< type >::operator+ int  iIndex  )  [inline]
 

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

00242 { MB_ASSERT( m_pThis == this ); return &operator[]( iIndex ); };
template<typename type>
void mudbox::Array< type >::operator= const Array< type > &  a  )  [inline]
 
00243 { 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; };
template<typename type>
virtual long long mudbox::Array< type >::MemoryUsage void   )  const [inline, virtual]
 
00254 { return m_iSize*sizeof(type); };

Friends And Related Function Documentation

template<typename type>
friend class Block [friend]
 

Member Data Documentation

template<typename type>
type* mudbox::Array< type >::m_pArray [mutable, protected]
 
template<typename type>
unsigned int mudbox::Array< type >::m_iSize [mutable, protected]
 

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

template<typename type>
bool mudbox::Array< type >::m_bData [mutable, protected]
 
template<typename type>
const Array<type>* mudbox::Array< type >::m_pThis [mutable, protected]