SIMPLE_ARRAY< _CT > Class Template Reference

Simple array template. More...

#include <mi32/simplear.h>

Inheritance diagram for SIMPLE_ARRAY< _CT >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 SIMPLE_ARRAY (const SIMPLE_ARRAY< _CT > &rhs)
 SIMPLE_ARRAY ()
 ~SIMPLE_ARRAY ()
void AddRef ()
ERRVALUE Append (const SIMPLE_ARRAY< _CT > &rhs)
ERRVALUE Append (const _CT *items, unsigned numitems)
ERRVALUE Append (const _CT &item)
void AppendExc (const SIMPLE_ARRAY< _CT > &rhs)
void AppendExc (const _CT *items, unsigned numitems)
void AppendExc (const _CT &item)
ERRVALUE AppendUnique (const _CT &item)
void AppendUniqueExc (const _CT &item)
ERRVALUE Assign (const _CT *items, unsigned numitems)
void Attach (_CT *&items, unsigned numitems)
void Clear ()
void ClearItems (unsigned start, unsigned end=-1)
void ClearItems ()
ERRVALUE Copy (const SIMPLE_ARRAY< _CT > &rhs)
ERRVALUE Extend ()
 operator _CT * ()
 operator const _CT * () const
bool operator!= (const SIMPLE_ARRAY< _CT > &rhs) const
SIMPLE_ARRAY< _CT > & operator= (const SIMPLE_ARRAY< _CT > &rhs)
bool operator== (const SIMPLE_ARRAY< _CT > &rhs) const
template<typename _IDXTYPE >
_CT & operator[] (_IDXTYPE index)
template<typename _IDXTYPE >
const _CT & operator[] (_IDXTYPE index) const



_CT * Detach ()
void ExchangeItems (unsigned index1, unsigned index2)
void Free ()
const _CT & GetItem (unsigned index) const
_CT * GetItems ()
const _CT * GetItems () const
const _CT & GetLast () const
unsigned GetMaxItems () const
unsigned GetNumItems () const
UINT32 GetRefCount () const
unsigned GetSizeInBytes () const
bool HasItem (const _CT &item) const
ERRVALUE Insert (unsigned pos, const _CT &item)
void InsertItems (unsigned start, unsigned num=1)
bool IsEmpty () const
template<typename _Pr1 >
unsigned Locate (const _CT &item, _Pr1 _Pr, bool &bFound) const
void Release ()
void RemoveDuplicates ()
void RemoveFast (unsigned item)
void RemoveItem (unsigned item)
void RemoveItems (unsigned item, unsigned count)
void RemoveLast (unsigned count=1)
bool RemoveMatchingItems (const _CT &item)
ERRVALUE Reserve (unsigned newmaxitems, bool clear=false)
void ReserveExc (unsigned newmaxitems, bool clear=false)
ERRVALUE Resize (unsigned numitems, bool keepold=true, bool clear=false)
void Reverse ()
void SetAll (const _CT &value)
void SetItem (unsigned index, const _CT &item)
ERRVALUE SetItems (unsigned firstitem, const _CT *items, unsigned numitems)
void Sort (int(*CompFunc)(_CT *, _CT *, void *), void *data=0)
void SortRange (int(*CompFunc)(_CT *, _CT *, void *), unsigned firstidx, unsigned numitems, void *data=0)
void Swap (SIMPLE_ARRAY< _CT > &rhs)
void SwapBytes ()

Detailed Description

template<class _CT>
class SIMPLE_ARRAY< _CT >

Simple array template.

This template is designed to contain an array of items which can be allocated using MmAlloc/MmRealloc. The primary purpose of this template is to replace allocated arrays where direct access to both array elements and the ability to access a pointer to the first element (as for a C array) is required. Do not use this template with classes which require constructors or have virtual methods or which do not have compiler-generated assignment operators.

For maximum efficiency, only minimal validation of access to array elements is performed. No initialization of array items is performed by the template.

For doubles and objects based on doubles, use DOUBLE_ARRAY<> in mi32/doublear.h

Instances of this class are passed to DLLs, so do not add or remove members.


Constructor & Destructor Documentation

template<class _CT>
SIMPLE_ARRAY< _CT >::SIMPLE_ARRAY (  )  [inline]

