00001
00008
00009
00010
00011
00012
00016
00017
00018
00019 template<class T> Array<T>::Array() : mMaxNbEntries(0), mCurNbEntries(0), mEntries(NULL)
00020 {
00021 }
00022
00023
00024
00025 template<class T> Array<T>::~Array()
00026 {
00027 DELETEARRAY(mEntries);
00028 }
00029
00030
00031
00032 template<class T> bool Array<T>::Resize()
00033 {
00034
00035 mMaxNbEntries = mMaxNbEntries ? (mMaxNbEntries<<1) : 2;
00036
00037
00038 T* NewEntries = new T[mMaxNbEntries];
00039 CHECKALLOC(NewEntries);
00040
00041
00042 if(mCurNbEntries)
00043 {
00044 for(int k=0; k<mCurNbEntries; k++) NewEntries[k] = mEntries[k];
00045 }
00046
00047
00048
00049 DELETEARRAY(mEntries);
00050
00051
00052 mEntries = NewEntries;
00053
00054 return true;
00055 }
00056
00057
00058
00059 template<class T> bool Array<T>::Contains(T entry, int* location) const
00060 {
00061
00062 for(int i=0;i<mCurNbEntries;i++)
00063 {
00064 if(mEntries[i]==entry)
00065 {
00066 if(location) *location = i;
00067 return true;
00068 }
00069 }
00070 return false;
00071 }
00072
00073
00074
00075 template<class T> bool Array<T>::Delete(T entry)
00076 {
00077
00078 for(int i=0;i<mCurNbEntries;i++)
00079 {
00080 if(mEntries[i]==entry)
00081 {
00082
00083 mEntries[i] = mEntries[--mCurNbEntries];
00084 return true;
00085 }
00086 }
00087 return false;
00088 }
00089
00090
00091
00092 template<class T> int Array<T>::GetUsedRam() const
00093 {
00094 return sizeof(Array) + mMaxNbEntries * sizeof(T);
00095 }
00096