JsonSerializeFormat.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * JsonSerializeFormat.cpp, 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. #include "StdInc.h"
  11. #include "JsonSerializeFormat.h"
  12. #include "../JsonNode.h"
  13. //JsonStructSerializer
  14. JsonStructSerializer::JsonStructSerializer(JsonStructSerializer&& other):
  15. restoreState(false),
  16. owner(other.owner),
  17. parentNode(other.parentNode),
  18. thisNode(other.thisNode)
  19. {
  20. }
  21. JsonStructSerializer::~JsonStructSerializer()
  22. {
  23. if(restoreState)
  24. owner.current = parentNode;
  25. }
  26. JsonStructSerializer::JsonStructSerializer(JsonSerializeFormat& owner_, const std::string& fieldName):
  27. restoreState(true),
  28. owner(owner_),
  29. parentNode(owner.current),
  30. thisNode(&(parentNode->operator[](fieldName)))
  31. {
  32. owner.current = thisNode;
  33. }
  34. JsonStructSerializer::JsonStructSerializer(JsonStructSerializer & parent, const std::string & fieldName):
  35. restoreState(true),
  36. owner(parent.owner),
  37. parentNode(parent.thisNode),
  38. thisNode(&(parentNode->operator[](fieldName)))
  39. {
  40. owner.current = thisNode;
  41. }
  42. JsonStructSerializer JsonStructSerializer::enterStruct(const std::string & fieldName)
  43. {
  44. return JsonStructSerializer(*this, fieldName);
  45. }
  46. JsonNode& JsonStructSerializer::get()
  47. {
  48. return *thisNode;
  49. }
  50. JsonSerializeFormat * JsonStructSerializer::operator->()
  51. {
  52. return &owner;
  53. }
  54. JsonSerializeFormat::LIC::LIC(const std::vector<bool> & Standard, const TDecoder & Decoder, const TEncoder & Encoder):
  55. standard(Standard), decoder(Decoder), encoder(Encoder)
  56. {
  57. any = standard;
  58. all.resize(standard.size(), false);
  59. none.resize(standard.size(), false);
  60. }
  61. //JsonSerializeFormat
  62. JsonSerializeFormat::JsonSerializeFormat(JsonNode & root_, const bool saving_):
  63. saving(saving_),
  64. root(&root_),
  65. current(root)
  66. {
  67. }
  68. JsonStructSerializer JsonSerializeFormat::enterStruct(const std::string & fieldName)
  69. {
  70. JsonStructSerializer res(*this, fieldName);
  71. return res;
  72. }