Default constructor, creates empty array.

template<class _CT>
SIMPLE_ARRAY< _CT >::SIMPLE_ARRAY ( const SIMPLE_ARRAY< _CT > &  rhs  )  [inline]

Copy constructor.

template<class _CT>
SIMPLE_ARRAY< _CT >::~SIMPLE_ARRAY (  )  [inline]

Destructor.


Member Function Documentation

template<class _CT>
void SIMPLE_ARRAY< _CT >::AddRef (  )  [inline]

Increment reference count.

template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::Append ( const SIMPLE_ARRAY< _CT > &  rhs  )  [inline]

Append items from SIMPLE_ARRAY.

template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::Append ( const _CT *  items,
unsigned  numitems 
) [inline]

Append items from C array.

Parameters:
items Items to append
numitems Number of items to append
template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::Append ( const _CT &  item  )  [inline]

Append item to end of array.

Reimplemented in BUTTONITEMARRAY, and MENUITEMARRAY.

template<class _CT>
void SIMPLE_ARRAY< _CT >::AppendExc ( const SIMPLE_ARRAY< _CT > &  rhs  )  [inline]

Append items from SIMPLE_ARRAY, throwing exception if out of memory.

template<class _CT>
void SIMPLE_ARRAY< _CT >::AppendExc ( const _CT *  items,
unsigned  numitems 
) [inline]

Append items from C array, throwing exception if out of memory.

Parameters:
items Items to append
numitems Number of items to append
template<class _CT>
void SIMPLE_ARRAY< _CT >::AppendExc ( const _CT &  item  )  [inline]

Append item to end of array, throwing exception if out of memory.

template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::AppendUnique ( const _CT &  item  )  [inline]

Append item to end of array if unique.

template<class _CT>
void SIMPLE_ARRAY< _CT >::AppendUniqueExc ( const _CT &  item  )  [inline]

Append item to end of array if unique, throwing exception if out of memory.

template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::Assign ( const _CT *  items,
unsigned  numitems 
) [inline]

Assign from C array, resizing to the specified number of items.

Parameters:
items Items to copy to array
numitems Number of items
template<class _CT>
void SIMPLE_ARRAY< _CT >::Attach ( _CT *&  items,
unsigned  numitems 
) [inline]

Attach a buffer to the SIMPLE_ARRAY.

After passing a buffer to Attach(), the SIMPLE_ARRAY "<b>owns</b>" the buffer and will free it in its destructor.

Parameters:
items Reference to a pointer to the templated data type. The reason it's a reference is that after recording the pointer, Attach() will set your pointer to 0. This will prevent you from accidently freeing a pointer you no longer own. If you want it back, call the Detach() method
Parameters:
numitems Number of items in array
template<class _CT>
void SIMPLE_ARRAY< _CT >::Clear (  )  [inline]

Clear the array, does not free resources.

template<class _CT>
void SIMPLE_ARRAY< _CT >::ClearItems ( unsigned  start,
unsigned  end = -1 
) [inline]

Clear specified items in the array.

Parameters:
end Default to use number of items
template<class _CT>
void SIMPLE_ARRAY< _CT >::ClearItems (  )  [inline]

Clear all items in the array.

template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::Copy ( const SIMPLE_ARRAY< _CT > &  rhs  )  [inline]

Copy the contents of another SIMPLE_ARRAY.

Same as assignment, but returns an error code instead of throwing an exception.

template<class _CT>
_CT* SIMPLE_ARRAY< _CT >::Detach (  )  [inline]

Detach the buffer from the SIMPLE_ARRAY.

This turns ownership of the buffer over to the caller, who is then responsible for seeing that it gets disposed of. After calling Detach(), the SIMPLE_ARRAY will behave as if it had just been constructed. In other words, it will be a NULL pointer pointing to 0 items. This means that if you want to know how many items are in the array returned, you must find out before} you call Detach()!

template<class _CT>
void SIMPLE_ARRAY< _CT >::ExchangeItems ( unsigned  index1,
unsigned  index2 
) [inline]

Switch positions of two items.

template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::Extend (  )  [inline]

Extend array by one entry without setting contents.

