namespace Salamander
{

template <typename SourceType, typename TargetType>
std::map<SourceType, TargetType> IMapping<SourceType, TargetType>::mapping_;

template <typename SourceType, typename TargetType>
IMapping<SourceType, TargetType>::IMapping(const SourceType sourceType) :
	sourceType_(sourceType),
	targetType_(TargetType(NULL))
{
	
}

template <typename SourceType, typename TargetType>
IMapping<SourceType, TargetType>::~IMapping()
{

}

template <typename SourceType, typename TargetType>
IMapping<SourceType, TargetType>::operator TargetType()
{
	// If this is the first instantiation of the class, we need to fill our
	// mapping table.
	if(mapping_.empty())
	{
		initialiseMapping();
	}

	// Use the filled table to find an appropriate mapping.
	if(!targetType_)
	{
		targetType_ = mapping_[sourceType_];
	}

	// Return the pre-determined mapping.
	return targetType_;
}

template <typename SourceType, typename TargetType>
bool IMapping<SourceType, TargetType>::addMapping(const SourceType sourceType, const TargetType targetType)
{
	// Add a mapping to the table.
	mapping_[sourceType] = targetType;
	return true;
}

}
