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

#include "EABaseTypes/callermap.h"

namespace EA
{
	namespace Types
	{
		CallerMap::CallerMap(EA::Allocator::ICoreAllocator* allocator):
			mMap(allocator)
		{
		}

		void CallerMap::Add(unsigned int calleeType, unsigned int callerType, DecodeFunction argumentDecode, DecodeFunction resultDecode)
		{
			mMap[eastl::pair<unsigned int, unsigned int>(calleeType, callerType)] = eastl::pair<DecodeFunction, DecodeFunction>(argumentDecode, resultDecode);
		}

		void CallerMap::Remove(unsigned int calleeType, unsigned int callerType)
		{
			mMap.erase(eastl::pair<unsigned int, unsigned int>(calleeType, callerType));
		}

		//lint -efunc(904, EA::Types::CallerMap::Get)
		const eastl::pair<DecodeFunction, DecodeFunction>* CallerMap::Get(unsigned int calleeType, unsigned int callerType) const
		{
			Map::const_iterator it = mMap.find(eastl::pair<unsigned int, unsigned int>(calleeType, callerType));
			if(it != mMap.end())
			{
				return &(*it).second;
			}
			else
			{
				return NULL;
			}
		}
	}
}
