QGearsBackground2DFileXMLSerializer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 __QGearsBackground2DFileXMLSerializer_H__
  23. #define __QGearsBackground2DFileXMLSerializer_H__
  24. #include "common/TypeDefine.h"
  25. #include "data/QGearsXMLSerializer.h"
  26. #include "QGearsBackground2DFile.h"
  27. namespace QGears
  28. {
  29. class Background2DFileXMLSerializer : public XMLSerializer
  30. {
  31. public:
  32. Background2DFileXMLSerializer();
  33. virtual ~Background2DFileXMLSerializer();
  34. virtual void importBackground2DFile( Ogre::DataStreamPtr &stream, Background2DFile *pDest );
  35. protected:
  36. virtual void readHeader( TiXmlNode *node );
  37. virtual bool readAttribute( TiXmlNode &node, const String &attribute, Blending &pDest, const Blending &pDefault );
  38. using XMLSerializer::readAttribute;
  39. virtual void readObject( TiXmlNode &node, Tile &pDest );
  40. virtual void readObject( TiXmlNode &node, Animation &pDest );
  41. virtual void readObject( TiXmlNode &node, KeyFrame &pDest );
  42. static const String BLENDING_ALPHA;
  43. static const String BLENDING_ADD;
  44. static const String BLENDING_SUBTRACT;
  45. template<typename ValueType> void
  46. readVector( TiXmlNode &node, const String &tag, std::vector<ValueType> &pDest )
  47. {
  48. pDest.clear();
  49. TiXmlNode* child( node.FirstChild() );
  50. while( child != NULL )
  51. {
  52. if( child->Type() == TiXmlNode::TINYXML_ELEMENT && child->ValueStr() == tag )
  53. {
  54. ValueType in_tmp;
  55. readObject( *child, in_tmp );
  56. pDest.push_back( in_tmp );
  57. }
  58. child = child->NextSibling();
  59. }
  60. }
  61. template<typename KeyType, typename ValueType> void
  62. readMap( TiXmlNode& node, const String& tag, const String& key_attribute, std::map< KeyType, ValueType > &pDest )
  63. {
  64. pDest.clear();
  65. TiXmlNode* child( node.FirstChild() );
  66. while( child != NULL )
  67. {
  68. if( child->Type() == TiXmlNode::TINYXML_ELEMENT && child->ValueStr() == tag )
  69. {
  70. KeyType key;
  71. if( readAttribute( *child, key_attribute, key ) )
  72. {
  73. ValueType in_tmp;
  74. readObject( *child, in_tmp );
  75. pDest[key] = in_tmp;
  76. }
  77. }
  78. child = child->NextSibling();
  79. }
  80. }
  81. private:
  82. };
  83. }
  84. #endif // __QGearsBackground2DFileXMLSerializer_H__