2024-02-11 23:09:01 +02:00
|
|
|
/*
|
|
|
|
* JsonNode.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "JsonNode.h"
|
|
|
|
|
|
|
|
#include "JsonParser.h"
|
|
|
|
#include "JsonWriter.h"
|
2024-02-13 19:16:35 +02:00
|
|
|
#include "filesystem/Filesystem.h"
|
2024-02-11 23:09:01 +02:00
|
|
|
|
|
|
|
// to avoid duplicating const and non-const code
|
|
|
|
template<typename Node>
|
|
|
|
Node & resolvePointer(Node & in, const std::string & pointer)
|
|
|
|
{
|
|
|
|
if(pointer.empty())
|
|
|
|
return in;
|
|
|
|
assert(pointer[0] == '/');
|
|
|
|
|
|
|
|
size_t splitPos = pointer.find('/', 1);
|
|
|
|
|
|
|
|
std::string entry = pointer.substr(1, splitPos - 1);
|
2024-06-24 03:23:26 +02:00
|
|
|
std::string remainder = splitPos == std::string::npos ? "" : pointer.substr(splitPos);
|
2024-02-11 23:09:01 +02:00
|
|
|
|
|
|
|
if(in.getType() == VCMI_LIB_WRAP_NAMESPACE(JsonNode)::JsonType::DATA_VECTOR)
|
|
|
|
{
|
|
|
|
if(entry.find_first_not_of("0123456789") != std::string::npos) // non-numbers in string
|
|
|
|
throw std::runtime_error("Invalid Json pointer");
|
|
|
|
|
|
|
|
if(entry.size() > 1 && entry[0] == '0') // leading zeros are not allowed
|
|
|
|
throw std::runtime_error("Invalid Json pointer");
|
|
|
|
|
|
|
|
auto index = boost::lexical_cast<size_t>(entry);
|
|
|
|
|
2024-02-13 19:16:35 +02:00
|
|
|
if(in.Vector().size() > index)
|
2024-06-24 03:23:26 +02:00
|
|
|
return in.Vector()[index].resolvePointer(remainder);
|
2024-02-11 23:09:01 +02:00
|
|
|
}
|
2024-06-24 03:23:26 +02:00
|
|
|
return in[entry].resolvePointer(remainder);
|
2024-02-11 23:09:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2024-02-13 22:19:24 +02:00
|
|
|
static const JsonNode nullNode;
|
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
class LibClasses;
|
|
|
|
class CModHandler;
|
|
|
|
|
2024-02-13 13:18:10 +02:00
|
|
|
JsonNode::JsonNode(bool boolean)
|
2024-02-13 19:16:35 +02:00
|
|
|
: data(boolean)
|
|
|
|
{
|
|
|
|
}
|
2024-02-11 23:09:01 +02:00
|
|
|
|
2024-02-13 13:18:10 +02:00
|
|
|
JsonNode::JsonNode(int32_t number)
|
2024-02-13 19:16:35 +02:00
|
|
|
: data(static_cast<int64_t>(number))
|
|
|
|
{
|
|
|
|
}
|
2024-02-11 23:09:01 +02:00
|
|
|
|
2024-02-13 13:18:10 +02:00
|
|
|
JsonNode::JsonNode(uint32_t number)
|
2024-02-13 19:16:35 +02:00
|
|
|
: data(static_cast<int64_t>(number))
|
|
|
|
{
|
|
|
|
}
|
2024-02-13 13:18:10 +02:00
|
|
|
|
|
|
|
JsonNode::JsonNode(int64_t number)
|
2024-02-13 19:16:35 +02:00
|
|
|
: data(number)
|
|
|
|
{
|
|
|
|
}
|
2024-02-13 13:18:10 +02:00
|
|
|
|
|
|
|
JsonNode::JsonNode(double number)
|
2024-02-13 19:16:35 +02:00
|
|
|
: data(number)
|
|
|
|
{
|
|
|
|
}
|
2024-02-13 13:18:10 +02:00
|
|
|
|
2024-02-29 17:33:00 +02:00
|
|
|
JsonNode::JsonNode(const char * string)
|
|
|
|
: data(std::string(string))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-02-13 13:18:10 +02:00
|
|
|
JsonNode::JsonNode(const std::string & string)
|
2024-02-13 19:16:35 +02:00
|
|
|
: data(string)
|
|
|
|
{
|
|
|
|
}
|
2024-02-13 13:18:10 +02:00
|
|
|
|
2024-07-17 14:37:58 +02:00
|
|
|
JsonNode::JsonNode(const std::byte * data, size_t datasize, const std::string & fileName)
|
2024-07-17 13:07:57 +02:00
|
|
|
: JsonNode(data, datasize, JsonParsingSettings(), fileName)
|
2024-02-13 19:16:35 +02:00
|
|
|
{
|
|
|
|
}
|
2024-02-13 18:08:35 +02:00
|
|
|
|
2024-07-17 14:37:58 +02:00
|
|
|
JsonNode::JsonNode(const std::byte * data, size_t datasize, const JsonParsingSettings & parserSettings, const std::string & fileName)
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
2024-02-13 22:19:24 +02:00
|
|
|
JsonParser parser(data, datasize, parserSettings);
|
2024-07-17 13:07:57 +02:00
|
|
|
*this = parser.parse(fileName);
|
2024-02-11 23:09:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode::JsonNode(const JsonPath & fileURI)
|
2024-02-13 22:19:24 +02:00
|
|
|
:JsonNode(fileURI, JsonParsingSettings())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode::JsonNode(const JsonPath & fileURI, const JsonParsingSettings & parserSettings)
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
|
|
|
auto file = CResourceHandler::get()->load(fileURI)->readAll();
|
|
|
|
|
2024-02-13 22:19:24 +02:00
|
|
|
JsonParser parser(reinterpret_cast<std::byte *>(file.first.get()), file.second, parserSettings);
|
2024-02-11 23:09:01 +02:00
|
|
|
*this = parser.parse(fileURI.getName());
|
|
|
|
}
|
|
|
|
|
2024-10-30 12:51:02 +02:00
|
|
|
JsonNode::JsonNode(const JsonPath & fileURI, const std::string & modName)
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
2024-10-30 12:51:02 +02:00
|
|
|
auto file = CResourceHandler::get(modName)->load(fileURI)->readAll();
|
2024-02-13 19:16:35 +02:00
|
|
|
|
2024-02-13 22:19:24 +02:00
|
|
|
JsonParser parser(reinterpret_cast<std::byte *>(file.first.get()), file.second, JsonParsingSettings());
|
2024-02-11 23:09:01 +02:00
|
|
|
*this = parser.parse(fileURI.getName());
|
|
|
|
}
|
|
|
|
|
2024-10-30 12:51:02 +02:00
|
|
|
JsonNode::JsonNode(const JsonPath & fileURI, const std::string & modName, bool & isValidSyntax)
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
2024-10-30 12:51:02 +02:00
|
|
|
auto file = CResourceHandler::get(modName)->load(fileURI)->readAll();
|
2024-02-11 23:09:01 +02:00
|
|
|
|
2024-02-13 22:19:24 +02:00
|
|
|
JsonParser parser(reinterpret_cast<std::byte *>(file.first.get()), file.second, JsonParsingSettings());
|
2024-02-11 23:09:01 +02:00
|
|
|
*this = parser.parse(fileURI.getName());
|
|
|
|
isValidSyntax = parser.isValid();
|
|
|
|
}
|
|
|
|
|
2024-02-13 19:16:35 +02:00
|
|
|
bool JsonNode::operator==(const JsonNode & other) const
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
|
|
|
return data == other.data;
|
|
|
|
}
|
|
|
|
|
2024-02-13 19:16:35 +02:00
|
|
|
bool JsonNode::operator!=(const JsonNode & other) const
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode::JsonType JsonNode::getType() const
|
|
|
|
{
|
|
|
|
return static_cast<JsonType>(data.index());
|
|
|
|
}
|
|
|
|
|
2024-02-13 14:34:16 +02:00
|
|
|
const std::string & JsonNode::getModScope() const
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
2024-02-13 14:34:16 +02:00
|
|
|
return modScope;
|
|
|
|
}
|
|
|
|
|
2024-02-13 15:20:08 +02:00
|
|
|
void JsonNode::setOverrideFlag(bool value)
|
|
|
|
{
|
|
|
|
overrideFlag = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonNode::getOverrideFlag() const
|
|
|
|
{
|
|
|
|
return overrideFlag;
|
|
|
|
}
|
|
|
|
|
2024-02-13 14:34:16 +02:00
|
|
|
void JsonNode::setModScope(const std::string & metadata, bool recursive)
|
|
|
|
{
|
|
|
|
modScope = metadata;
|
2024-02-13 19:16:35 +02:00
|
|
|
if(recursive)
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
2024-02-13 19:16:35 +02:00
|
|
|
switch(getType())
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
2024-02-13 19:16:35 +02:00
|
|
|
break;
|
|
|
|
case JsonType::DATA_VECTOR:
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
|
|
|
for(auto & node : Vector())
|
|
|
|
{
|
2024-02-13 14:34:16 +02:00
|
|
|
node.setModScope(metadata);
|
2024-02-11 23:09:01 +02:00
|
|
|
}
|
|
|
|
}
|
2024-02-13 19:16:35 +02:00
|
|
|
break;
|
|
|
|
case JsonType::DATA_STRUCT:
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
|
|
|
for(auto & node : Struct())
|
|
|
|
{
|
2024-02-13 14:34:16 +02:00
|
|
|
node.second.setModScope(metadata);
|
2024-02-11 23:09:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonNode::setType(JsonType Type)
|
|
|
|
{
|
2024-02-13 19:16:35 +02:00
|
|
|
if(getType() == Type)
|
2024-02-11 23:09:01 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
//float<->int conversion
|
|
|
|
if(getType() == JsonType::DATA_FLOAT && Type == JsonType::DATA_INTEGER)
|
|
|
|
{
|
|
|
|
si64 converted = static_cast<si64>(std::get<double>(data));
|
|
|
|
data = JsonData(converted);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(getType() == JsonType::DATA_INTEGER && Type == JsonType::DATA_FLOAT)
|
|
|
|
{
|
|
|
|
double converted = static_cast<double>(std::get<si64>(data));
|
|
|
|
data = JsonData(converted);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Set new node type
|
|
|
|
switch(Type)
|
|
|
|
{
|
2024-02-13 19:16:35 +02:00
|
|
|
case JsonType::DATA_NULL:
|
|
|
|
data = JsonData();
|
|
|
|
break;
|
|
|
|
case JsonType::DATA_BOOL:
|
|
|
|
data = JsonData(false);
|
|
|
|
break;
|
|
|
|
case JsonType::DATA_FLOAT:
|
2024-02-13 22:19:24 +02:00
|
|
|
data = JsonData(0.0);
|
2024-02-13 19:16:35 +02:00
|
|
|
break;
|
|
|
|
case JsonType::DATA_STRING:
|
|
|
|
data = JsonData(std::string());
|
|
|
|
break;
|
|
|
|
case JsonType::DATA_VECTOR:
|
|
|
|
data = JsonData(JsonVector());
|
|
|
|
break;
|
|
|
|
case JsonType::DATA_STRUCT:
|
|
|
|
data = JsonData(JsonMap());
|
|
|
|
break;
|
|
|
|
case JsonType::DATA_INTEGER:
|
|
|
|
data = JsonData(static_cast<si64>(0));
|
|
|
|
break;
|
2024-02-11 23:09:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonNode::isNull() const
|
|
|
|
{
|
|
|
|
return getType() == JsonType::DATA_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonNode::isNumber() const
|
|
|
|
{
|
|
|
|
return getType() == JsonType::DATA_INTEGER || getType() == JsonType::DATA_FLOAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonNode::isString() const
|
|
|
|
{
|
|
|
|
return getType() == JsonType::DATA_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonNode::isVector() const
|
|
|
|
{
|
|
|
|
return getType() == JsonType::DATA_VECTOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonNode::isStruct() const
|
|
|
|
{
|
|
|
|
return getType() == JsonType::DATA_STRUCT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonNode::containsBaseData() const
|
|
|
|
{
|
|
|
|
switch(getType())
|
|
|
|
{
|
2024-02-13 19:16:35 +02:00
|
|
|
case JsonType::DATA_NULL:
|
|
|
|
return false;
|
|
|
|
case JsonType::DATA_STRUCT:
|
|
|
|
for(const auto & elem : Struct())
|
|
|
|
{
|
|
|
|
if(elem.second.containsBaseData())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
//other types (including vector) cannot be extended via merge
|
|
|
|
return true;
|
2024-02-11 23:09:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonNode::isCompact() const
|
|
|
|
{
|
|
|
|
switch(getType())
|
|
|
|
{
|
2024-02-13 19:16:35 +02:00
|
|
|
case JsonType::DATA_VECTOR:
|
|
|
|
for(const JsonNode & elem : Vector())
|
|
|
|
{
|
|
|
|
if(!elem.isCompact())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case JsonType::DATA_STRUCT:
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
|
|
|
auto propertyCount = Struct().size();
|
|
|
|
if(propertyCount == 0)
|
|
|
|
return true;
|
|
|
|
else if(propertyCount == 1)
|
|
|
|
return Struct().begin()->second.isCompact();
|
|
|
|
}
|
2024-02-13 19:16:35 +02:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
2024-02-11 23:09:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonNode::TryBoolFromString(bool & success) const
|
|
|
|
{
|
|
|
|
success = true;
|
|
|
|
if(getType() == JsonNode::JsonType::DATA_BOOL)
|
|
|
|
return Bool();
|
|
|
|
|
|
|
|
success = getType() == JsonNode::JsonType::DATA_STRING;
|
|
|
|
if(success)
|
|
|
|
{
|
|
|
|
auto boolParamStr = String();
|
|
|
|
boost::algorithm::trim(boolParamStr);
|
|
|
|
boost::algorithm::to_lower(boolParamStr);
|
|
|
|
success = boolParamStr == "true";
|
|
|
|
|
|
|
|
if(success)
|
|
|
|
return true;
|
2024-02-13 19:16:35 +02:00
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
success = boolParamStr == "false";
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JsonNode::clear()
|
|
|
|
{
|
|
|
|
setType(JsonType::DATA_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool & JsonNode::Bool()
|
|
|
|
{
|
|
|
|
setType(JsonType::DATA_BOOL);
|
|
|
|
return std::get<bool>(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
double & JsonNode::Float()
|
|
|
|
{
|
|
|
|
setType(JsonType::DATA_FLOAT);
|
|
|
|
return std::get<double>(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
si64 & JsonNode::Integer()
|
|
|
|
{
|
|
|
|
setType(JsonType::DATA_INTEGER);
|
|
|
|
return std::get<si64>(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string & JsonNode::String()
|
|
|
|
{
|
|
|
|
setType(JsonType::DATA_STRING);
|
|
|
|
return std::get<std::string>(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonVector & JsonNode::Vector()
|
|
|
|
{
|
|
|
|
setType(JsonType::DATA_VECTOR);
|
|
|
|
return std::get<JsonVector>(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonMap & JsonNode::Struct()
|
|
|
|
{
|
|
|
|
setType(JsonType::DATA_STRUCT);
|
|
|
|
return std::get<JsonMap>(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JsonNode::Bool() const
|
|
|
|
{
|
2024-02-13 22:19:24 +02:00
|
|
|
static const bool boolDefault = false;
|
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_BOOL);
|
|
|
|
|
2024-02-13 19:16:35 +02:00
|
|
|
if(getType() == JsonType::DATA_BOOL)
|
2024-02-11 23:09:01 +02:00
|
|
|
return std::get<bool>(data);
|
|
|
|
|
|
|
|
return boolDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
double JsonNode::Float() const
|
|
|
|
{
|
2024-02-13 22:19:24 +02:00
|
|
|
static const double floatDefault = 0;
|
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_INTEGER || getType() == JsonType::DATA_FLOAT);
|
|
|
|
|
|
|
|
if(getType() == JsonType::DATA_FLOAT)
|
|
|
|
return std::get<double>(data);
|
|
|
|
|
|
|
|
if(getType() == JsonType::DATA_INTEGER)
|
|
|
|
return static_cast<double>(std::get<si64>(data));
|
|
|
|
|
|
|
|
return floatDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
si64 JsonNode::Integer() const
|
|
|
|
{
|
2024-02-13 22:19:24 +02:00
|
|
|
static const si64 integerDefault = 0;
|
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_INTEGER || getType() == JsonType::DATA_FLOAT);
|
|
|
|
|
|
|
|
if(getType() == JsonType::DATA_INTEGER)
|
|
|
|
return std::get<si64>(data);
|
|
|
|
|
|
|
|
if(getType() == JsonType::DATA_FLOAT)
|
|
|
|
return static_cast<si64>(std::get<double>(data));
|
|
|
|
|
|
|
|
return integerDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & JsonNode::String() const
|
|
|
|
{
|
2024-02-15 22:29:56 +02:00
|
|
|
static const std::string stringDefault;
|
2024-02-13 22:19:24 +02:00
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_STRING);
|
|
|
|
|
2024-02-13 19:16:35 +02:00
|
|
|
if(getType() == JsonType::DATA_STRING)
|
2024-02-11 23:09:01 +02:00
|
|
|
return std::get<std::string>(data);
|
|
|
|
|
|
|
|
return stringDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
const JsonVector & JsonNode::Vector() const
|
|
|
|
{
|
2024-02-15 22:29:56 +02:00
|
|
|
static const JsonVector vectorDefault;
|
2024-02-13 22:19:24 +02:00
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_VECTOR);
|
|
|
|
|
2024-02-13 19:16:35 +02:00
|
|
|
if(getType() == JsonType::DATA_VECTOR)
|
2024-02-11 23:09:01 +02:00
|
|
|
return std::get<JsonVector>(data);
|
|
|
|
|
|
|
|
return vectorDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
const JsonMap & JsonNode::Struct() const
|
|
|
|
{
|
2024-02-15 22:29:56 +02:00
|
|
|
static const JsonMap mapDefault;
|
2024-02-13 22:19:24 +02:00
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
assert(getType() == JsonType::DATA_NULL || getType() == JsonType::DATA_STRUCT);
|
|
|
|
|
2024-02-13 19:16:35 +02:00
|
|
|
if(getType() == JsonType::DATA_STRUCT)
|
2024-02-11 23:09:01 +02:00
|
|
|
return std::get<JsonMap>(data);
|
|
|
|
|
|
|
|
return mapDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode & JsonNode::operator[](const std::string & child)
|
|
|
|
{
|
|
|
|
return Struct()[child];
|
|
|
|
}
|
|
|
|
|
|
|
|
const JsonNode & JsonNode::operator[](const std::string & child) const
|
|
|
|
{
|
|
|
|
auto it = Struct().find(child);
|
2024-02-13 19:16:35 +02:00
|
|
|
if(it != Struct().end())
|
2024-02-11 23:09:01 +02:00
|
|
|
return it->second;
|
|
|
|
return nullNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode & JsonNode::operator[](size_t child)
|
|
|
|
{
|
2024-02-13 19:16:35 +02:00
|
|
|
if(child >= Vector().size())
|
2024-02-11 23:09:01 +02:00
|
|
|
Vector().resize(child + 1);
|
|
|
|
return Vector()[child];
|
|
|
|
}
|
|
|
|
|
|
|
|
const JsonNode & JsonNode::operator[](size_t child) const
|
|
|
|
{
|
2024-02-13 19:16:35 +02:00
|
|
|
if(child < Vector().size())
|
2024-02-11 23:09:01 +02:00
|
|
|
return Vector()[child];
|
|
|
|
|
|
|
|
return nullNode;
|
|
|
|
}
|
|
|
|
|
2024-02-13 19:16:35 +02:00
|
|
|
const JsonNode & JsonNode::resolvePointer(const std::string & jsonPointer) const
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
|
|
|
return ::resolvePointer(*this, jsonPointer);
|
|
|
|
}
|
|
|
|
|
2024-02-13 19:16:35 +02:00
|
|
|
JsonNode & JsonNode::resolvePointer(const std::string & jsonPointer)
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
|
|
|
return ::resolvePointer(*this, jsonPointer);
|
|
|
|
}
|
|
|
|
|
2024-02-12 01:22:16 +02:00
|
|
|
std::vector<std::byte> JsonNode::toBytes() const
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
2024-02-12 01:22:16 +02:00
|
|
|
std::string jsonString = toString();
|
2024-02-13 19:16:35 +02:00
|
|
|
auto dataBegin = reinterpret_cast<const std::byte *>(jsonString.data());
|
2024-02-11 23:09:01 +02:00
|
|
|
auto dataEnd = dataBegin + jsonString.size();
|
|
|
|
std::vector<std::byte> result(dataBegin, dataEnd);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-02-12 01:22:16 +02:00
|
|
|
std::string JsonNode::toCompactString() const
|
2024-02-11 23:09:01 +02:00
|
|
|
{
|
|
|
|
std::ostringstream out;
|
2024-02-12 01:22:16 +02:00
|
|
|
JsonWriter writer(out, true);
|
|
|
|
writer.writeNode(*this);
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string JsonNode::toString() const
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
JsonWriter writer(out, false);
|
2024-02-11 23:09:01 +02:00
|
|
|
writer.writeNode(*this);
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|