OgreXmlHelper.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "irrXMLWrapper.h"
  2. #include "fast_atof.h"
  3. namespace Assimp
  4. {
  5. namespace Ogre
  6. {
  7. typedef irr::io::IrrXMLReader XmlReader;
  8. //------------Helper Funktion to Get a Attribute Save---------------
  9. template<typename t> inline t GetAttribute(XmlReader* Reader, std::string Name);
  10. /*
  11. {
  12. BOOST_STATIC_ASSERT(false);
  13. return t();
  14. }
  15. */
  16. template<> inline int GetAttribute<int>(XmlReader* Reader, std::string Name)
  17. {
  18. const char* Value=Reader->getAttributeValue(Name.c_str());
  19. if(Value)
  20. return atoi(Value);
  21. else
  22. throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
  23. }
  24. template<> inline float GetAttribute<float>(XmlReader* Reader, std::string Name)
  25. {
  26. const char* Value=Reader->getAttributeValue(Name.c_str());
  27. if(Value)
  28. return fast_atof(Value);
  29. else
  30. throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
  31. }
  32. template<> inline std::string GetAttribute<std::string>(XmlReader* Reader, std::string Name)
  33. {
  34. const char* Value=Reader->getAttributeValue(Name.c_str());
  35. if(Value)
  36. return std::string(Value);
  37. else
  38. throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
  39. }
  40. template<> inline bool GetAttribute<bool>(XmlReader* Reader, std::string Name)
  41. {
  42. const char* Value=Reader->getAttributeValue(Name.c_str());
  43. if(Value)
  44. {
  45. if(Value==std::string("true"))
  46. return true;
  47. else if(Value==std::string("false"))
  48. return false;
  49. else
  50. throw DeadlyImportError(std::string("Bool value has invalid value: "+Name+" / "+Value+" / "+Reader->getNodeName()));
  51. }
  52. else
  53. throw DeadlyImportError(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
  54. }
  55. //__________________________________________________________________
  56. inline bool XmlRead(XmlReader* Reader)
  57. {
  58. do
  59. {
  60. if(!Reader->read())
  61. return false;
  62. }
  63. while(Reader->getNodeType()!=irr::io::EXN_ELEMENT);
  64. return true;
  65. }
  66. }//namespace Ogre
  67. }//namespace Assimp