18class IDPropertySerializer;
19struct DictionaryEntryParser;
93 std::shared_ptr<DictionaryValue> result = std::make_shared<DictionaryValue>();
161 return get_array_primitive<int32_t, IntValue>(
IDP_KEY_VALUE);
166 return get_array_primitive<float, DoubleValue>(
IDP_KEY_VALUE);
171 return get_array_primitive<double, DoubleValue>(
IDP_KEY_VALUE);
175 std::optional<std::string> get_string(
StringRef key)
const
178 if (value ==
nullptr) {
181 if (value->get()->type() != eValueType::String) {
184 return value->get()->as_string_value()->value();
190 if (value ==
nullptr) {
193 if (value->get()->type() != eValueType::Array) {
196 return value->get()->as_array_value();
199 std::optional<bool> get_bool(
StringRef key)
const
202 if (value ==
nullptr) {
205 if (value->get()->type() != eValueType::Boolean) {
208 return value->get()->as_boolean_value()->value();
211 std::optional<int32_t> get_int(
StringRef key)
const
214 if (value ==
nullptr) {
217 if (value->get()->type() != eValueType::Int) {
220 return value->get()->as_int_value()->value();
223 std::optional<int32_t> get_enum(
StringRef key)
const
226 if (value ==
nullptr) {
229 if (value->get()->type() != eValueType::Int) {
232 return value->get()->as_int_value()->value();
235 std::optional<double> get_double(
StringRef key)
const
238 if (value ==
nullptr) {
241 if (value->get()->type() != eValueType::Double) {
244 return value->get()->as_double_value()->value();
247 std::optional<float> get_float(
StringRef key)
const
249 return static_cast<std::optional<float>
>(get_double(key));
252 template<
typename PrimitiveType,
typename ValueType>
253 std::optional<Vector<PrimitiveType>> get_array_primitive(
StringRef key)
const
256 if (value ==
nullptr) {
259 if (value->get()->type() != eValueType::Array) {
263 Vector<PrimitiveType>
result;
264 for (
const std::shared_ptr<Value> &element : value->
get()->as_array_value()->elements()) {
265 const ValueType *value_type =
static_cast<const ValueType *
>(element.get());
267 result.append_as(primitive_value);
273 std::optional<eIDPropertyType> get_id_property_type(
StringRef key)
const
275 std::optional<std::string> string_value = get_string(key);
276 if (!string_value.has_value()) {
279 const IDPropertySerializer &serializer =
serializer_for(*string_value);
280 return serializer.property_type();
311 std::optional<std::string> name = entry_reader.
get_name();
312 if (!name.has_value()) {
316 if (!string_value.has_value()) {
319 return create(name->c_str(), string_value->c_str());
350 std::optional<std::string> name = entry_reader.
get_name();
351 if (!name.has_value()) {
354 std::optional<bool> extracted_value = entry_reader.
get_bool_value();
355 if (!extracted_value.has_value()) {
358 return create_bool(name->c_str(), *extracted_value);
389 std::optional<std::string> name = entry_reader.
get_name();
390 if (!name.has_value()) {
393 std::optional<int32_t> extracted_value = entry_reader.
get_int_value();
394 if (!extracted_value.has_value()) {
397 return create(name->c_str(), *extracted_value);
428 std::optional<std::string> name = entry_reader.
get_name();
429 if (!name.has_value()) {
433 if (!extracted_value.has_value()) {
436 return create(name->c_str(), *extracted_value);
467 std::optional<std::string> name = entry_reader.
get_name();
468 if (!name.has_value()) {
472 if (!extracted_value.has_value()) {
475 return create(name->c_str(), *extracted_value);
510 float *values =
static_cast<float *
>(
IDP_Array(id_property));
515 double *values =
static_cast<double *
>(
IDP_Array(id_property));
538 std::optional<eIDPropertyType> property_subtype = entry_reader.
get_subtype();
539 if (!property_subtype.has_value()) {
543 switch (*property_subtype) {
545 return idprop_array_int_from_value(entry_reader);
547 return idprop_array_float_from_value(entry_reader);
549 return idprop_array_double_from_value(entry_reader);
571 for (
const IDProperty &id_property : values) {
574 if (!value_serializer.supports_serializing()) {
577 array.
append(value_serializer.idprop_to_dictionary(&id_property));
581 std::unique_ptr<IDProperty, IDPropertyDeleter> idprop_array_int_from_value(
582 DictionaryEntryParser &entry_reader)
const
586 std::optional<std::string> name = entry_reader.get_name();
587 if (!name.has_value()) {
590 std::optional<Vector<int32_t>> extracted_value = entry_reader.get_array_int_value();
591 if (!extracted_value.has_value()) {
594 return create(name->c_str(), *extracted_value);
597 std::unique_ptr<IDProperty, IDPropertyDeleter> idprop_array_float_from_value(
598 DictionaryEntryParser &entry_reader)
const
602 std::optional<std::string> name = entry_reader.get_name();
603 if (!name.has_value()) {
606 std::optional<Vector<float>> extracted_value = entry_reader.get_array_float_value();
607 if (!extracted_value.has_value()) {
610 return create(name->c_str(), *extracted_value);
613 std::unique_ptr<IDProperty, IDPropertyDeleter> idprop_array_double_from_value(
614 DictionaryEntryParser &entry_reader)
const
618 std::optional<std::string> name = entry_reader.get_name();
619 if (!name.has_value()) {
622 std::optional<Vector<double>> extracted_value = entry_reader.get_array_double_value();
623 if (!extracted_value.has_value()) {
626 return create(name->c_str(), *extracted_value);
650 std::shared_ptr<ArrayValue>
array = std::make_shared<ArrayValue>();
665 std::optional<std::string> name = entry_reader.
get_name();
666 if (!name.has_value()) {
671 if (
array ==
nullptr) {
675 std::unique_ptr<IDProperty, IDPropertyDeleter> result =
create_group(name->c_str());
676 for (
const std::shared_ptr<Value> &element :
array->elements()) {
677 if (element->type() != eValueType::Dictionary) {
736 switch (property_type) {
759 BLI_assert_msg(
false,
"Trying to convert an unsupported/unknown property type to a string");
799 std::unique_ptr<ArrayValue> result = std::make_unique<ArrayValue>();
800 const IDProperty *current_property = properties;
801 while (current_property !=
nullptr) {
807 current_property = current_property->
next;
822 std::optional<eIDPropertyType> property_type = entry_reader.
get_type();
823 if (!property_type.has_value()) {
836 for (
const std::shared_ptr<Value> &element : value.elements()) {
837 if (element->type() != eValueType::Dictionary) {
842 if (last_created ==
nullptr) {
846 if (result ==
nullptr) {
847 result = last_created;
850 if (previous_added) {
851 previous_added->
next = last_created;
853 last_created->
prev = previous_added;
854 previous_added = last_created;
862 if (value.type() != eValueType::Array) {
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
#define LISTBASE_FOREACH(type, var, list)
ID and Library types, which are fundamental for SDNA.
void append(const array< T > &from)
const Value * lookup_ptr(const Key &key) const
IDPSerializer for IDP_ARRAY.
std::string type_name() const override
return the type name for (de)serializing. Type name is stored in the type or subtype attribute of the...
constexpr IDPArraySerializer()=default
std::optional< eIDPropertyType > property_type() const override
return the IDPropertyType for (de)serializing.
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const IDProperty *id_property) const override
create dictionary containing the given id_property.
std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &entry_reader) const override
convert the entry to an id property.
IDPSerializer for IDP_INT.
std::optional< eIDPropertyType > property_type() const override
return the IDPropertyType for (de)serializing.
std::string type_name() const override
return the type name for (de)serializing. Type name is stored in the type or subtype attribute of the...
constexpr IDPBoolSerializer()=default
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const IDProperty *id_property) const override
create dictionary containing the given id_property.
std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &entry_reader) const override
convert the entry to an id property.
IDPSerializer for IDP_DOUBLE.
std::optional< eIDPropertyType > property_type() const override
return the IDPropertyType for (de)serializing.
constexpr IDPDoubleSerializer()=default
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const IDProperty *id_property) const override
create dictionary containing the given id_property.
std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &entry_reader) const override
convert the entry to an id property.
std::string type_name() const override
return the type name for (de)serializing. Type name is stored in the type or subtype attribute of the...
IDPSerializer for IDP_FLOAT.
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const IDProperty *id_property) const override
create dictionary containing the given id_property.
constexpr IDPFloatSerializer()=default
std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &entry_reader) const override
convert the entry to an id property.
std::optional< eIDPropertyType > property_type() const override
return the IDPropertyType for (de)serializing.
std::string type_name() const override
return the type name for (de)serializing. Type name is stored in the type or subtype attribute of the...
IDPSerializer for IDP_GROUP.
constexpr IDPGroupSerializer()=default
std::string type_name() const override
return the type name for (de)serializing. Type name is stored in the type or subtype attribute of the...
std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &entry_reader) const override
convert the entry to an id property.
std::optional< eIDPropertyType > property_type() const override
return the IDPropertyType for (de)serializing.
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const IDProperty *id_property) const override
create dictionary containing the given id_property.
IDPSerializer for IDP_INT.
std::string type_name() const override
return the type name for (de)serializing. Type name is stored in the type or subtype attribute of the...
constexpr IDPIntSerializer()=default
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const IDProperty *id_property) const override
create dictionary containing the given id_property.
std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &entry_reader) const override
convert the entry to an id property.
std::optional< eIDPropertyType > property_type() const override
return the IDPropertyType for (de)serializing.
IDPSerializer for IDP_STRING.
std::string type_name() const override
return the type name for (de)serializing. Type name is stored in the type or subtype attribute of the...
constexpr IDPStringSerializer()=default
std::optional< eIDPropertyType > property_type() const override
return the IDPropertyType for (de)serializing.
std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &entry_reader) const override
convert the entry to an id property.
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const IDProperty *id_property) const override
create dictionary containing the given id_property.
Dummy serializer for unknown and unsupported types.
std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &) const override
convert the entry to an id property.
std::string type_name() const override
return the type name for (de)serializing. Type name is stored in the type or subtype attribute of the...
std::optional< eIDPropertyType > property_type() const override
return the IDPropertyType for (de)serializing.
bool supports_serializing() const override
Can the serializer be used?
constexpr IDPUnknownSerializer()=default
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const IDProperty *) const override
create dictionary containing the given id_property.
Base class for (de)serializing IDProperties.
virtual std::shared_ptr< DictionaryValue > idprop_to_dictionary(const IDProperty *id_property) const =0
create dictionary containing the given id_property.
std::shared_ptr< DictionaryValue > create_dictionary(const IDProperty *id_property) const
Create a new DictionaryValue instance.
virtual std::string type_name() const =0
return the type name for (de)serializing. Type name is stored in the type or subtype attribute of the...
virtual std::optional< eIDPropertyType > property_type() const =0
return the IDPropertyType for (de)serializing.
virtual std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &entry_reader) const =0
convert the entry to an id property.
constexpr IDPropertySerializer()=default
virtual bool supports_serializing() const
Can the serializer be used?
const DictionaryValue * as_dictionary_value() const
static constexpr StringRef IDP_KEY_SUBTYPE("subtype")
static constexpr StringRef IDP_PROPERTY_TYPENAME_FLOAT("IDP_FLOAT")
static constexpr IDPUnknownSerializer IDP_SERIALIZER_UNKNOWN
static constexpr StringRef IDP_PROPERTY_TYPENAME_STRING("IDP_STRING")
static constexpr IDPStringSerializer IDP_SERIALIZER_STRING
static constexpr StringRef IDP_PROPERTY_TYPENAME_BOOL("IDP_BOOL")
static constexpr StringRef IDP_KEY_VALUE("value")
static const IDPropertySerializer & serializer_for(eIDPropertyType property_type)
get the serializer for the given property type.
static constexpr IDPArraySerializer IDP_SERIALIZER_ARRAY
static constexpr StringRef IDP_PROPERTY_TYPENAME_DOUBLE("IDP_DOUBLE")
static constexpr IDPGroupSerializer IDP_SERIALIZER_GROUP
static constexpr StringRef IDP_PROPERTY_TYPENAME_UNKNOWN("IDP_UNKNOWN")
static constexpr StringRef IDP_PROPERTY_TYPENAME_GROUP("IDP_GROUP")
static IDProperty * idprop_from_value(const DictionaryValue &value)
static constexpr StringRef IDP_KEY_TYPE("type")
static constexpr StringRef IDP_PROPERTY_TYPENAME_INT("IDP_INT")
static constexpr IDPDoubleSerializer IDP_SERIALIZER_DOUBLE
static constexpr IDPFloatSerializer IDP_SERIALIZER_FLOAT
static constexpr StringRef IDP_PROPERTY_TYPENAME_ARRAY("IDP_ARRAY")
std::unique_ptr< IDProperty, IDPropertyDeleter > create_bool(StringRefNull prop_name, bool value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_BOOLEAN, set its name and value.
std::unique_ptr< blender::io::serialize::ArrayValue > convert_to_serialize_values(const IDProperty *properties)
Convert the given properties to Value objects for serialization.
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
static constexpr StringRef IDP_KEY_NAME("name")
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRefNull prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
static constexpr IDPBoolSerializer IDP_SERIALIZER_BOOL
static constexpr IDPIntSerializer IDP_SERIALIZER_INT
IDProperty * convert_from_serialize_value(const blender::io::serialize::Value &value)
Convert the given value to an IDProperty.
std::shared_ptr< const T > get(const GenericKey &key, FunctionRef< std::unique_ptr< T >()> compute_fn)
Helper class for parsing DictionaryValues.
DictionaryEntryParser(const DictionaryValue &value)
std::optional< int > get_enum_value() const
std::optional< std::string > get_string_value() const
const ArrayValue * get_array_value() const
std::optional< std::string > get_name() const
std::optional< float > get_float_value() const
std::optional< Vector< double > > get_array_double_value() const
std::optional< eIDPropertyType > get_type() const
DictionaryValue::Lookup lookup
std::optional< int32_t > get_int_value() const
std::optional< Vector< float > > get_array_float_value() const
std::optional< double > get_double_value() const
std::optional< Vector< int32_t > > get_array_int_value() const
std::optional< eIDPropertyType > get_subtype() const
std::optional< bool > get_bool_value() const