/** @file refcountedica.h
*	ICoreAllocator shim for refcounted types in UX.
*	@author Chris Burns (cburns@ea.com)
*
*	UX
*	(c) 2011 Electronic Arts Inc.
*/

#ifndef EABASETYPESPLUS_REFCOUNTEDICA_H_
#define EABASETYPESPLUS_REFCOUNTEDICA_H_

#include "coreallocator/icoreallocatormacros.h"

namespace EA
{
namespace Types
{
	/*! @class	RefCountedICA refcountedica.h "ux_base/refcountedica.h"
	*	@brief	Mixin implementation of DeleteThis() for RefCounted using an ICoreAllocator member
	*/
	template<typename Base>
	class RefCountedICA : public Base
	{
	public:

		explicit RefCountedICA(EA::Allocator::ICoreAllocator* allocator);

		virtual ~RefCountedICA();

	protected:

		virtual void DeleteThis();

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

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

	template<typename Base>
	/* virtual */ RefCountedICA<Base>::~RefCountedICA()
	{
		mAllocator = NULL;
	}

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

}
}

#endif /* EABASETYPESPLUS_REFCOUNTEDICA_H_ */
