25 return static_cast<const IntValue *
>(
this);
49 return static_cast<const EnumValue *
>(
this);
74 for (
const std::shared_ptr<Value> &item_value : value.elements()) {
75 nlohmann::ordered_json json_item;
77 j.push_back(json_item);
87 nlohmann::ordered_json json_item;
89 j[attribute.first] = json_item;
95 switch (value.type()) {
97 j = value.as_string_value()->value();
102 j = value.as_int_value()->value();
124 j = value.as_boolean_value()->value();
129 j = value.as_double_value()->value();
134 j = value.as_enum_value()->value();
143 std::unique_ptr<ArrayValue>
array = std::make_unique<ArrayValue>();
144 for (
auto element : j.items()) {
151 const nlohmann::ordered_json &j)
153 std::unique_ptr<DictionaryValue>
object = std::make_unique<DictionaryValue>();
154 for (
auto element : j.items()) {
163 case nlohmann::json::value_t::array: {
167 case nlohmann::json::value_t::object: {
171 case nlohmann::json::value_t::string: {
172 std::string value = j;
173 return std::make_unique<StringValue>(value);
176 case nlohmann::json::value_t::null: {
177 return std::make_unique<NullValue>();
180 case nlohmann::json::value_t::boolean: {
181 return std::make_unique<BooleanValue>(j);
183 case nlohmann::json::value_t::number_integer:
184 case nlohmann::json::value_t::number_unsigned: {
185 return std::make_unique<IntValue>(j);
188 case nlohmann::json::value_t::number_float: {
189 return std::make_unique<DoubleValue>(j);
192 case nlohmann::json::value_t::binary:
193 case nlohmann::json::value_t::discarded:
201 return std::make_unique<NullValue>();
205 return std::make_unique<NullValue>();
210 values_.append(std::move(value));
215 this->
append(std::make_shared<BooleanValue>(value));
220 this->
append(std::make_shared<IntValue>(value));
225 this->
append(std::make_shared<DoubleValue>(value));
230 this->
append(std::make_shared<StringValue>(std::move(value)));
235 this->
append(std::make_shared<NullValue>());
240 auto value = std::make_shared<DictionaryValue>();
247 auto value = std::make_shared<ArrayValue>();
255 for (
const Item &item : values_) {
256 result.
add_as(item.first, item.second);
263 for (
const auto &item : values_) {
264 if (item.first == key) {
273 if (
const std::shared_ptr<Value> *value = this->
lookup(key)) {
283 if (
const std::shared_ptr<Value> *value = this->
lookup(key)) {
285 return int_value->value();
293 if (
const std::shared_ptr<Value> *value = this->
lookup(key)) {
295 return double_value->value();
303 if (
const std::shared_ptr<Value> *value = this->
lookup(key)) {
311 if (
const std::shared_ptr<Value> *value = this->
lookup(key)) {
319 values_.
append({std::move(key), std::move(value)});
324 this->
append(std::move(key), std::make_shared<IntValue>(value));
329 this->
append(std::move(key), std::make_shared<DoubleValue>(value));
334 this->
append(std::move(key), std::make_shared<StringValue>(std::move(value)));
339 auto value = std::make_shared<DictionaryValue>();
340 this->
append(std::move(key), value);
346 auto value = std::make_shared<ArrayValue>();
347 this->
append(std::move(key), value);
353 nlohmann::ordered_json j;
365 nlohmann::ordered_json j;
378 fstream stream(path, std::ios::out);
385 fstream stream(path, std::ios::in);
#define BLI_assert_unreachable()
File and directory operations.
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()
void append(std::string key, std::shared_ptr< Value > value)
const std::shared_ptr< Value > * lookup(const 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
const DictionaryValue * lookup_dict(const StringRef key) const
void append_double(std::string key, double value)
void append_int(std::string key, int64_t value)
const ArrayValue * lookup_array(const StringRef key) const
std::optional< int64_t > lookup_int(const StringRef key) const
std::shared_ptr< ArrayValue > append_array(std::string key)
std::optional< StringRefNull > lookup_str(const StringRef key) const
std::optional< double > lookup_double(const 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)