#ifndef _COMMON_ARRAY_HPP_ #define _COMMON_ARRAY_HPP_ #ifndef _COMMON_WINDOWS_HPP_ #include #endif #ifndef _COMMON_EXCEPTION_HPP_ #include #endif template class Array { public: Array(void); Array(const Array &someArray); virtual ~Array(); T &operator[](DWORD index); T &elementAt(DWORD index); Array &operator=(const Array &someArray); bool operator==(const Array &someArray)const; DWORD size(void)const; void size(DWORD size); DWORD sizeBytes(void)const; private: void destroy(void); void create(DWORD elements); T *mpArray; DWORD mElements; }; template inline Array::Array(void) : mpArray(0), mElements(0) { } template inline Array::Array(const Array &someArray) : mpArray(0), mElements(0) { *this=someArray; } template inline Array::~Array() { destroy(); } template inline T &Array::operator[](DWORD index) { if(index>mElements)throw ArrayIndexOutOfBoundsException(); return mpArray[index]; } template inline Array &Array::operator=(const Array &someArray) { destroy(); if(!someArray.size())return *this; size(someArray.size()); for(unsigned index=0;index&)someArray)[index]; return *this; } template inline bool Array::operator==(const Array &someArray)const { if(!someArray.size()||(size()!=someArray.size()))return FALSE; for(int index=0;index<(int)size();index++)if(!(((Array&)*this).operator[](index)==((Array&)someArray)[index]))return FALSE; return TRUE; } template inline DWORD Array::sizeBytes(void)const { return mElements*sizeof(T); } template DWORD Array::size(void)const { return mElements; } template void Array::size(DWORD size) { create(size); } template inline void Array::destroy(void) { if(!mpArray)return; delete[] mpArray; mpArray=0; mElements=0; } template inline void Array::create(DWORD elements) { destroy(); if(!elements)return; mpArray=new T[elements]; if(0==mpArray)throw(NullError()); mElements=elements; } template inline T &Array::elementAt(DWORD index) { if(index>mElements)throw ArrayIndexOutOfBoundsException(); return mpArray[index]; } #endif