/** @file callermap.h
*	A type for the map of optimized caller functions
*	@author Chris Burns (cburns@ea.com)
*
*	EABaseTypes
*	(c) 2012 Electronic Arts Inc.
*/

#ifndef EABASETYPES_CALLERMAP_H_
#define EABASETYPES_CALLERMAP_H_

#include "EASTLICA/hash_map.h"

namespace eastl
{
	template<>
	struct hash<eastl::pair<unsigned int, unsigned int> >
	{
		size_t operator()(const eastl::pair<unsigned int, unsigned int>& p) const
		{
			// cantor pairing function
			unsigned int k1 = p.first;
			unsigned int k2 = p.second;

			return (((k1 + k2) * (k1 + k2 + 1)) >> 1) + k2;
		}
	};
}

namespace EA
{
	namespace Allocator
	{
		class ICoreAllocator;
	}

	namespace Types
	{
		typedef void (*DecodeFunction)(void*, void*);

		class CallerMap
		{
		public:

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

			void Add(unsigned int calleeType, unsigned int callerType, DecodeFunction argumentDecode, DecodeFunction resultDecode);
			void Remove(unsigned int calleeType, unsigned int callerType);

			const eastl::pair<DecodeFunction, DecodeFunction>* Get(unsigned int calleeType, unsigned int callerType) const;

		private:

			typedef EASTLICA::HashMap<eastl::pair<unsigned int, unsigned int>, eastl::pair<DecodeFunction, DecodeFunction> > Map;

			Map mMap;
		};
	}
}

#endif /* EABASETYPES_CALLERMAP_H_ */
