/****************************************************************************************************

		MCIndex.h
		Copyright: (c) 2002 Eovia Corp. All rights reserved.

		Author:	Arnaud
		Date:	1/12/2003

****************************************************************************************************/

#ifndef __MCIndex__
#define __MCIndex__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCBasicTypes.h"

/// \addtogroup MCCore
/// \{

/// Base class to create index classes when you need the compiler to perform type checking.
/// Example: class TCellIndex : public TMCIndex<int32> { };
///
template <class TIndexType> class TMCIndex
{
public:
	//No constructor taking a TIndexType to enforce no implicit conversion
	inline				TMCIndex	()								: fValue(sInvalidIndex)	{}
	inline				TMCIndex	(const TMCIndex& index)			{ fValue = index.fValue; }
	inline TMCIndex&	operator=	(const TMCIndex& index)			{ fValue = index.fValue; return *this; }
			
	inline void			operator++	()								{ fValue++; }
	inline boolean		operator<	(TIndexType count)		const	{ return (fValue <  count); }
	inline boolean		operator<=	(TIndexType count)		const	{ return (fValue <= count); }
	inline boolean		operator==	(const TMCIndex& index)	const	{ return (fValue == index.fValue); }
	inline boolean		operator!=	(const TMCIndex& index)	const	{ return (fValue != index.fValue); }
	inline boolean		operator<	(const TMCIndex& index)	const	{ return (fValue <  index.fValue); }
	inline boolean		operator<=	(const TMCIndex& index)	const	{ return (fValue <= index.fValue); }

	inline TIndexType	GetValue	() const						{ MCAssert(IsValid()); return fValue; }
	inline void			SetValue	(TIndexType value)				{ fValue= value; MCAssert(IsValid()); }
	
	inline boolean		IsValid		() const						{ return ((fValue != sInvalidIndex) && (fValue >= 0)); }
	inline boolean		IsInvalid	() const						{ return ((fValue == sInvalidIndex) || (fValue <  0)); }

	inline void			MakeInvalid	()								{ fValue= sInvalidIndex; }

protected:
	TIndexType fValue;
	static const TIndexType sInvalidIndex;
};

/// \}

template<class TIndexType> const TIndexType TMCIndex<TIndexType>::sInvalidIndex= -1;





#endif
