#ifndef __ZOOARRAY_H__
#define __ZOOARRAY_H__


#include	"..\Basic\ZooStd.h"


template<class T> class ZArray
{
	public:

		ZArray();
		~ZArray();


		__forceinline	ZArray&		Add(T entry)
		{
			if(mCurNbEntries==mMaxNbEntries)	Resize();
			mEntries[mCurNbEntries++] = entry;
			return *this;
		}

		__forceinline	ZArray&		Insert(T entry, int location)
		{
			if(mCurNbEntries==mMaxNbEntries)	Resize();

			for(int j=mCurNbEntries; j>location; j--)				mEntries[j] = mEntries[j-1];
			mEntries[location] = entry;

			mCurNbEntries++;
			
			return *this;
		}

		// Add unique [slow]
		ZArray&		AddUnique(T entry)
		{
			if(!Contains(entry))	Add(entry);
			return *this;
		}


		__forceinline	ZArray&		Empty()
		{
			DELETEARRAY(mEntries);
			mCurNbEntries = mMaxNbEntries = 0;
			return *this;
		}


		__forceinline	ZArray&		Clear()
		{
			mCurNbEntries = 0;
			return *this;
		}


						bool		Contains(T entry, int* location=NULL) const;

						bool		Delete(T entry);
		__forceinline	void		DeleteLastEntry()			{	if(mCurNbEntries)	mCurNbEntries--;	}
		__forceinline	void		DeleteIndex(int index)		{	mEntries[index] = mEntries[--mCurNbEntries];	}

						int			GetUsedRam()		const;
		__forceinline	int			Size()				const	{ return mCurNbEntries;	}	//!< Returns the current number of entries.
		__forceinline	int			SizeMax()			const	{ return mMaxNbEntries;	}	//!< Returns the current number of entries.
		__forceinline	T&			GetEntry(int i)		const	{ return mEntries[i];	}	//!< Returns ith entry
		__forceinline	T*			GetEntries()		const	{ return mEntries;		}	//!< Returns the list of entries.
		__forceinline	T&			operator[](int i)	const	{ ASSERT(i>=0 && i<mCurNbEntries); return mEntries[i];	}



	private:

						bool		Resize();

						int			mMaxNbEntries;		//!< Maximum possible number of entries
						int			mCurNbEntries;		//!< Current number of entries
						T*			mEntries;			//!< List of entries
};


#include	"ZooArray.inl"


#endif
