JsonWriter.h 908 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * JsonWriter.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. #include "JsonNode.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class JsonWriter
  14. {
  15. //prefix for each line (tabulation)
  16. std::string prefix;
  17. std::ostream & out;
  18. //sets whether compact nodes are written in single-line format
  19. bool compact;
  20. //tracks whether we are currently using single-line format
  21. bool compactMode = false;
  22. public:
  23. template<typename Iterator>
  24. void writeContainer(Iterator begin, Iterator end);
  25. void writeEntry(JsonMap::const_iterator entry);
  26. void writeEntry(JsonVector::const_iterator entry);
  27. void writeString(const std::string & string);
  28. void writeNode(const JsonNode & node);
  29. JsonWriter(std::ostream & output, bool compact);
  30. };
  31. VCMI_LIB_NAMESPACE_END