vrshoot

view libs/assimp/OgreXmlHelper.hpp @ 1:e7ca128b8713

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