ILICReader.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * JsonTreeSerializer.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 "ILICReader.h"
  12. #include "../JsonNode.h"
  13. #include <vstd/StringUtils.h>
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. void ILICReader::readLICPart(const JsonNode & part, const JsonSerializeFormat::TDecoder & decoder, bool val, std::vector<bool> & value) const
  16. {
  17. for(const auto & index : part.Vector())
  18. {
  19. const std::string & identifier = index.String();
  20. const std::string type = typeid(decltype(this)).name();
  21. const si32 rawId = decoder(identifier);
  22. if(rawId >= 0)
  23. {
  24. if(rawId < value.size())
  25. value[rawId] = val;
  26. else
  27. logGlobal->error("%s::serializeLIC: id out of bounds %d", type, rawId);
  28. }
  29. }
  30. }
  31. void ILICReader::readLICPart(const JsonNode & part, const JsonSerializeFormat::TDecoder & decoder, std::set<si32> & value) const
  32. {
  33. for(const auto & index : part.Vector())
  34. {
  35. const std::string & identifier = index.String();
  36. const si32 rawId = decoder(identifier);
  37. if(rawId != -1)
  38. value.insert(rawId);
  39. }
  40. }
  41. VCMI_LIB_NAMESPACE_END