vrshoot

annotate libs/assimp/OgreXmlHelper.hpp @ 3:c179c72369be

rename candy->vr
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 03 Feb 2014 08:52:13 +0200
parents
children
rev   line source
nuclear@0 1
nuclear@0 2 #include "irrXMLWrapper.h"
nuclear@0 3 #include "fast_atof.h"
nuclear@0 4
nuclear@0 5 namespace Assimp
nuclear@0 6 {
nuclear@0 7 namespace Ogre
nuclear@0 8 {
nuclear@0 9
nuclear@0 10 typedef irr::io::IrrXMLReader XmlReader;
nuclear@0 11
nuclear@0 12
nuclear@0 13 //------------Helper Funktion to Get a Attribute Save---------------
nuclear@0 14 template<typename t> inline t GetAttribute(XmlReader* Reader, std::string Name);
nuclear@0 15
nuclear@0 16 /*
nuclear@0 17 {
nuclear@0 18 BOOST_STATIC_ASSERT(false);
nuclear@0 19 return t();
nuclear@0 20 }
nuclear@0 21 */
nuclear@0 22
nuclear@0 23 template<> inline int GetAttribute<int>(XmlReader* Reader, std::string Name)
nuclear@0 24 {
nuclear@0 25 const char* Value=Reader->getAttributeValue(Name.c_str());
nuclear@0 26 if(Value)
nuclear@0 27 return atoi(Value);
nuclear@0 28 else
nuclear@0 29 throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
nuclear@0 30 }
nuclear@0 31
nuclear@0 32 template<> inline unsigned int GetAttribute<unsigned int>(XmlReader* Reader, std::string Name)
nuclear@0 33 {
nuclear@0 34 const char* Value=Reader->getAttributeValue(Name.c_str());
nuclear@0 35 if(Value)
nuclear@0 36 return static_cast<unsigned int>(atoi(Value));//yes, ugly, but pfff
nuclear@0 37 else
nuclear@0 38 throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
nuclear@0 39 }
nuclear@0 40
nuclear@0 41 template<> inline float GetAttribute<float>(XmlReader* Reader, std::string Name)
nuclear@0 42 {
nuclear@0 43 const char* Value=Reader->getAttributeValue(Name.c_str());
nuclear@0 44 if(Value)
nuclear@0 45 return fast_atof(Value);
nuclear@0 46 else
nuclear@0 47 throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
nuclear@0 48 }
nuclear@0 49
nuclear@0 50 template<> inline std::string GetAttribute<std::string>(XmlReader* Reader, std::string Name)
nuclear@0 51 {
nuclear@0 52 const char* Value=Reader->getAttributeValue(Name.c_str());
nuclear@0 53 if(Value)
nuclear@0 54 return std::string(Value);
nuclear@0 55 else
nuclear@0 56 throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
nuclear@0 57 }
nuclear@0 58
nuclear@0 59 template<> inline bool GetAttribute<bool>(XmlReader* Reader, std::string Name)
nuclear@0 60 {
nuclear@0 61 const char* Value=Reader->getAttributeValue(Name.c_str());
nuclear@0 62 if(Value)
nuclear@0 63 {
nuclear@0 64 if(Value==std::string("true"))
nuclear@0 65 return true;
nuclear@0 66 else if(Value==std::string("false"))
nuclear@0 67 return false;
nuclear@0 68 else
nuclear@0 69 throw DeadlyImportError(std::string("Bool value has invalid value: "+Name+" / "+Value+" / "+Reader->getNodeName()));
nuclear@0 70 }
nuclear@0 71 else
nuclear@0 72 throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
nuclear@0 73 }
nuclear@0 74 //__________________________________________________________________
nuclear@0 75
nuclear@0 76 inline bool XmlRead(XmlReader* Reader)
nuclear@0 77 {
nuclear@0 78 do
nuclear@0 79 {
nuclear@0 80 if(!Reader->read())
nuclear@0 81 return false;
nuclear@0 82 }
nuclear@0 83 while(Reader->getNodeType()!=irr::io::EXN_ELEMENT);
nuclear@0 84 return true;
nuclear@0 85 }
nuclear@0 86
nuclear@0 87 }//namespace Ogre
nuclear@0 88 }//namespace Assimp