



template<class T> ZArray<T>::ZArray() : mMaxNbEntries(0), mCurNbEntries(0), mEntries(NULL)
{
}


template<class T> ZArray<T>::~ZArray()
{
	DELETEARRAY(mEntries);
}


template<class T> bool ZArray<T>::Resize()
{
	// Get twice as many entries as before
	mMaxNbEntries = mMaxNbEntries ? (mMaxNbEntries<<1) : 2;	// Default nb Entries = 2

	// Get some bytes for new entries
	T*	NewEntries = new T[mMaxNbEntries];
	CHECKALLOC(NewEntries);

	// Copy old data if needed
	if(mCurNbEntries)		//CopyMemory(NewEntries, mEntries, mCurNbEntries*sizeof(T));
	{
		for(int k=0; k<mCurNbEntries; k++)		NewEntries[k] = mEntries[k];		
	}
	

	// Delete old data
	DELETEARRAY(mEntries);

	// Assign new pointer
	mEntries = NewEntries;

	return true;
}


template<class T> bool ZArray<T>::Contains(T entry, int* location) const
{
	// Look for the entry
	for(int i=0;i<mCurNbEntries;i++)
	{
		if(mEntries[i]==entry)
		{
			if(location)	*location = i;
			return true;
		}
	}
	return false;
}


template<class T> bool ZArray<T>::Delete(T entry)
{
	// Look for the entry
	for(int i=0;i<mCurNbEntries;i++)
	{
		if(mEntries[i]==entry)
		{
			// Entry has been found at index i. The strategy is to copy the last current entry at index i, and decrement the current number of entries.
			mEntries[i] = mEntries[--mCurNbEntries];
			return true;
		}
	}
	return false;
}


template<class T> int ZArray<T>::GetUsedRam() const
{
	return sizeof(ZArray) + mMaxNbEntries * sizeof(T);
}

