QGearsXMLSerializer.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-08-26 Tobias Peters <tobias.peters@kreativeffekt.at>
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. -----------------------------------------------------------------------------
  21. */
  22. #ifndef __QGearsXMLSerializer_H__
  23. #define __QGearsXMLSerializer_H__
  24. #include <OgreAxisAlignedBox.h>
  25. #include <OgreColourValue.h>
  26. #include <OgreSerializer.h>
  27. #include <OgreVector2.h>
  28. #include <OgreVector3.h>
  29. #include <tinyxml/tinyxml.h>
  30. #include "common/TypeDefine.h"
  31. namespace QGears
  32. {
  33. #ifdef NDEBUG
  34. #define assertElement( node )((void)0)
  35. #else
  36. #define assertElement( node )\
  37. {\
  38. if( node.Type() != TiXmlNode::TINYXML_ELEMENT )\
  39. {\
  40. OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS\
  41. ,"node has wrong type, needs to be TINYXML_ELEMENT"\
  42. ,"XMLSerializer::assertElement" );\
  43. }\
  44. }
  45. #endif
  46. class XMLSerializer
  47. {
  48. public:
  49. XMLSerializer();
  50. virtual ~XMLSerializer();
  51. protected:
  52. virtual void parse( Ogre::DataStreamPtr &stream, TiXmlDocument &pDest );
  53. virtual const String* readAttribute( TiXmlNode &node, const String &attribute );
  54. virtual bool readAttribute( TiXmlNode &node, const String &attribute, bool &pDest, const bool &pDefault = false );
  55. virtual bool readAttribute( TiXmlNode &node, const String &attribute, int &pDest, const int &pDefault = 0 );
  56. virtual bool readAttribute( TiXmlNode &node, const String &attribute, String &pDest, const String &pDefault = "" );
  57. virtual bool readAttribute( TiXmlNode &node, const String &attribute, Ogre::Real &pDest, const Ogre::Real &pDefault = 0 );
  58. virtual bool readAttribute( TiXmlNode &node, const String &attribute, Ogre::Vector2 &pDest, const Ogre::Vector2 &pDefault = Ogre::Vector2::ZERO );
  59. virtual bool readAttribute( TiXmlNode &node, const String &attribute, Ogre::Vector3 &pDest, const Ogre::Vector3 &pDefault = Ogre::Vector3::ZERO );
  60. virtual bool readAttribute( TiXmlNode &node, const String &attribute, Ogre::Vector4 &pDest, const Ogre::Vector4 &pDefault = Ogre::Vector4::ZERO );
  61. virtual bool readAttribute( TiXmlNode &node, const String &attribute, Ogre::Quaternion &pDest, const Ogre::Quaternion &pDefault = Ogre::Quaternion::IDENTITY );
  62. virtual TiXmlNode* findChildNode( TiXmlNode &node, const String &tag );
  63. private:
  64. };
  65. }
  66. #endif // __QGearsXMLSerializer_H__