00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef TA_PTRARRAY_H
00013 #define TA_PTRARRAY_H
00014
00015 #ifndef TA_COMMON_H
00016 #include "Common.h"
00017 #endif // TA_COMMON_H
00018
00019 namespace TA
00020 {
00021
00022 template <class Type>
00023 class TACOMMON_CLASS PtrArray
00024 {
00025 public:
00026 class Iterator
00027 {
00028 public:
00029 ~Iterator() { Finalise(); }
00030 Type* operator ++()
00031 {
00032 if (m_nCountLeft <= 0)
00033 return 0;
00034 else
00035 {
00036 m_nCountLeft--;
00037 return *(++m_ppCurrentPtr);
00038 }
00039 }
00040 Type& operator *() { return **m_ppCurrentPtr; }
00041 bool AtEnd() { return m_nCountLeft <= 0; }
00042 private:
00043 friend PtrArray;
00044 Iterator() { m_ppCurrentPtr = 0; m_nCountLeft = 0; }
00045 void Initialise(Type** ppCurrentPtr, int nSize) { m_ppCurrentPtr = ppCurrentPtr; m_nCountLeft = nSize; }
00046 void Finalise() { m_ppCurrentPtr = 0; m_nCountLeft = 0; }
00047 Type** m_ppCurrentPtr;
00048 int m_nCountLeft;
00049 };
00050
00051 PtrArray();
00052 ~PtrArray();
00053
00054 void Initialise(int nInitialSize, int nInitialMaxSize, int nBlockSize = 32);
00055 void Finalise();
00056 void Clear();
00057
00058 Type* operator [] (int nIndex);
00059 const Type* operator [] (int nIndex) const;
00060
00061 int GetSize() const;
00062 Type* Append();
00063 void Append(const Type& type);
00064 void Remove(int nIndex);
00065 void RemoveByValue(Type* pType);
00066 Type* Insert(int nIndex);
00067 void ReallocateIfNecessary(int nNewMaxSize);
00068 Iterator GetIterator();
00069
00070 private:
00071 int m_nSize;
00072 int m_nMaxSize;
00073 int m_nBlockSize;
00074 Type** m_ppArray;
00075 };
00076
00077 }
00078
00079 #include "PtrArray.inl"
00080
00081
00082 #endif // TA_ARRAY_H
© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.