2
0

JsonSerializer.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * JsonSerializer.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 "JsonTreeSerializer.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class DLL_LINKAGE JsonSerializer : public JsonTreeSerializer<JsonNode *>
  14. {
  15. public:
  16. JsonSerializer(const IInstanceResolver * instanceResolver_, JsonNode & root_);
  17. void serializeLIC(const std::string & fieldName, const TDecoder & decoder, const TEncoder & encoder, const std::vector<bool> & standard, std::vector<bool> & value) override;
  18. void serializeLIC(const std::string & fieldName, LIC & value) override;
  19. void serializeLIC(const std::string & fieldName, LICSet & value) override;
  20. void serializeString(const std::string & fieldName, std::string & value) override;
  21. void serializeRaw(const std::string & fieldName, JsonNode & value, const std::optional<std::reference_wrapper<const JsonNode>> defaultValue) override;
  22. protected:
  23. void serializeInternal(const std::string & fieldName, boost::logic::tribool & value) override;
  24. void serializeInternal(const std::string & fieldName, si32 & value, const std::optional<si32> & defaultValue, const TDecoder & decoder, const TEncoder & encoder) override;
  25. void serializeInternal(const std::string & fieldName, std::vector<si32> & value, const TDecoder & decoder, const TEncoder & encoder) override;
  26. void serializeInternal(const std::string & fieldName, double & value, const std::optional<double> & defaultValue) override;
  27. void serializeInternal(const std::string & fieldName, si64 & value, const std::optional<si64> & defaultValue) override;
  28. void serializeInternal(const std::string & fieldName, si32 & value, const std::optional<si32> & defaultValue, const std::vector<std::string> & enumMap) override;
  29. void serializeInternal(std::string & value) override;
  30. void serializeInternal(int64_t & value) override;
  31. void pushStruct(const std::string & fieldName) override;
  32. void pushArray(const std::string & fieldName) override;
  33. void pushArrayElement(const size_t index) override;
  34. void resizeCurrent(const size_t newSize, JsonNode::JsonType type) override;
  35. private:
  36. void writeLICPart(const std::string & fieldName, const std::string & partName, const TEncoder & encoder, const std::vector<bool> & data);
  37. void writeLICPart(const std::string & fieldName, const std::string & partName, const TEncoder & encoder, const std::set<si32> & data);
  38. void writeLICPartBuffer(const std::string & fieldName, const std::string & partName, std::vector<std::string> & buffer);
  39. };
  40. VCMI_LIB_NAMESPACE_END