nuclear@0: nuclear@0: #include "irrXMLWrapper.h" nuclear@0: #include "fast_atof.h" nuclear@0: nuclear@0: namespace Assimp nuclear@0: { nuclear@0: namespace Ogre nuclear@0: { nuclear@0: nuclear@0: typedef irr::io::IrrXMLReader XmlReader; nuclear@0: nuclear@0: nuclear@0: //------------Helper Funktion to Get a Attribute Save--------------- nuclear@0: template inline t GetAttribute(XmlReader* Reader, std::string Name); nuclear@0: nuclear@0: /* nuclear@0: { nuclear@0: BOOST_STATIC_ASSERT(false); nuclear@0: return t(); nuclear@0: } nuclear@0: */ nuclear@0: nuclear@0: template<> inline int GetAttribute(XmlReader* Reader, std::string Name) nuclear@0: { nuclear@0: const char* Value=Reader->getAttributeValue(Name.c_str()); nuclear@0: if(Value) nuclear@0: return atoi(Value); nuclear@0: else nuclear@0: throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str()); nuclear@0: } nuclear@0: nuclear@0: template<> inline unsigned int GetAttribute(XmlReader* Reader, std::string Name) nuclear@0: { nuclear@0: const char* Value=Reader->getAttributeValue(Name.c_str()); nuclear@0: if(Value) nuclear@0: return static_cast(atoi(Value));//yes, ugly, but pfff nuclear@0: else nuclear@0: throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str()); nuclear@0: } nuclear@0: nuclear@0: template<> inline float GetAttribute(XmlReader* Reader, std::string Name) nuclear@0: { nuclear@0: const char* Value=Reader->getAttributeValue(Name.c_str()); nuclear@0: if(Value) nuclear@0: return fast_atof(Value); nuclear@0: else nuclear@0: throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str()); nuclear@0: } nuclear@0: nuclear@0: template<> inline std::string GetAttribute(XmlReader* Reader, std::string Name) nuclear@0: { nuclear@0: const char* Value=Reader->getAttributeValue(Name.c_str()); nuclear@0: if(Value) nuclear@0: return std::string(Value); nuclear@0: else nuclear@0: throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str()); nuclear@0: } nuclear@0: nuclear@0: template<> inline bool GetAttribute(XmlReader* Reader, std::string Name) nuclear@0: { nuclear@0: const char* Value=Reader->getAttributeValue(Name.c_str()); nuclear@0: if(Value) nuclear@0: { nuclear@0: if(Value==std::string("true")) nuclear@0: return true; nuclear@0: else if(Value==std::string("false")) nuclear@0: return false; nuclear@0: else nuclear@0: throw DeadlyImportError(std::string("Bool value has invalid value: "+Name+" / "+Value+" / "+Reader->getNodeName())); nuclear@0: } nuclear@0: else nuclear@0: throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str()); nuclear@0: } nuclear@0: //__________________________________________________________________ nuclear@0: nuclear@0: inline bool XmlRead(XmlReader* Reader) nuclear@0: { nuclear@0: do nuclear@0: { nuclear@0: if(!Reader->read()) nuclear@0: return false; nuclear@0: } nuclear@0: while(Reader->getNodeType()!=irr::io::EXN_ELEMENT); nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: }//namespace Ogre nuclear@0: }//namespace Assimp