diff options
author | Jeroen Bakker <jeroen@blender.org> | 2022-01-03 10:10:21 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2022-01-03 10:10:21 +0300 |
commit | ea8d749587ddf1108429f19eea89b9f0c2af3ee4 (patch) | |
tree | 37e700a67ebbc0da6ad9025fc8f1b89a65e25ec3 /source/blender/blenlib | |
parent | 180b66ae8a1ffc0a1bb7d3993028240b4c7f7246 (diff) |
Cleanup: Rename ObjectValue to DictionaryValue (Serialization).
ObjectValue was to confusing as it is the term from JSON.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_serialize.hh | 18 | ||||
-rw-r--r-- | source/blender/blenlib/intern/serialize.cc | 18 | ||||
-rw-r--r-- | source/blender/blenlib/tests/BLI_serialize_test.cc | 4 |
3 files changed, 20 insertions, 20 deletions
diff --git a/source/blender/blenlib/BLI_serialize.hh b/source/blender/blenlib/BLI_serialize.hh index 051731ab801..b1002b07fd3 100644 --- a/source/blender/blenlib/BLI_serialize.hh +++ b/source/blender/blenlib/BLI_serialize.hh @@ -36,7 +36,7 @@ * - DoubleValue: for double precision floating point numbers * - BooleanValue: for boolean values * - ArrayValue: An array of any supported value. - * - ObjectValue: A key value pair where keys are std::string. + * - DictionaryValue: A key value pair where keys are std::string. * - NullValue: for null values. * * # Basic usage @@ -97,7 +97,7 @@ enum class eValueType { class Value; class StringValue; -class ObjectValue; +class DictionaryValue; template<typename T, eValueType V> class PrimitiveValue; using IntValue = PrimitiveValue<int64_t, eValueType::Int>; using DoubleValue = PrimitiveValue<double, eValueType::Double>; @@ -122,7 +122,7 @@ using ArrayValue = ContainerValue<Vector<std::shared_ptr<Value>>, eValueType::Ar * - `NullValue`: represents nothing (null pointer or optional). * - `BooleanValue`: contains a boolean (true/false). * - `DoubleValue`: contains a double precision floating point number. - * - `ObjectValue`: represents an object (key value pairs where keys are strings and values can be + * - `DictionaryValue`: represents an object (key value pairs where keys are strings and values can be * of different types. * */ @@ -174,10 +174,10 @@ class Value { const ArrayValue *as_array_value() const; /** - * Casts to an ObjectValue. + * Casts to an DictionaryValue. * Will return nullptr when it is a different type. */ - const ObjectValue *as_object_value() const; + const DictionaryValue *as_object_value() const; }; /** @@ -228,7 +228,7 @@ class StringValue : public Value { /** * Template for arrays and objects. * - * Both ArrayValue and ObjectValue store their values in an array. + * Both ArrayValue and DictionaryValue store their values in an array. */ template< /** The container type where the elements are stored in. */ @@ -264,10 +264,10 @@ class ContainerValue : public Value { }; /** - * Internal storage type for ObjectValue. + * Internal storage type for DictionaryValue. * * The elements are stored as an key value pair. The value is a shared pointer so it can be shared - * when using `ObjectValue::create_lookup`. + * when using `DictionaryValue::create_lookup`. */ using ObjectElementType = std::pair<std::string, std::shared_ptr<Value>>; @@ -275,7 +275,7 @@ using ObjectElementType = std::pair<std::string, std::shared_ptr<Value>>; * Object is a key-value container where the key must be a std::string. * Internally it is stored in a blender::Vector to ensure the order of keys. */ -class ObjectValue : public ContainerValue<Vector<ObjectElementType>, eValueType::Object> { +class DictionaryValue : public ContainerValue<Vector<ObjectElementType>, eValueType::Object> { public: using LookupValue = std::shared_ptr<Value>; using Lookup = Map<std::string, LookupValue>; diff --git a/source/blender/blenlib/intern/serialize.cc b/source/blender/blenlib/intern/serialize.cc index 52aff140e3e..a17d7a189f6 100644 --- a/source/blender/blenlib/intern/serialize.cc +++ b/source/blender/blenlib/intern/serialize.cc @@ -44,12 +44,12 @@ const ArrayValue *Value::as_array_value() const return static_cast<const ArrayValue *>(this); } -const ObjectValue *Value::as_object_value() const +const DictionaryValue *Value::as_object_value() const { if (type_ != eValueType::Object) { return nullptr; } - return static_cast<const ObjectValue *>(this); + return static_cast<const DictionaryValue *>(this); } static void convert_to_json(nlohmann::ordered_json &j, const Value &value); @@ -66,13 +66,13 @@ static void convert_to_json(nlohmann::ordered_json &j, const ArrayValue &value) } } -static void convert_to_json(nlohmann::ordered_json &j, const ObjectValue &value) +static void convert_to_json(nlohmann::ordered_json &j, const DictionaryValue &value) { - const ObjectValue::Items &attributes = value.elements(); + const DictionaryValue::Items &attributes = value.elements(); /* Create a json object to store the attributes. If this isn't done and attributes is empty it * would return use a null value, in stead of an empty object. */ j = "{}"_json; - for (const ObjectValue::Item &attribute : attributes) { + for (const DictionaryValue::Item &attribute : attributes) { nlohmann::ordered_json json_item; convert_to_json(json_item, *attribute.second); j[attribute.first] = json_item; @@ -99,7 +99,7 @@ static void convert_to_json(nlohmann::ordered_json &j, const Value &value) } case eValueType::Object: { - const ObjectValue &object = *value.as_object_value(); + const DictionaryValue &object = *value.as_object_value(); convert_to_json(j, object); break; } @@ -133,10 +133,10 @@ static std::unique_ptr<ArrayValue> convert_from_json_to_array(const nlohmann::or return array; } -static std::unique_ptr<ObjectValue> convert_from_json_to_object(const nlohmann::ordered_json &j) +static std::unique_ptr<DictionaryValue> convert_from_json_to_object(const nlohmann::ordered_json &j) { - std::unique_ptr<ObjectValue> object = std::make_unique<ObjectValue>(); - ObjectValue::Items &elements = object->elements(); + std::unique_ptr<DictionaryValue> object = std::make_unique<DictionaryValue>(); + DictionaryValue::Items &elements = object->elements(); for (auto element : j.items()) { std::string key = element.key(); nlohmann::ordered_json element_json = element.value(); diff --git a/source/blender/blenlib/tests/BLI_serialize_test.cc b/source/blender/blenlib/tests/BLI_serialize_test.cc index 6c55a85ca1e..120fcdc3e81 100644 --- a/source/blender/blenlib/tests/BLI_serialize_test.cc +++ b/source/blender/blenlib/tests/BLI_serialize_test.cc @@ -93,8 +93,8 @@ TEST(serialize, object_to_json) { JsonFormatter json; std::stringstream out; - ObjectValue value_object; - ObjectValue::Items &attributes = value_object.elements(); + DictionaryValue value_object; + DictionaryValue::Items &attributes = value_object.elements(); attributes.append_as(std::pair(std::string("best_number"), new IntValue(42))); json.serialize(out, value_object); |