template<class _CT>
void SIMPLE_ARRAY< _CT >::Free (  )  [inline]

Free the array.

template<class _CT>
const _CT& SIMPLE_ARRAY< _CT >::GetItem ( unsigned  index  )  const [inline]

Get array item, does not verify index range.

template<class _CT>
_CT* SIMPLE_ARRAY< _CT >::GetItems (  )  [inline]

Get pointer to items.

template<class _CT>
const _CT* SIMPLE_ARRAY< _CT >::GetItems (  )  const [inline]

Get const pointer to items.

template<class _CT>
const _CT& SIMPLE_ARRAY< _CT >::GetLast (  )  const [inline]

Get last item in array.

Does not verify that array is non-empty.

template<class _CT>
unsigned SIMPLE_ARRAY< _CT >::GetMaxItems (  )  const [inline]

Get maximum number of items in array.

template<class _CT>
unsigned SIMPLE_ARRAY< _CT >::GetNumItems (  )  const [inline]

Get number of items in array.

template<class _CT>
UINT32 SIMPLE_ARRAY< _CT >::GetRefCount (  )  const [inline]

Get current reference count.

template<class _CT>
unsigned SIMPLE_ARRAY< _CT >::GetSizeInBytes (  )  const [inline]

Get size of array required to hold current number of items in bytes.

template<class _CT>
bool SIMPLE_ARRAY< _CT >::HasItem ( const _CT &  item  )  const [inline]

Determine if an item exists in the array.

Item must have a valid operator==()

Returns:
'True' if item found
template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::Insert ( unsigned  pos,
const _CT &  item 
) [inline]

Insert item at specified position.

template<class _CT>
void SIMPLE_ARRAY< _CT >::InsertItems ( unsigned  start,
unsigned  num = 1 
) [inline]

Insert multiple items into the array.

template<class _CT>
bool SIMPLE_ARRAY< _CT >::IsEmpty (  )  const [inline]

Determine if array is empty.

template<class _CT>
template<typename _Pr1 >
unsigned SIMPLE_ARRAY< _CT >::Locate ( const _CT &  item,
_Pr1  _Pr,
bool &  bFound 
) const [inline]

Search sorted array for an entry or the place where the entry should be.

_Pr is a functor that returns -1 if 1st item < 2nd, 1 if 1st > 2nd, 0 if 1st == 2nd 'item' is the first parameter passed to the _Pr functor.

Returns:
Position of item if found, indeterminant if not found.
Parameters:
bFound Returned as 'true' if item found, 'false' if not
template<class _CT>
SIMPLE_ARRAY< _CT >::operator _CT * (  )  [inline]

Cast to array of template type.

template<class _CT>
SIMPLE_ARRAY< _CT >::operator const _CT * (  )  const [inline]

Cast to const array of template type.

template<class _CT>
bool SIMPLE_ARRAY< _CT >::operator!= ( const SIMPLE_ARRAY< _CT > &  rhs  )  const [inline]

Inequality operator.

template<class _CT>
SIMPLE_ARRAY<_CT>& SIMPLE_ARRAY< _CT >::operator= ( const SIMPLE_ARRAY< _CT > &  rhs  )  [inline]

Assignment, may throw exception if out of memory.

Use Copy() method for error checking.

template<class _CT>
bool SIMPLE_ARRAY< _CT >::operator== ( const SIMPLE_ARRAY< _CT > &  rhs  )  const [inline]

Equality operator.

template<class _CT>
template<typename _IDXTYPE >
_CT& SIMPLE_ARRAY< _CT >::operator[] ( _IDXTYPE  index  )  [inline]

Write (non-const) access to array element.

Note:
Does not verify that index is within valid range.
template<class _CT>
template<typename _IDXTYPE >
const _CT& SIMPLE_ARRAY< _CT >::operator[] ( _IDXTYPE  index  )  const [inline]

Read (const) access to array element.

Note:
Does not verify that index is within valid range.
template<class _CT>
void SIMPLE_ARRAY< _CT >::Release (  )  [inline]

Decrement reference count, delete if zero.

template<class _CT>
void SIMPLE_ARRAY< _CT >::RemoveDuplicates (  )  [inline]

Remove duplicate entries in the list, assume not sorted.

