//-----------------------------------------------------------------------------------------------
// NamedProperties.cpp
//
#include "GypsyPrecompiledHeader.hpp"
#include "Engine/Core/NamedProperties.hpp"


//-----------------------------------------------------------------------------------------------
STATIC const NamedProperties NamedProperties::s_empty;


/////////////////////////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------------------------
PropertyGetResult NamedProperties::Get( CaseSensitiveStringHashValue propertyNameHash, std::string& out_propertyData ) const
{
	std::vector< NamedPropertyEntry >::const_iterator propertyIter;
	for( propertyIter = m_properties.begin(); propertyIter != m_properties.end(); ++ propertyIter )
	{
		const NamedPropertyEntry& entry = *propertyIter;
		if( entry.m_propertyNameHash == propertyNameHash )
		{
			static const type_info& typeInfoStdString = typeid( std::string );
			static const type_info& typeInfoConstCharPtr = typeid( const char* );
			static size_t rttiHashStdString = typeInfoStdString.hash_code();
			static size_t rttiHashConstCharPtr = typeInfoConstCharPtr.hash_code();

			if( entry.m_rttiHash == rttiHashStdString )
			{
				TypedProperty< std::string >* typedProperty = reinterpret_cast< TypedProperty< std::string >* >( entry.m_property );
				out_propertyData = typedProperty->m_propertyData;
				return GET_RESULT_SUCCESS;
			}
			else if( entry.m_rttiHash == rttiHashConstCharPtr )
			{
				TypedProperty< const char* >* typedProperty = reinterpret_cast< TypedProperty< const char* >* >( entry.m_property );
				out_propertyData = typedProperty->m_propertyData;
				return GET_RESULT_SUCCESS;
			}
			else
			{
				return GET_RESULT_FAILURE_PROPERTY_WRONG_TYPE;
			}
		}
	}

	return GET_RESULT_FAILURE_PROPERTY_NOT_FOUND;
}


