XMLSerializable.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* ---------------------------------------------------------------------------
  2. // XMLSerializable.h
  3. // Author: Christian Schüller on 19/11/13.
  4. ------------------------------------------------------------------------------
  5. Inherit from this abstract class to have full control over the serialization
  6. of your user defined class.
  7. ----------------------------------------------------------------------------*/
  8. #ifndef XML_SERIALIZABLE_H
  9. #define XML_SERIALIZABLE_H
  10. #include <iostream>
  11. #include <tinyxml2.h>
  12. namespace igl
  13. {
  14. class XMLSerializable
  15. {
  16. public:
  17. /**
  18. * Default name of serializable object
  19. */
  20. std::string Name;
  21. /**
  22. * This function gets called if the objects were not found during deserialization.
  23. * Initialize your objects as you like.
  24. */
  25. virtual void Init() = 0;
  26. /**
  27. * Serialize your stuff within this function.
  28. * It contains the current serialization xml file. You can use SaveToXMLDoc or SaveGroupToXMLElement to add your objects.
  29. */
  30. virtual bool Serialize(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* element) = 0;
  31. /**
  32. * Deserialize your stuff within this function.
  33. * It contains the current serialization xml file. You can use LoadFromXMLDoc or LoadGroupFromXMLElement to read out your objects.
  34. */
  35. virtual bool Deserialize(tinyxml2::XMLDocument* doc, const tinyxml2::XMLElement* element) = 0;
  36. };
  37. }
  38. #endif