vrshoot

diff libs/assimp/OgreXmlHelper.hpp @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/assimp/OgreXmlHelper.hpp	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,88 @@
     1.4 +
     1.5 +#include "irrXMLWrapper.h"
     1.6 +#include "fast_atof.h"
     1.7 +
     1.8 +namespace Assimp
     1.9 +{
    1.10 +namespace Ogre
    1.11 +{
    1.12 +	
    1.13 +typedef irr::io::IrrXMLReader XmlReader;
    1.14 +
    1.15 +
    1.16 +//------------Helper Funktion to Get a Attribute Save---------------
    1.17 +template<typename t> inline t GetAttribute(XmlReader* Reader, std::string Name);
    1.18 +
    1.19 +/*
    1.20 +{
    1.21 +	BOOST_STATIC_ASSERT(false);
    1.22 +	return t();
    1.23 +}
    1.24 +*/
    1.25 +
    1.26 +template<> inline int GetAttribute<int>(XmlReader* Reader, std::string Name)
    1.27 +{
    1.28 +	const char* Value=Reader->getAttributeValue(Name.c_str());
    1.29 +	if(Value)
    1.30 +		return atoi(Value);
    1.31 +	else
    1.32 +		throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
    1.33 +}
    1.34 +
    1.35 +template<> inline unsigned int GetAttribute<unsigned int>(XmlReader* Reader, std::string Name)
    1.36 +{
    1.37 +	const char* Value=Reader->getAttributeValue(Name.c_str());
    1.38 +	if(Value)
    1.39 +		return static_cast<unsigned int>(atoi(Value));//yes, ugly, but pfff
    1.40 +	else
    1.41 +		throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
    1.42 +}
    1.43 +
    1.44 +template<> inline float GetAttribute<float>(XmlReader* Reader, std::string Name)
    1.45 +{
    1.46 +	const char* Value=Reader->getAttributeValue(Name.c_str());
    1.47 +	if(Value)
    1.48 +		return fast_atof(Value);
    1.49 +	else
    1.50 +		throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
    1.51 +}
    1.52 +
    1.53 +template<> inline std::string GetAttribute<std::string>(XmlReader* Reader, std::string Name)
    1.54 +{
    1.55 +	const char* Value=Reader->getAttributeValue(Name.c_str());
    1.56 +	if(Value)
    1.57 +		return std::string(Value);
    1.58 +	else
    1.59 +		throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
    1.60 +}
    1.61 +
    1.62 +template<> inline bool GetAttribute<bool>(XmlReader* Reader, std::string Name)
    1.63 +{
    1.64 +	const char* Value=Reader->getAttributeValue(Name.c_str());
    1.65 +	if(Value)
    1.66 +	{
    1.67 +		if(Value==std::string("true"))
    1.68 +			return true;
    1.69 +		else if(Value==std::string("false"))
    1.70 +			return false;
    1.71 +		else
    1.72 +			throw DeadlyImportError(std::string("Bool value has invalid value: "+Name+" / "+Value+" / "+Reader->getNodeName()));
    1.73 +	}
    1.74 +	else
    1.75 +		throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
    1.76 +}
    1.77 +//__________________________________________________________________
    1.78 +
    1.79 +inline bool XmlRead(XmlReader* Reader)
    1.80 +{
    1.81 +	do
    1.82 +	{
    1.83 +		if(!Reader->read())
    1.84 +			return false;
    1.85 +	}
    1.86 +	while(Reader->getNodeType()!=irr::io::EXN_ELEMENT);
    1.87 +	return true;
    1.88 +}
    1.89 +
    1.90 +}//namespace Ogre
    1.91 +}//namespace Assimp