Array< type > Class Template Reference

Array< type > Class Template Reference

#include <array.h>

Class Description

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

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

Definition at line 65 of file array.h.

+ Inheritance diagram for Array< type >:

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< typeClone (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)
 
typeoperator[] (int iIndex)
 
typeoperator[] (unsigned int iIndex)
 
const typeoperator[] (unsigned int iIndex) const
 
typeindexedAddr (unsigned int i)
 
const typeindexedAddr (unsigned int i) const
 
typebaseAddr ()
 
const typebaseAddr () const
 
void operator= (const Array< type > &a)
 
 ~Array (void)
 
- Public Member Functions inherited from Block
const BlockNext (void) const
 
unsigned int ItemSize (void) const
 
const char * Name (void) const
 
long long Size (void) const
 
long long Address (void) const
 
void Check (void) const
 

Protected Attributes

typem_pArray
 
unsigned int m_iSize
 
bool m_bData
 
const Array< type > * m_pThis
 
- Protected Attributes inherited from Block
Blockm_pNext
 
Blockm_pPrev
 
unsigned int m_iItemSize
 

Friends

class Block
 

Additional Inherited Members

- Static Public Member Functions inherited from Block
static const BlockHead (void)
 
static void LogAll (float fSizeFilter=0.01f, bool bSortByAddress=false)
 
static void CheckAll (void)
 
static bool RegisterMemoryBlock (long long iSize)
 
static bool UnregisterMemoryBlock (long long iSize)
 
static void SetAllocatorID (const char *pAllocatorID)
 
static void CopyMemoryBlock (void *pDestination, const void *pSource, long long iSize)
 
static voidAlignedAlloc (size_t iBytes, unsigned int iAlignment)
 
static void AlignedFree (void *pData)
 
- Public Attributes inherited from Block
const char * m_sName
 
- Protected Member Functions inherited from Block
 Block (const char *sName, unsigned int iItemSize)
 
 ~Block (void)
 
- Static Protected Attributes inherited from Block
static Blocks_pHead
 

Constructor & Destructor Documentation

Array ( const char *  sName)
inline

Definition at line 69 of file array.h.

69  : Block( sName, sizeof(type) )
70  {
71  m_bData = true;
72  m_iSize = 0;
73  m_pArray = 0;
74  m_pThis = this;
75  };
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
type * m_pArray
Definition: array.h:266
friend class Block
Definition: array.h:67
bool m_bData
Definition: array.h:271
unsigned int m_iSize
Definition: array.h:270
const Array< type > * m_pThis
Definition: array.h:272
Array ( const char *  sName,
unsigned int  iSize 
)
inline

Definition at line 76 of file array.h.

76  : Block( sName, sizeof(type) )
77  {
78  m_bData = true;
79  m_iSize = iSize;
80  m_pArray = 0;
81  try
82  {
83  if ( RegisterMemoryBlock( sizeof(type)*iSize ) )
84  {
85  SetAllocatorID( sName );
86  m_pArray = new type[iSize];
87  SetAllocatorID( 0 );
88  }
89  else
90  throw &Error::s_cBadAlloc;
91  }
92  catch ( ... )
93  {
94  LogAll();
95  throw &Error::s_cBadAlloc;
96  };
97  m_pThis = this;
98  };
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
type * m_pArray
Definition: array.h:266
friend class Block
Definition: array.h:67
bool m_bData
Definition: array.h:271
unsigned int m_iSize
Definition: array.h:270
static void SetAllocatorID(const char *pAllocatorID)
static Error s_cBadAlloc
Definition: error.h:112
static bool RegisterMemoryBlock(long long iSize)
static void LogAll(float fSizeFilter=0.01f, bool bSortByAddress=false)
const Array< type > * m_pThis
Definition: array.h:272
Array ( const char *  sName,
const type pArray,
int  iSize 
)
inline

Definition at line 99 of file array.h.

