Mudbox/array.h Source File

array.h
Go to the documentation of this file.
1 
2 //**************************************************************************/
3 // Copyright (c) 2008 Autodesk, Inc.
4 // All rights reserved.
5 //
6 // Use of this software is subject to the terms of the Autodesk license
7 // agreement provided at the time of installation or download, or which
8 // otherwise accompanies this software in either electronic or hard copy form.
9 //
10 //**************************************************************************/
11 // DESCRIPTION:
12 // CREATED: October 2008
13 //**************************************************************************/
14 
15 namespace mudbox {
16 
17 void MBDLL_DECL QuickSort( void *pBase, unsigned int iNum, unsigned int iSize, int ( * fComparator ) ( const void *, const void * ) );
18 
21 {
22 protected:
23  Block( const char *sName, unsigned int iItemSize )
24  {
25  m_sName = sName;
26  m_pNext = s_pHead;
27  m_pPrev = 0;
28  if ( m_pNext ) m_pNext->m_pPrev = this;
29  s_pHead = this;
30  m_iItemSize = iItemSize;
31  };
32 
33  ~Block( void );
34  Block *m_pNext, *m_pPrev;
35  unsigned int m_iItemSize;
36  static Block *s_pHead;
37 
38 public:
39  inline static const Block *Head( void ) { return s_pHead; };
40  inline const Block *Next( void ) const { return m_pNext; };
41  inline unsigned int ItemSize( void ) const { return m_iItemSize; };
42 
43  const char *Name( void ) const;
44  long long Size( void ) const;
45  long long Address( void ) const;
46  static void LogAll( float fSizeFilter = 0.01f, bool bSortByAddress = false );
47  void Check( void ) const;
48  static void CheckAll( void );
49  static bool RegisterMemoryBlock( long long iSize );
50  static bool UnregisterMemoryBlock( long long iSize );
51  static void SetAllocatorID( const char *pAllocatorID );
52  static void CopyMemoryBlock( void *pDestination, const void *pSource, long long iSize );
53 
54  // Allocates iBytes aligned to iAlignment boundaries. iAlignment must be a positive power of two.
55  static void* AlignedAlloc( size_t iBytes, unsigned int iAlignment );
56 
57  // Frees memory allocated with AlignedAlloc
58  static void AlignedFree( void* pData );
59 
60  const char *m_sName;
61 };
62 
64 template < typename type >
66 {
67  friend class Block;
68 public:
69  Array( const char *sName ) : Block( sName, sizeof(type) )
70  {
71  m_bData = true;
72  m_iSize = 0;
73  m_pArray = 0;
74  m_pThis = this;
75  };
76  Array( const char *sName, unsigned int iSize ) : 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  };
99  Array( const char *sName, const type *pArray, int iSize ) : 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  };
127 
128  Array( const char *sName, bool bNoObjects ) : Block( sName, sizeof(type) )
129  {
130  m_bData = bNoObjects;
131  m_iSize = 0;
132  m_pArray = 0;
133  m_pThis = this;
134  };
135 
136  Array( const char *sName, const Array<type> &a ) : 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  };
145 
146  void Clear( bool bDestruct = false )
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  };
161 
162  inline Array<type> Clone( void ) const { Array<type> a; Copy( a ); return a; };
163 
164  inline bool Copy( Array<type> &a ) const
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  };
171 
172  inline void Set( unsigned int iStart, unsigned int iSize, unsigned char cPattern )
173  { MB_ASSERT( m_pThis == this ); MB_ASSERT( iStart+iSize <= m_iSize ); memset( m_pArray+iStart, int(cPattern), sizeof(type)*iSize ); };
174 
175  inline bool Extend( unsigned int iElementIndex )
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  };
186 
187  bool Alloc( unsigned int iNewSize )
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  {
197  SetAllocatorID( m_sName );
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  {
220  UnregisterMemoryBlock( sizeof(type)*m_iSize );
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  };
232 
233  inline type &operator []( int iIndex )
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  };
240 
241  inline type &operator []( unsigned int iIndex )
242  {
243  MB_ASSERT( m_pThis == this );
244  MB_ONBUG( iIndex >= m_iSize )
245  return m_pArray[0];
246  return m_pArray[iIndex];
247  };
248 
249  inline const type &operator []( unsigned int iIndex ) const
250  {
251  MB_ASSERT( m_pThis == this );
252  MB_ONBUG( iIndex >= m_iSize )
253  return m_pArray[0];
254  return m_pArray[iIndex];
255  };
256 
257 
258  // these are unsafe......
259  inline type *indexedAddr(unsigned int i) { return &operator[]( i ); };
260  inline const type *indexedAddr(unsigned int i) const { return &operator[]( i ); };
261 
262  inline type *baseAddr() { return &operator[]( 0 ); };
263  inline const type *baseAddr() const { return &operator[]( 0 ); };
264 
265  inline void operator =( const Array<type> &a )
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; };
267 
268 protected:
269  mutable type *m_pArray;
270  mutable unsigned int m_iSize;
271  mutable bool m_bData;
272  mutable const Array<type> *m_pThis;
273 
274 private:
275  // removing these and replacing them with baseAddr/indexedAddr will make it far easier to see or grep
276  // where we are leaking addresses of elements. DEPRECATED. DO NOT USE. IT ALWAYS RETURNs 0
277  //
278  inline type *operator +( unsigned int iIndex ) { MB_ASSERT( 0 /*m_pThis == this*/ ); return 0; /*&operator[]( iIndex );*/ };
279  inline type *operator +( int iIndex ) { MB_ASSERT( 0 /*m_pThis == this*/ ); return 0; /*&operator[]( iIndex );*/ };
280 
281 public:
282  ~Array( void ) { MB_ASSERT( m_pThis == this ); Clear(); };
283 };
284 
332 
333 template < typename type >
334 class MBDLL_TEMPLATE_DECL Store : public Array<type>
335 {
336 public:
339  const char *sName = "unknown"
340  ) : Array<type>( sName ) { m_iSize = 0; };
341 
351  unsigned int iSize,
352  const char *sName
353  ) : Array<type>( sName, iSize ) { m_iSize = iSize; };
354 
361  const type *pArray,
362  int iSize,
363  const char *sName = "unknown"
364  ) : Array<type>( sName, pArray, iSize ) { m_iSize = iSize; };
365 
368  bool bNoObjects,
369  const char *sName
370  ) : Array<type>( sName, bNoObjects ) { m_iSize = 0; };
371 
374  const Store &s
375  ) : Array<type>( s.m_sName, s ) { m_iSize = s.m_iSize; s.m_iSize = 0; };
376 
378  ~Store( void ) { Clear( !Array<type>::m_bData ); };
379 
381  bool Copy(
382  Store &s
383  ) const { s.m_iSize = m_iSize; return Array<type>::Copy( s ); };
384 
386  Store Clone( void ) const { Store s; s.SetItemCount( m_iSize ); Copy( s ); return s; };
387 
389  void Clone(
390  Store &s
391  ) const { s.SetItemCount( m_iSize ); Copy( s ); };
392 
394  inline void Clear(
395  bool bDestruct = false
396  ) { Array<type>::Clear( bDestruct ); m_iSize = 0; };
397 
403  inline bool SetItemCount(
404  unsigned int iSize,
405  bool bKeepContent = false
406  )
407  {
408  if ( iSize <= m_iSize )
409  {
410  m_iSize = iSize;
411  return true;
412  };
413  if ( !bKeepContent )
414  Clear();
415  if ( Array<type>::Alloc( iSize ) )
416  {
417  m_iSize = iSize;
418  return true;
419  };
420  return false;
421  };
422 
430  inline bool Allocate(
431  unsigned int iSize,
432  bool bKeepContent = false
433  ) { if ( !bKeepContent ) Clear(); return Array<type>::Alloc( iSize ); };
434 
440  inline bool Extend(
441  unsigned int iIndex
442  )
443  {
444  if ( Array<type>::Extend( iIndex ) )
445  {
446  m_iSize = Max( m_iSize, iIndex+1 );
447  return true;
448  };
449  return false;
450  };
451 
457  inline bool Extend(
458  int iIndex
459  ) { return Extend( (unsigned int)iIndex ); };
460 
462  inline void RemoveTail(
463  int iItemCount = 1
464  ) { SetItemCount( ItemCount()-iItemCount ); };
465 
467  inline void Fill(
468  type cPattern
469  ) { for ( unsigned int i = 0; i < m_iSize; i++ ) operator[](i) = cPattern; };
470 
473  inline void ByteFill(
474  unsigned char cPattern
475  ) { memset( Array<type>::m_pArray, (unsigned int)cPattern, sizeof(type) * m_iSize ); }
476 
482  inline unsigned int Add(
483  const type &e
484  ) { if( Array<type>::Extend( m_iSize ) ) { Array<type>::operator[]( m_iSize ) = e; return m_iSize++; } else return 0xffffffff; };
485 
490  inline unsigned int Add(
491  type &e
492  ) { if( Array<type>::Extend( m_iSize ) ) { Array<type>::operator[]( m_iSize ) = e; return m_iSize++; } else return 0xffffffff; };
493 
497  inline Store &operator =( const Store &s ) { m_iSize = s.m_iSize; s.m_iSize = 0; Array<type>::operator =( s ); return *this; };
498 
502  void GetFrom(
503  Store &s
504  ) { m_iSize = s.m_iSize; Array<type>::operator =( s ); };
505 
507  const type &operator []( unsigned int iIndex ) const { return Array<type>::m_pArray[iIndex]; };
508 
510  type &operator []( unsigned int iIndex ) { MB_ASSERT( iIndex < m_iSize ); return Array<type>::m_pArray[iIndex]; };
511 
513  const type &operator []( int iIndex ) const { return operator[]( (unsigned int)iIndex ); };
514 
516  type &operator []( int iIndex ) { return operator[]( (unsigned int)iIndex ); };
517 
518 
520  inline bool IsEmpty( void ) const { return ItemCount() == 0; };
521 
523  inline operator bool( void ) const { return !IsEmpty(); };
524 
526  inline bool operator !( void ) const { return IsEmpty(); };
527 
537  void SetBuffer( type *pData, unsigned int iSize = 0 ) { m_iSize = Array<type>::m_iSize = iSize; Array<type>::m_pArray = pData; };
538 
540  void Serialize( // currently implemented in stream.h
541  class Stream &s
542  );
543 
556  inline void Sort( void ) { QuickSort( Array<type>::m_pArray, m_iSize, sizeof(type), Compare ); };
557 
566  inline type *Find(
567  type a
568  ) { return (type *) bsearch( &a, Array<type>::m_pArray, m_iSize, sizeof(type), Compare ); };
569 
578  inline type *Find( type *a ) { return (type *) bsearch( a, Array<type>::m_pArray, m_iSize, sizeof(type), Compare ); };
579 
584  inline unsigned int IndexOf( type pValue )
585  {
586  for(unsigned int i = 0; i < ItemCount(); ++i )
587  if( (*this)[i] == pValue )
588  return i;
589  return 0xffffffff;
590  };
591 
593  unsigned int Remove(
594  const type &e
595  )
596  {
597  unsigned int j = 0, i = 0;
598  while ( i < ItemCount() )
599  {
600  if ( operator[]( i ) != e )
601  operator[]( j++ ) = operator[]( i );
602  i++;
603  };
604  SetItemCount( j );
605  return i-j;
606  };
607 
609  void RemoveAt(
610  unsigned int iIndex
611  )
612  {
613  while ( iIndex+1 < ItemCount( ) )
614  {
615  operator[]( iIndex ) = operator[]( iIndex+1 );
616  iIndex++;
617  };
618  SetItemCount( Min(iIndex,ItemCount()-1) );
619  };
620 
627  unsigned int RemoveDuplicates( void )
628  {
629  if ( ItemCount() == 0 )
630  return 0;
631  Sort();
632  unsigned int j = 0;
633  for ( unsigned int i = 0; i < ItemCount()-1; i++ )
634  {
635  if ( operator[]( i ) != operator[]( i+1 ) )
636  operator[]( j++ ) = operator[]( i );
637  };
638  operator[]( j++ ) = operator[]( ItemCount()-1 );
639  unsigned iRemoved = ItemCount()-j;
640  m_iSize = j;
641  return iRemoved;
642  };
643 
645  inline unsigned int ItemCount( void ) const { return m_iSize; };
646 
648  inline type &Last( void ) { if ( ItemCount() ) return operator []( ItemCount()-1 ); else throw new Error( "Store::LastItem called for an empty store" ); };
649 
659  inline void Optimize( void ) { Array<type>::Alloc( m_iSize ); };
660 
661 protected:
662  static int Compare( const void *a, const void *b ) { return (int)(*((type *)a)-*((type *)b)); };
663 
664 private:
670  inline type *operator +( unsigned int iIndex ) { return 0; /* &operator[]( iIndex ); */ };
671 
677  inline type *operator +( int iIndex ) { return 0; /* &operator[]( iIndex ); */ };
678 
679 public:
680  mutable unsigned int m_iSize;
681 };
682 
687 template<typename T>
689 {
690  unsigned int m_iLogicalItemCount;
691 
692  const unsigned int m_iBlockItemCount;
693  const unsigned int m_iBlockPow;
694  const unsigned int m_iBlockMask;
695 
696  const unsigned int m_iAlignment;
697 
698  Store< T* > m_aBlocks;
699 
700 public:
701 
703  m_iBlockItemCount(16384),
704  m_iBlockPow(14),
705  m_iBlockMask(0x3FFF),
706  m_iLogicalItemCount(0),
707  m_iAlignment(16)
708  {
709 
710  };
711 
713  {
714  Clear();
715  };
716 
718  inline unsigned int ItemCount() const { return m_iLogicalItemCount; }
719 
725  inline void SetItemCount(
726  unsigned int iCount
727  ) { if( iCount == 0 ) Clear(); else Extend( iCount-1 ); m_iLogicalItemCount = iCount; }
728 
730  inline void Clear()
731  {
732  m_iLogicalItemCount = 0;
733  for( unsigned int i = 0; i < m_aBlocks.ItemCount(); ++i )
734  {
735  Block::AlignedFree( (void*)m_aBlocks[i] );
736  }
737  m_aBlocks.Clear();
738  }
739 
741  inline void Add(
742  const T& t
743  )
744  {
745  const unsigned int c = ItemCount();
746  Extend(c);
747  operator[](c) = t;
748  }
749 
755  inline void Extend(
756  unsigned int iIndex
757  )
758  {
759  const unsigned int iBlock = iIndex >> m_iBlockPow;
760 
761  // extend the logical item count to include iIndex
762  m_iLogicalItemCount = Max( iIndex + 1, m_iLogicalItemCount );
763 
764  // if this block has already be allocated we are done.
765  if( iBlock < m_aBlocks.ItemCount() )
766  return;
767 
768  // allocate enough blocks to include iIndex
769  const unsigned int ic = m_aBlocks.ItemCount();
770  m_aBlocks.Extend( iBlock );
771  for( unsigned int i = ic; i < m_aBlocks.ItemCount(); ++i )
772  {
773  T* pNewBlock = (T*)Block::AlignedAlloc( sizeof(T) * m_iBlockItemCount, m_iAlignment );
774  MB_ASSERT( ((size_t) pNewBlock) % m_iAlignment == 0 );
775  m_aBlocks[i] = pNewBlock;
776  }
777  }
778 
780  inline void Fill(
781  T cPattern
782  )
783  {
784  for ( unsigned int i = 0; i < m_aBlocks.ItemCount(); i++ )
785  for( unsigned int j = 0; j < m_iBlockItemCount; ++j )
786  m_aBlocks[i][j] = cPattern;
787  }
788 
793  inline unsigned int IndexOf( const T& pValue ) const
794  {
795  for(unsigned int i = 0; i < ItemCount(); ++i )
796  if( (*this)[i] == pValue )
797  return i;
798  return 0xffffffff;
799  };
800 
802  inline T &Last( void ) { if ( ItemCount() ) return operator []( ItemCount()-1 ); else throw new Error( "ExtenableStore::LastItem called for an empty store" ); };
803 
804  inline T &operator []( unsigned int iIndex )
805  {
806  const unsigned int iBlock = iIndex >> m_iBlockPow;
807  const unsigned int iBlockItem = iIndex & m_iBlockMask;
808  return m_aBlocks[ iBlock ][iBlockItem];
809  }
810 
811  inline const T &operator []( unsigned int iIndex ) const
812  {
813  const unsigned int iBlock = iIndex >> m_iBlockPow;
814  const unsigned int iBlockItem = iIndex & m_iBlockMask;
815  return m_aBlocks[ iBlock ][iBlockItem];
816  }
817 
818  void Serialize( Stream& s ); // This is defined in Stream.h
819 };
820 
821 
822 
823 
824 
825 }; // end of namespace mudbox
826 
unsigned int RemoveDuplicates(void)
Removes duplicated items from the array after sorting it.
Definition: array.h:627
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
type * m_pArray
Definition: array.h:266
static void AlignedFree(void *pData)
Store(unsigned int iSize, const char *sName)
Creates an array with space for some elements already allocated.
Definition: array.h:350
void operator=(const Array< type > &a)
Definition: array.h:265
#define MBDLL_TEMPLATE_DECL
Definition: dllinterface.h:44
void Optimize(void)
Reduces the allocated memory size to match the size of the current elements in the array...
Definition: array.h:659
Simple array class.
Definition: array.h:334
unsigned int Remove(const type &e)
Remove every occurrence of a specified item from the array. Returns the number of removed items...
Definition: array.h:593
unsigned int m_iSize
Definition: array.h:677
type * indexedAddr(unsigned int i)
Definition: array.h:259
bool Extend(int iIndex)
Extends the logical size of the array.
Definition: array.h:457
bool Extend(unsigned int iElementIndex)
Definition: array.h:175
Array< type > Clone(void) const
Definition: array.h:162
Array(const char *sName, const Array< type > &a)
Definition: array.h:136
#define MB_ASSERT(condition)
Definition: mudbox.h:73
void GetFrom(Store &s)
Transfers the contents of another array to this one, leaving the original array empty.
Definition: array.h:502
type * Find(type *a)
Returns a pointer to the item in the array with a particular value.
Definition: array.h:578
Block(const char *sName, unsigned int iItemSize)
Definition: array.h:23
unsigned int ItemSize(void) const
Definition: array.h:41
const type * baseAddr() const
Definition: array.h:263
type & Last(void)
Returns the last item in the array, or 0 if the array is empty.
Definition: array.h:648
~Array(void)
Definition: array.h:282
This class is similar to Store, except that adding elements to the end of the array is guaranteed to ...
Definition: array.h:688
void Fill(T cPattern)
Fills the array with a specified element.
Definition: array.h:780
void Set(unsigned int iStart, unsigned int iSize, unsigned char cPattern)
Definition: array.h:172
bool m_bData
Definition: array.h:271
type Min(type a, type b)
Definition: mudbox.h:184
type & operator[](int iIndex)
Definition: array.h:233
void MBDLL_DECL QuickSort(void *pBase, unsigned int iNum, unsigned int iSize, int(*fComparator)(const void *, const void *))
Store(bool bNoObjects, const char *sName)
Creates an empty array, allowing you to specify if elements have constructors or destructors that nee...
Definition: array.h:367
type * baseAddr()
Definition: array.h:262
Holds information about an error.
Definition: error.h:46
Array(const char *sName, const type *pArray, int iSize)
Definition: array.h:99
Block * m_pPrev
Definition: array.h:34
Array(const char *sName)
Definition: array.h:69
void Clone(Store &s) const
Copies the contents of another array into this one, duplicating all data.
Definition: array.h:389
static const Block * Head(void)
Definition: array.h:39
bool Copy(Array< type > &a) const
Definition: array.h:164
void Sort(void)
Sorts the items in the array.
Definition: array.h:556
void Clear(bool bDestruct=false)
Clears the array and deallocates its memory.
Definition: array.h:394
unsigned int m_iSize
Definition: array.h:270
void Serialize(Stream &s)
Definition: stream.h:331
An internal helper class, representing an array. Use the Store class instead.
Definition: array.h:65
unsigned int IndexOf(type pValue)
Returns the first index of the element equal to pValue.
Definition: array.h:584
bool Alloc(unsigned int iNewSize)
Definition: array.h:187
const char * m_sName
Definition: array.h:60
void Fill(type cPattern)
Fills the array with a specified element.
Definition: array.h:467
static Error s_cBadAlloc
Definition: error.h:112
static int Compare(const void *a, const void *b)
Definition: array.h:662
Array(const char *sName, bool bNoObjects)
Definition: array.h:128
bool SetItemCount(unsigned int iSize, bool bKeepContent=false)
Sets the logical size of the array.
Definition: array.h:403
void Add(const T &t)
Adds a new item to the array, increasing the array size by 1.
Definition: array.h:741
Store(const type *pArray, int iSize, const char *sName="unknown")
Creates an array and populates it will information copied from another array.
Definition: array.h:360
bool Copy(Store &s) const
Copies the contents of another array into this one, duplicating all data. Returns true if successful...
Definition: array.h:381
unsigned int Add(type &e)
Adds a new item to the array, increasing the array size by 1.
Definition: array.h:490
type & operator[](int iIndex)
Returns an indexed item from the array.
Definition: array.h:516
#define MB_ONBUG(condition)
Definition: mudbox.h:101
void Clear(bool bDestruct=false)
Definition: array.h:146
T & Last(void)
Returns the last item in the array, or 0 if the array is empty.
Definition: array.h:802
const QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
Definition: qbytearray.h:564
Store(const Store &s)
Creates an array from another one. The other array becomes empty after the operation.
Definition: array.h:373
GLubyte GLubyte b
Definition: GLee.h:5404
unsigned int ItemCount(void) const
Returns the number of items in the array.
Definition: array.h:645
unsigned int IndexOf(const T &pValue) const
Returns the first index of the element equal to pValue.
Definition: array.h:793
void SetItemCount(unsigned int iCount)
Sets the logical size of the array.
Definition: array.h:725
const type * indexedAddr(unsigned int i) const
Definition: array.h:260
Array(const char *sName, unsigned int iSize)
Definition: array.h:76
Store Clone(void) const
Returns a copy of this array. The returned copy will have a duplicate of all data in the original...
Definition: array.h:386
const type & operator[](int iIndex) const
Returns an indexed item from the array.
Definition: array.h:513
const GLubyte * c
Definition: GLee.h:5419
static Block * s_pHead
Definition: array.h:36
void Extend(unsigned int iIndex)
Extends the logical size of the array.
Definition: array.h:755
bool Allocate(unsigned int iSize, bool bKeepContent=false)
Preallocates memory for the an array, without changing the array's logical size.
Definition: array.h:430
unsigned int Add(const type &e)
Adds a new item to the array, increasing the array size by 1.
Definition: array.h:482
Class: ConvolutionKernel.
Definition: array.h:15
void RemoveTail(int iItemCount=1)
Removes the final items from the array.
Definition: array.h:462
const Array< type > * m_pThis
Definition: array.h:272
Store(const char *sName="unknown")
Creates an empty array.
Definition: array.h:338
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
static void ThrowBadAlloc(void)
Throws a static bad alloc exception. (No memory allocation is required to report allocation problems...
Definition: error.h:112
void SetBuffer(type *pData, unsigned int iSize=0)
Makes a Store array from a regular C or C++ array.
Definition: array.h:537
void RemoveAt(unsigned int iIndex)
Removes the item at the specified index from the array.
Definition: array.h:609
Streams are used to read information from a file, or to write it to a file.
Definition: stream.h:39
bool IsEmpty(void) const
Returns true if the array has no items.
Definition: array.h:520
const Block * Next(void) const
Definition: array.h:40
unsigned int ItemCount() const
Returns the number of items in the array.
Definition: array.h:718
T & operator[](unsigned int iIndex)
Definition: array.h:804
An internal helper class, representing a block of memory. Use the Store class instead.
Definition: array.h:20
unsigned int m_iItemSize
Definition: array.h:35
~Store(void)
Destroys the contents of the array and deallocate its memory.
Definition: array.h:378
GLdouble GLdouble t
Definition: GLee.h:1181
GLdouble s
Definition: GLee.h:1173
type * Find(type a)
Returns a pointer to the item in the array with a particular value.
Definition: array.h:566
void Clear()
Clears the array and deallocates its memory.
Definition: array.h:730
type Max(type a, type b)
Definition: mudbox.h:186
GLclampf f
Definition: GLee.h:9303
#define MBDLL_DECL
Definition: dllinterface.h:35
void ByteFill(unsigned char cPattern)
Fills the array with a specified byte pattern.
Definition: array.h:473
bool Extend(unsigned int iIndex)
Extends the logical size of the array.
Definition: array.h:440
static void * AlignedAlloc(size_t iBytes, unsigned int iAlignment)