XMLSerializable.h 1.7 KB

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