99  : Block( sName, sizeof(type) )
100  {
101  m_bData = true;
102  m_pArray = 0;
103  try
104  {
105  if ( RegisterMemoryBlock( sizeof(type)*iSize ) )
106  {
107  SetAllocatorID( sName );
108  m_pArray = new type[iSize];
109  SetAllocatorID( 0 );
110  }
111  else
113  }
114  catch ( ... )
115  {
116  // probably std::bad_alloc
117  LogAll();
118  throw &Error::s_cBadAlloc;
119  };
120  if ( !m_pArray )
121  return;
122 
123  memcpy( m_pArray, pArray, sizeof(type)*iSize );
124  m_iSize = iSize;
125  m_pThis = this;
126  };
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
type * m_pArray
Definition: array.h:266
friend class Block
Definition: array.h:67
bool m_bData
Definition: array.h:271
unsigned int m_iSize
Definition: array.h:270
static void SetAllocatorID(const char *pAllocatorID)
static Error s_cBadAlloc
Definition: error.h:112
static bool RegisterMemoryBlock(long long iSize)
static void LogAll(float fSizeFilter=0.01f, bool bSortByAddress=false)
const Array< type > * m_pThis
Definition: array.h:272
static void ThrowBadAlloc(void)
Throws a static bad alloc exception. (No memory allocation is required to report allocation problems...
Definition: error.h:112
Array ( const char *  sName,
bool  bNoObjects 
)
inline

Definition at line 128 of file array.h.

128  : Block( sName, sizeof(type) )
129  {
130  m_bData = bNoObjects;
131  m_iSize = 0;
132  m_pArray = 0;
133  m_pThis = this;
134  };
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
type * m_pArray
Definition: array.h:266
friend class Block
Definition: array.h:67
bool m_bData
Definition: array.h:271
unsigned int m_iSize
Definition: array.h:270
const Array< type > * m_pThis
Definition: array.h:272
Array ( const char *  sName,
const Array< type > &  a 
)
inline

Definition at line 136 of file array.h.

136  : Block( sName, sizeof(type) )
137  {
138  m_bData = true;
139  m_pArray = a.m_pArray;
140  m_iSize = a.m_iSize;
141  a.m_iSize = 0;
142  a.m_pArray = 0;
143  m_pThis = this;
144  };
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
type * m_pArray
Definition: array.h:266
friend class Block
Definition: array.h:67
bool m_bData
Definition: array.h:271
unsigned int m_iSize
Definition: array.h:270
const Array< type > * m_pThis
Definition: array.h:272
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
~Array ( void  )
inline

Definition at line 282 of file array.h.

282 { MB_ASSERT( m_pThis == this ); Clear(); };
#define MB_ASSERT(condition)
Definition: mudbox.h:73
void Clear(bool bDestruct=false)
Definition: array.h:146
const Array< type > * m_pThis
Definition: array.h:272

Member Function Documentation

void Clear ( bool  bDestruct = false)
inline

Definition at line 146 of file array.h.

147  {
148  bDestruct = bDestruct;
149 
150  if ( m_pArray )
151  {
152  UnregisterMemoryBlock( (long long)(sizeof(type)*m_iSize) );
153 // if ( bDestruct )
154  delete [] m_pArray;
155 // else
156 // delete m_pArray;
157  m_pArray = 0;
158  };
159  m_iSize = 0;
160  };
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
type * m_pArray
Definition: array.h:266
static bool UnregisterMemoryBlock(long long iSize)
unsigned int m_iSize
Definition: array.h:270
Array<type> Clone ( void  ) const
inline

Definition at line 162 of file array.h.

162 { Array<type> a; Copy( a ); return a; };
bool Copy(Array< type > &a) const
Definition: array.h:164
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
bool Copy ( Array< type > &  a) const
inline

Definition at line 164 of file array.h.

165  {
166  if ( !a.Alloc( m_iSize ) )
167  return false;
168  memcpy( a.m_pArray, m_pArray, sizeof(type)*a.m_iSize );
169  return true;
170  };
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
type * m_pArray
Definition: array.h:266
unsigned int m_iSize
Definition: array.h:270
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
void Set ( unsigned int  iStart,
unsigned int  iSize,
unsigned char  cPattern 
)
inline

Definition at line 172 of file array.h.

173  { MB_ASSERT( m_pThis == this ); MB_ASSERT( iStart+iSize <= m_iSize ); memset( m_pArray+iStart, int(cPattern), sizeof(type)*iSize ); };
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
type * m_pArray
Definition: array.h:266
#define MB_ASSERT(condition)
Definition: mudbox.h:73
unsigned int m_iSize
Definition: array.h:270
const Array< type > * m_pThis
Definition: array.h:272
bool Extend ( unsigned int  iElementIndex)
inline

Definition at line 175 of file array.h.

176  {
177  if ( iElementIndex == 0xffffffff )
178  return true;
179  unsigned int iNewSize = m_iSize;
180  while ( iElementIndex >= iNewSize )
181  iNewSize = iNewSize*2+1;
182  if( iNewSize > m_iSize )
183  return Alloc( iNewSize );
184  return true;
185  };
unsigned int m_iSize
Definition: array.h:270
bool Alloc(unsigned int iNewSize)
Definition: array.h:187
bool Alloc ( unsigned int  iNewSize)
inline

Definition at line 187 of file array.h.

188  {
189  if ( iNewSize == m_iSize )
190  return true;
191  MB_ASSERT( m_pThis == this );
192  type *pNew = 0;
193  try
194  {
195  if ( RegisterMemoryBlock( sizeof(type)*iNewSize ) )
196  {
198  pNew = new type[iNewSize];
199  SetAllocatorID( 0 );
200  }
201  else
202  throw &Error::s_cBadAlloc;
203  }
204  catch ( Error * )
205  {
206  LogAll();
207  return false;
208  }
209  catch ( ... )
210  {
211  // probably std::bad_alloc
212  // not a good idea to call LogAll here, since that function also uses memory, and might fail. In that case stack overflow might happen.
213  //LogAll();
214  throw &Error::s_cBadAlloc;
215  };
216  if ( pNew == 0 )
217  return false;
218  if ( m_iSize )
219  {
221  if ( m_bData )
222  CopyMemoryBlock( pNew, m_pArray, Min( iNewSize, m_iSize )*sizeof(type) );
223  else
224  for ( unsigned int i = 0; i < Min( iNewSize, m_iSize ); i++ )
225  pNew[i] = m_pArray[i];
226  delete [] m_pArray;
227  };
228  m_pArray = pNew;
229  m_iSize = iNewSize;
230  return true;
231  };
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
type * m_pArray
Definition: array.h:266
#define MB_ASSERT(condition)
Definition: mudbox.h:73
bool m_bData
Definition: array.h:271
type Min(type a, type b)
Definition: mudbox.h:184
static bool UnregisterMemoryBlock(long long iSize)
unsigned int m_iSize
Definition: array.h:270
static void SetAllocatorID(const char *pAllocatorID)
const char * m_sName
Definition: array.h:60
static Error s_cBadAlloc
Definition: error.h:112
static bool RegisterMemoryBlock(long long iSize)
static void LogAll(float fSizeFilter=0.01f, bool bSortByAddress=false)
const Array< type > * m_pThis
Definition: array.h:272
static void CopyMemoryBlock(void *pDestination, const void *pSource, long long iSize)
type& operator[] ( int  iIndex)
inline

Definition at line 233 of file array.h.

234  {
235  MB_ASSERT( m_pThis == this );
236  MB_ONBUG( (unsigned int)(iIndex) >= m_iSize )
237  return m_pArray[0];
238  return m_pArray[iIndex];
239  };
type * m_pArray
Definition: array.h:266
#define MB_ASSERT(condition)
Definition: mudbox.h:73
unsigned int m_iSize
Definition: array.h:270
#define MB_ONBUG(condition)
Definition: mudbox.h:101
const Array< type > * m_pThis
Definition: array.h:272
type& operator[] ( unsigned int  iIndex)
inline

Definition at line 241 of file array.h.

242  {
243  MB_ASSERT( m_pThis == this );
244  MB_ONBUG( iIndex >= m_iSize )
245  return m_pArray[0];
246  return m_pArray[iIndex];
247  };
type * m_pArray
Definition: array.h:266
#define MB_ASSERT(condition)
Definition: mudbox.h:73
unsigned int m_iSize
Definition: array.h:270
#define MB_ONBUG(condition)
Definition: mudbox.h:101
const Array< type > * m_pThis
Definition: array.h:272
const type& operator[] ( unsigned int  iIndex) const
inline

Definition at line 249 of file array.h.

250  {
251  MB_ASSERT( m_pThis == this );
252  MB_ONBUG( iIndex >= m_iSize )
253  return m_pArray[0];
254  return m_pArray[iIndex];
255  };
type * m_pArray
Definition: array.h:266
#define MB_ASSERT(condition)
Definition: mudbox.h:73
unsigned int m_iSize
Definition: array.h:270
#define MB_ONBUG(condition)
Definition: mudbox.h:101
const Array< type > * m_pThis
Definition: array.h:272
type* indexedAddr ( unsigned int  i)
inline

Definition at line 259 of file array.h.

259 { return &operator[]( i ); };
type & operator[](int iIndex)
Definition: array.h:233
const type* indexedAddr ( unsigned int  i) const
inline

Definition at line 260 of file array.h.

260 { return &operator[]( i ); };
type & operator[](int iIndex)
Definition: array.h:233
type* baseAddr ( )
inline

Definition at line 262 of file array.h.

262 { return &operator[]( 0 ); };
type & operator[](int iIndex)
Definition: array.h:233
const type* baseAddr ( ) const
inline

Definition at line 263 of file array.h.

263 { return &operator[]( 0 ); };
type & operator[](int iIndex)
Definition: array.h:233
void operator= ( const Array< type > &  a)
inline

Definition at line 265 of file array.h.

266  { 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; };
type * m_pArray
Definition: array.h:266
#define MB_ASSERT(condition)
Definition: mudbox.h:73
unsigned int m_iSize
Definition: array.h:270
void Clear(bool bDestruct=false)
Definition: array.h:146
const Array< type > * m_pThis
Definition: array.h:272
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404

Friends And Related Function Documentation

friend class Block
friend

Definition at line 67 of file array.h.

Member Data Documentation

type* m_pArray
mutableprotected

Definition at line 266 of file array.h.

unsigned int m_iSize
mutableprotected

Definition at line 270 of file array.h.

bool m_bData
mutableprotected

Definition at line 271 of file array.h.

const Array<type>* m_pThis
mutableprotected

Definition at line 272 of file array.h.


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