XMLSerializable.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // Copyright (C) 2014 Christian Schüller <schuellchr@gmail.com>
  3. //
  4. // This Source Code Form is subject to the terms of the Mozilla Public License
  5. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  6. // obtain one at http://mozilla.org/MPL/2.0/.
  7. /* ------------------------------------------------------------------------------
  8. Inherit from this abstract class to have full control over the serialization
  9. of your user defined class.
  10. ----------------------------------------------------------------------------*/
  11. #ifndef IGL_XML_SERIALIZABLE_H
  12. #define IGL_XML_SERIALIZABLE_H
  13. #include <iostream>
  14. #include <tinyxml2.h>
  15. namespace igl
  16. {
  17. namespace
  18. {
  19. class XMLSerializable
  20. {
  21. public:
  22. /**
  23. * Default name of serializable object
  24. */
  25. std::string Name;
  26. /**
  27. * This function gets called if the objects were not found during deserialization.
  28. * Initialize your objects as you like.
  29. */
  30. virtual void Init() = 0;
  31. /**
  32. * Serialize your stuff within this function.
  33. * doc is the current serialization xml file. You can use SaveToXMLDoc to add your objects.
  34. */
  35. virtual bool Serialize(tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element) = 0;
  36. /**
  37. * Deserialize your stuff within this function.
  38. * doc is the current serialization xml file. You can use LoadFromXMLDoc to read out your objects.
  39. */
  40. virtual bool Deserialize(tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element) = 0;
  41. };
  42. }
  43. }
  44. #endif