template<class _CT>
void SIMPLE_ARRAY< _CT >::RemoveFast ( unsigned  item  )  [inline]

Remove an item by placing the end item in its place.

template<class _CT>
void SIMPLE_ARRAY< _CT >::RemoveItem ( unsigned  item  )  [inline]

Remove item at specified index, maintaining order.

Note that this is inefficient for large arrays.

template<class _CT>
void SIMPLE_ARRAY< _CT >::RemoveItems ( unsigned  item,
unsigned  count 
) [inline]

Remove items starting at specified index, maintaining order.

Note that this is inefficient for large arrays.

template<class _CT>
void SIMPLE_ARRAY< _CT >::RemoveLast ( unsigned  count = 1  )  [inline]

Remove last item(s) from array.

Parameters:
count Number of items to remove
template<class _CT>
bool SIMPLE_ARRAY< _CT >::RemoveMatchingItems ( const _CT &  item  )  [inline]

Remove items matching the item passed in.

_CT must have a operator==() defined Maintains item order

Returns:
'True' if one or more items was removed
template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::Reserve ( unsigned  newmaxitems,
bool  clear = false 
) [inline]

Reserve space in array for up to specified number of items.

Free the old array to avoid expensive copy in reallocation

Parameters:
newmaxitems New maximum number of items
clear Clear the array by resetting number of items to 0
template<class _CT>
void SIMPLE_ARRAY< _CT >::ReserveExc ( unsigned  newmaxitems,
bool  clear = false 
) [inline]

Reserve space in array for up to specified number of items.

Throws exception if out of memory.

Free the old array to avoid expensive copy in reallocation

Parameters:
newmaxitems New maximum number of items
clear Clear the array by resetting number of items to 0
template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::Resize ( unsigned  numitems,
bool  keepold = true,
bool  clear = false 
) [inline]

Resize array to specified number of items.

If the new size is larger than the previous size and the array is not cleared the new array entries will have indeterminant values.

Parameters:
numitems New number of items desired
keepold Keep old array entries
clear Clear new array items to zeros
template<class _CT>
void SIMPLE_ARRAY< _CT >::Reverse (  )  [inline]

Reverse order of items in array.

template<class _CT>
void SIMPLE_ARRAY< _CT >::SetAll ( const _CT &  value  )  [inline]

Set all items to specified value.

template<class _CT>
void SIMPLE_ARRAY< _CT >::SetItem ( unsigned  index,
const _CT &  item 
) [inline]

Set single item, does not verify index range.

Parameters:
index Item index, must be in range from 0 to NumItems-1
item Item value to set
template<class _CT>
ERRVALUE SIMPLE_ARRAY< _CT >::SetItems ( unsigned  firstitem,
const _CT *  items,
unsigned  numitems 
) [inline]

Set array items from C array, expanding if needed.

Will not reduce the number of items in the array.

Parameters:
firstitem First array item to replace
items Items to copy to array
numitems Number of items to copy
template<class _CT>
void SIMPLE_ARRAY< _CT >::Sort ( int(*)(_CT *, _CT *, void *)  CompFunc,
void *  data = 0 
) [inline]

Sort the items in the array.

CompFunc should return 1 if the first item sorts before the 2nd item Otherwise, return 0.

template<class _CT>
void SIMPLE_ARRAY< _CT >::SortRange ( int(*)(_CT *, _CT *, void *)  CompFunc,
unsigned  firstidx,
unsigned  numitems,
void *  data = 0 
) [inline]

Sort the items in the array.

CompFunc should return 1 if the first item sorts before the 2nd item Otherwise, return 0.

template<class _CT>
void SIMPLE_ARRAY< _CT >::Swap ( SIMPLE_ARRAY< _CT > &  rhs  )  [inline]

Swap (exchange) two SIMPLE_ARRAYs.

This exchanges the internal buffers so minimal copying is performed for efficiency.

template<class _CT>
void SIMPLE_ARRAY< _CT >::SwapBytes (  )  [inline]

Swap bytes in a SIMPLE_ARRAY, assume that there is an overload to swap a _CT.


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

Generated on Sun Oct 7 21:33:51 2012 for TNTsdk 2012 by  doxygen 1.6.1