/** @file vrefcountedica.h
*	ICoreAllocator shim for abstract refcounted types.
*	@author Chris Burns (cburns@ea.com)
*
*	(c) 2012 Electronic Arts Inc.
*/

#ifndef EABASETYPESPLUS_VREFCOUNTEDICA_H_
#define EABASETYPESPLUS_VREFCOUNTEDICA_H_

#include "EABaseTypesPlus/vrefcounted.h"
#include "coreallocator/icoreallocatormacros.h"

namespace EA
{
namespace Types
{

	/*! @class	VRefCountedICA vrefcountedica.h "EABaseTypesPlus/vrefcountedica.h"
	*	@brief	Mixin implementation of DeleteThis() for IRefCounted using an ICoreAllocator member
	*/
	template<typename Base>
	class VRefCountedICA : public VRefCounted<Base>
	{
	public:

		VRefCountedICA();
		VRefCountedICA(EA::Allocator::ICoreAllocator* allocator);

	protected:

		/*!
		*	Delete this object
		*/
		inline virtual void DeleteThis();

		EA::Allocator::ICoreAllocator *mAllocator;
	};

	template<typename Base>
	VRefCountedICA<Base>::VRefCountedICA():
		VRefCounted<Base>(),
		mAllocator(NULL)
	{
	}

	template<typename Base>
	VRefCountedICA<Base>::VRefCountedICA(EA::Allocator::ICoreAllocator* allocator):
		VRefCounted<Base>(),
		mAllocator(allocator)
	{
	}

	template<typename Base>
	/* inline virtual */ void VRefCountedICA<Base>::DeleteThis()
	{
		CORE_DELETE(mAllocator, this);
	}
}
}

#endif /* EABASETYPESPLUS_VREFCOUNTEDICA_H_ */
