JsonSerializeFormat.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * JsonSerializeFormat.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. class JsonNode;
  12. class JsonSerializeFormat;
  13. class JsonStructSerializer: public boost::noncopyable
  14. {
  15. public:
  16. JsonStructSerializer(JsonStructSerializer && other);
  17. virtual ~JsonStructSerializer();
  18. JsonStructSerializer enterStruct(const std::string & fieldName);
  19. JsonNode & get();
  20. JsonSerializeFormat * operator->();
  21. private:
  22. JsonStructSerializer(JsonSerializeFormat & owner_, const std::string & fieldName);
  23. JsonStructSerializer(JsonStructSerializer & parent, const std::string & fieldName);
  24. bool restoreState;
  25. JsonSerializeFormat & owner;
  26. JsonNode * parentNode;
  27. JsonNode * thisNode;
  28. friend class JsonSerializeFormat;
  29. };
  30. class JsonSerializeFormat
  31. {
  32. public:
  33. JsonSerializeFormat(JsonNode & root_);
  34. virtual ~JsonSerializeFormat() = default;
  35. JsonNode & getRoot()
  36. {
  37. return *root;
  38. };
  39. JsonStructSerializer enterStruct(const std::string & fieldName);
  40. protected:
  41. JsonNode * root;
  42. JsonNode * current;
  43. private:
  44. friend class JsonStructSerializer;
  45. };