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()) {
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));
224 this->
append(std::make_shared<IntValue>(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_) {
260 result.add_as(item.first, item.second);
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)) {
288 if (
const IntValue *int_value = (*value)->as_int_value()) {
289 return int_value->value();
297 if (
const std::shared_ptr<Value> *value = this->
lookup(key)) {
298 if (
const DoubleValue *double_value = (*value)->as_double_value()) {
299 return double_value->value();
307 if (
const std::shared_ptr<Value> *value = this->
lookup(key)) {
308 return (*value)->as_dictionary_value();
315 if (
const std::shared_ptr<Value> *value = this->
lookup(key)) {
316 return (*value)->as_array_value();
323 values_.
append({std::move(key), std::move(value)});
328 this->
append(std::move(key), std::make_shared<IntValue>(value));
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>();
344 this->
append(std::move(key), value);
350 auto value = std::make_shared<ArrayValue>();
351 this->
append(std::move(key), value);
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)
void append_int(int value)
void append_double(double value)
void append(std::shared_ptr< Value > value)
Span< std::shared_ptr< Value > > elements() const
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
Span< Item > elements() const
void append_double(std::string key, double value)
void append_int(std::string key, int64_t value)
Map< std::string, std::shared_ptr< Value > > Lookup
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 std::string & value() 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)
PrimitiveValue< int64_t, eValueType::Int > IntValue
PrimitiveValue< bool, eValueType::Boolean > BooleanValue
PrimitiveValue< int, eValueType::Enum > EnumValue
static std::unique_ptr< Value > convert_from_json(const nlohmann::ordered_json &j)
PrimitiveValue< double, eValueType::Double > DoubleValue
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)