XMLSerializable.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 <schuellchr@gmail.com>
  11. ------------------------------------------------------------------------------
  12. Inherit from this abstract class to have full control over the serialization
  13. of your user defined class.
  14. ----------------------------------------------------------------------------*/
  15. #ifndef IGL_XML_SERIALIZABLE_H
  16. #define IGL_XML_SERIALIZABLE_H
  17. #include <iostream>
  18. #include <tinyxml2.h>
  19. namespace igl
  20. {
  21. namespace
  22. {
  23. class XMLSerializable
  24. {
  25. public:
  26. /**
  27. * Default name of serializable object
  28. */
  29. std::string Name;
  30. /**
  31. * This function gets called if the objects were not found during deserialization.
  32. * Initialize your objects as you like.
  33. */
  34. virtual void Init() = 0;
  35. /**
  36. * Serialize your stuff within this function.
  37. * doc is the current serialization xml file. You can use SaveToXMLDoc to add your objects.
  38. */
  39. virtual void Serialize(tinyxml2::XMLDocument* doc,tinyxml2::XMLElement* element) = 0;
  40. /**
  41. * Deserialize your stuff within this function.
  42. * doc is the current serialization xml file. You can use LoadFromXMLDoc to read out your objects.
  43. */
  44. virtual void Deserialize(tinyxml2::XMLDocument* doc,const tinyxml2::XMLElement* element) = 0;
  45. };
  46. }
  47. }
  48. #endif