29 return static_cast<const IntValue *
>(
this);
53 return static_cast<const EnumValue *
>(
this);
78 for (
const std::shared_ptr<Value> &item_value :
value.elements()) {
79 nlohmann::ordered_json json_item;
81 j.push_back(json_item);
91 nlohmann::ordered_json json_item;
93 j[attribute.first] = json_item;
99 switch (
value.type()) {
101 j =
value.as_string_value()->value();
106 j =
value.as_int_value()->value();
128 j =
value.as_boolean_value()->value();
133 j =
value.as_double_value()->value();
138 j =
value.as_enum_value()->value();
147 std::unique_ptr<ArrayValue>
array = std::make_unique<ArrayValue>();
148 for (
auto element : j.items()) {
155 const nlohmann::ordered_json &j)
157 std::unique_ptr<DictionaryValue>
object = std::make_unique<DictionaryValue>();
158 for (
auto element : j.items()) {
167 case nlohmann::json::value_t::array: {
171 case nlohmann::json::value_t::object: {
175 case nlohmann::json::value_t::string: {
176 std::string
value = j;
177 return std::make_unique<StringValue>(
value);
180 case nlohmann::json::value_t::null: {
181 return std::make_unique<NullValue>();
184 case nlohmann::json::value_t::boolean: {
185 return std::make_unique<BooleanValue>(j);
187 case nlohmann::json::value_t::number_integer:
188 case nlohmann::json::value_t::number_unsigned: {
189 return std::make_unique<IntValue>(j);
192 case nlohmann::json::value_t::number_float: {
193 return std::make_unique<DoubleValue>(j);
196 case nlohmann::json::value_t::binary:
197 case nlohmann::json::value_t::discarded:
205 return std::make_unique<NullValue>();
209 return std::make_unique<NullValue>();
214 values_.append(std::move(
value));
219 this->
append(std::make_shared<BooleanValue>(
value));
229 this->
append(std::make_shared<DoubleValue>(
value));
234 this->
append(std::make_shared<StringValue>(std::move(
value)));
239 this->
append(std::make_shared<NullValue>());
244 auto value = std::make_shared<DictionaryValue>();
251 auto value = std::make_shared<ArrayValue>();
259 for (
const Item &item : values_) {
267 for (
const auto &item : values_) {
268 if (item.first ==
key) {
277 if (
const std::shared_ptr<Value> *
value = this->
lookup(key)) {
287 if (
const std::shared_ptr<Value> *
value = this->
lookup(key)) {
289 return int_value->value();
297 if (
const std::shared_ptr<Value> *
value = this->
lookup(key)) {
299 return double_value->value();
307 if (
const std::shared_ptr<Value> *
value = this->
lookup(key)) {
315 if (
const std::shared_ptr<Value> *
value = this->
lookup(key)) {
333 this->
append(std::move(
key), std::make_shared<DoubleValue>(
value));
338 this->
append(std::move(
key), std::make_shared<StringValue>(std::move(
value)));
343 auto value = std::make_shared<DictionaryValue>();
350 auto value = std::make_shared<ArrayValue>();
357 nlohmann::ordered_json j;
369 nlohmann::ordered_json j;
382 fstream stream(path, std::ios::out);
389 fstream stream(path, std::ios::in);
#define BLI_assert_unreachable()
File and directory operations.
ATTR_WARN_UNUSED_RESULT const void * element
void append(const array< T > &from)
bool add_as(ForwardKey &&key, ForwardValue &&...value)
void append(const T &value)
void append_int(int value)
void append_double(double value)
void append(std::shared_ptr< Value > value)
std::shared_ptr< ArrayValue > append_array()
void append_str(std::string value)
void append_bool(bool value)
std::shared_ptr< DictionaryValue > append_dict()
const std::shared_ptr< Value > * lookup(StringRef key) const
void append(std::string key, std::shared_ptr< Value > value)
std::optional< StringRefNull > lookup_str(StringRef key) const
void append_str(std::string key, std::string value)
std::shared_ptr< DictionaryValue > append_dict(std::string key)
std::pair< std::string, std::shared_ptr< Value > > Item
std::optional< int64_t > lookup_int(StringRef key) const
void append_double(std::string key, double value)
void append_int(std::string key, int64_t value)
std::optional< double > lookup_double(StringRef key) const
std::shared_ptr< ArrayValue > append_array(std::string key)
const DictionaryValue * lookup_dict(StringRef key) const
const ArrayValue * lookup_array(StringRef key) const
Lookup create_lookup() const
const EnumValue * as_enum_value() const
const BooleanValue * as_boolean_value() const
const ArrayValue * as_array_value() const
const StringValue * as_string_value() const
const IntValue * as_int_value() const
const DoubleValue * as_double_value() const
const DictionaryValue * as_dictionary_value() const
static std::unique_ptr< DictionaryValue > convert_from_json_to_object(const nlohmann::ordered_json &j)
void write_json_file(StringRef path, const Value &value)
static std::unique_ptr< Value > convert_from_json(const nlohmann::ordered_json &j)
static void convert_to_json(nlohmann::ordered_json &j, const Value &value)
static std::unique_ptr< ArrayValue > convert_from_json_to_array(const nlohmann::ordered_json &j)
std::shared_ptr< Value > read_json_file(StringRef path)