OgreXmlHelper.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. throw std::exception("unimplemented Funtcion used!");
  12. return t();
  13. }
  14. template<> inline int GetAttribute<int>(XmlReader* Reader, std::string Name)
  15. {
  16. const char* Value=Reader->getAttributeValue(Name.c_str());
  17. if(Value)
  18. return atoi(Value);
  19. else
  20. throw new ImportErrorException(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
  21. }
  22. template<> inline float GetAttribute<float>(XmlReader* Reader, std::string Name)
  23. {
  24. const char* Value=Reader->getAttributeValue(Name.c_str());
  25. if(Value)
  26. return fast_atof(Value);
  27. else
  28. throw new ImportErrorException(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
  29. }
  30. template<> inline std::string GetAttribute<std::string>(XmlReader* Reader, std::string Name)
  31. {
  32. const char* Value=Reader->getAttributeValue(Name.c_str());
  33. if(Value)
  34. return std::string(Value);
  35. else
  36. throw new ImportErrorException(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
  37. }
  38. template<> inline bool GetAttribute<bool>(XmlReader* Reader, std::string Name)
  39. {
  40. const char* Value=Reader->getAttributeValue(Name.c_str());
  41. if(Value)
  42. {
  43. if(Value==std::string("true"))
  44. return true;
  45. else if(Value==std::string("false"))
  46. return false;
  47. else
  48. throw new ImportErrorException(std::string("Bool value has invalid value: "+Name+" / "+Value+" / "+Reader->getNodeName()));
  49. }
  50. else
  51. throw new ImportErrorException(std::string("Attribute "+Name+" does not exist in "+Reader->getNodeName()).c_str());
  52. }
  53. //__________________________________________________________________
  54. inline bool XmlRead(XmlReader* Reader)
  55. {
  56. do
  57. {
  58. if(!Reader->read())
  59. return false;
  60. }
  61. while(Reader->getNodeType()!=irr::io::EXN_ELEMENT);
  62. return true;
  63. }
  64. }//namespace Ogre
  65. }//namespace Assimp