16 class IDPropertySerializer;
17 struct DictionaryEntryParser;
20 static const IDPropertySerializer &
serializer_for(StringRef idprop_typename);
64 const struct IDProperty *id_property)
const = 0;
90 std::shared_ptr<DictionaryValue>
result = std::make_shared<DictionaryValue>();
151 return get_array_primitive<int32_t, IntValue>(
IDP_KEY_VALUE);
156 return get_array_primitive<float, DoubleValue>(
IDP_KEY_VALUE);
161 return get_array_primitive<double, DoubleValue>(
IDP_KEY_VALUE);
168 if (value_ptr ==
nullptr) {
173 if (value->type() != eValueType::String) {
177 return value->as_string_value()->value();
180 const ArrayValue *get_array(StringRef key)
const
183 if (value_ptr ==
nullptr) {
192 return value->as_array_value();
195 std::optional<int32_t>
get_int(StringRef key)
const
198 if (value_ptr ==
nullptr) {
203 if (value->type() != eValueType::Int) {
207 return value->as_int_value()->value();
210 std::optional<double> get_double(StringRef key)
const
213 if (value_ptr ==
nullptr) {
218 if (value->type() != eValueType::Double) {
222 return value->as_double_value()->value();
225 std::optional<float>
get_float(StringRef key)
const
227 return static_cast<std::optional<float>
>(get_double(key));
230 template<
typename PrimitiveType,
typename ValueType>
231 std::optional<Vector<PrimitiveType>> get_array_primitive(StringRef key)
const
234 if (value_ptr ==
nullptr) {
243 Vector<PrimitiveType>
result;
246 const ValueType *value_type =
static_cast<const ValueType *
>(
element.get());
248 result.append_as(primitive_value);
254 std::optional<eIDPropertyType> get_id_property_type(StringRef key)
const
256 std::optional<std::string> string_value =
get_string(key);
257 if (!string_value.has_value()) {
260 const IDPropertySerializer &serializer =
serializer_for(*string_value);
261 return serializer.property_type();
281 const struct IDProperty *id_property)
const override
283 std::shared_ptr<DictionaryValue>
result = create_dictionary(id_property);
293 std::optional<std::string> name = entry_reader.
get_name();
294 if (!name.has_value()) {
298 if (!string_value.has_value()) {
301 return create(name->c_str(), string_value->c_str());
321 const struct IDProperty *id_property)
const override
323 std::shared_ptr<DictionaryValue>
result = create_dictionary(id_property);
333 std::optional<std::string> name = entry_reader.
get_name();
334 if (!name.has_value()) {
337 std::optional<int32_t> extracted_value = entry_reader.
get_int_value();
338 if (!extracted_value.has_value()) {
341 return create(name->c_str(), *extracted_value);
361 const struct IDProperty *id_property)
const override
363 std::shared_ptr<DictionaryValue>
result = create_dictionary(id_property);
373 std::optional<std::string> name = entry_reader.
get_name();
374 if (!name.has_value()) {
378 if (!extracted_value.has_value()) {
381 return create(name->c_str(), *extracted_value);
401 const struct IDProperty *id_property)
const override
403 std::shared_ptr<DictionaryValue>
result = create_dictionary(id_property);
413 std::optional<std::string> name = entry_reader.
get_name();
414 if (!name.has_value()) {
418 if (!extracted_value.has_value()) {
421 return create(name->c_str(), *extracted_value);
441 const struct IDProperty *id_property)
const override
443 std::shared_ptr<DictionaryValue>
result = create_dictionary(id_property);
447 attributes.append_as(
450 std::shared_ptr<ArrayValue> array = std::make_shared<ArrayValue>();
454 add_values<int32_t, IntValue>(array.get(),
Span<int32_t>(values, id_property->
len));
459 float *values =
static_cast<float *
>(
IDP_Array(id_property));
460 add_values<float, DoubleValue>(array.get(),
Span<float>(values, id_property->
len));
465 double *values =
static_cast<double *
>(
IDP_Array(id_property));
466 add_values<double, DoubleValue>(array.get(),
Span<double>(values, id_property->
len));
482 attributes.append_as(std::pair(
IDP_KEY_VALUE, std::move(array)));
491 std::optional<eIDPropertyType> property_subtype = entry_reader.
get_subtype();
492 if (!property_subtype.has_value()) {
496 switch (*property_subtype) {
498 return idprop_array_int_from_value(entry_reader);
501 return idprop_array_float_from_value(entry_reader);
504 return idprop_array_double_from_value(entry_reader);
523 items.append_as(std::make_shared<ValueType>(value));
530 for (
const IDProperty &id_property : values) {
533 if (!value_serializer.supports_serializing()) {
536 std::shared_ptr<DictionaryValue> value = value_serializer.idprop_to_dictionary(&id_property);
537 items.append_as(value);
541 std::unique_ptr<IDProperty, IDPropertyDeleter> idprop_array_int_from_value(
542 DictionaryEntryParser &entry_reader)
const
546 std::optional<std::string> name = entry_reader.get_name();
547 if (!name.has_value()) {
550 std::optional<Vector<int32_t>> extracted_value = entry_reader.get_array_int_value();
551 if (!extracted_value.has_value()) {
554 return create(name->c_str(), *extracted_value);
557 std::unique_ptr<IDProperty, IDPropertyDeleter> idprop_array_float_from_value(
558 DictionaryEntryParser &entry_reader)
const
562 std::optional<std::string> name = entry_reader.get_name();
563 if (!name.has_value()) {
566 std::optional<Vector<float>> extracted_value = entry_reader.get_array_float_value();
567 if (!extracted_value.has_value()) {
570 return create(name->c_str(), *extracted_value);
573 std::unique_ptr<IDProperty, IDPropertyDeleter> idprop_array_double_from_value(
574 DictionaryEntryParser &entry_reader)
const
578 std::optional<std::string> name = entry_reader.get_name();
579 if (!name.has_value()) {
582 std::optional<Vector<double>> extracted_value = entry_reader.get_array_double_value();
583 if (!extracted_value.has_value()) {
586 return create(name->c_str(), *extracted_value);
606 const struct IDProperty *id_property)
const override
608 std::shared_ptr<DictionaryValue>
result = create_dictionary(id_property);
610 std::shared_ptr<ArrayValue> array = std::make_shared<ArrayValue>();
628 std::optional<std::string> name = entry_reader.
get_name();
629 if (!name.has_value()) {
634 if (array ==
nullptr) {
640 if (
element->type() != eValueType::Dictionary) {
698 switch (property_type) {
718 BLI_assert_msg(
false,
"Trying to convert an unsupported/unknown property type to a string");
755 std::unique_ptr<ArrayValue>
result = std::make_unique<ArrayValue>();
757 const struct IDProperty *current_property = properties;
758 while (current_property !=
nullptr) {
764 current_property = current_property->
next;
779 std::optional<eIDPropertyType> property_type = entry_reader.
get_type();
780 if (!property_type.has_value()) {
795 if (
element->type() != eValueType::Dictionary) {
800 if (last_created ==
nullptr) {
808 if (previous_added) {
809 previous_added->
next = last_created;
811 last_created->
prev = previous_added;
812 previous_added = last_created;
bool IDP_AddToGroup(struct IDProperty *group, struct 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.
ATTR_WARN_UNUSED_RESULT const void * element
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...
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const struct IDProperty *id_property) const override
create dictionary containing the given id_property.
constexpr IDPArraySerializer()=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.
IDPSerializer for IDP_DOUBLE.
constexpr IDPDoubleSerializer()=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 struct IDProperty *id_property) const override
create dictionary containing the given 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 struct IDProperty *id_property) const override
create dictionary containing the given id_property.
std::optional< eIDPropertyType > property_type() const override
return the IDPropertyType for (de)serializing.
constexpr IDPFloatSerializer()=default
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_GROUP.
std::optional< eIDPropertyType > property_type() const override
return the IDPropertyType for (de)serializing.
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::shared_ptr< DictionaryValue > idprop_to_dictionary(const struct 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::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::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 struct IDProperty *id_property) const override
create dictionary containing the given id_property.
IDPSerializer for IDP_STRING.
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...
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const struct 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.
constexpr IDPStringSerializer()=default
Dummy serializer for unknown and unsupported types.
std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &UNUSED(entry_reader)) const override
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...
bool supports_serializing() const override
Can the serializer be used?
constexpr IDPUnknownSerializer()=default
std::shared_ptr< DictionaryValue > idprop_to_dictionary(const struct IDProperty *UNUSED(id_property)) const override
Base class for (de)serializing IDProperties.
virtual std::unique_ptr< IDProperty, IDPropertyDeleter > entry_to_idprop(DictionaryEntryParser &entry_reader) const =0
convert the entry to an id property.
std::shared_ptr< DictionaryValue > create_dictionary(const struct 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::shared_ptr< DictionaryValue > idprop_to_dictionary(const struct IDProperty *id_property) const =0
create dictionary containing the given id_property.
virtual std::optional< eIDPropertyType > property_type() const =0
return the IDPropertyType for (de)serializing.
constexpr IDPropertySerializer()=default
virtual bool supports_serializing() const
Can the serializer be used?
const Container & elements() const
Vector< DictionaryElementType > Items
std::shared_ptr< Value > LookupValue
const ArrayValue * as_array_value() const
static float get_float(PointerRNA &ptr, const char *name)
static int get_int(PointerRNA &ptr, const char *name)
static string get_string(PointerRNA &ptr, const char *name)
GAttributeReader lookup(const void *owner, const AttributeIDRef &attribute_id)
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRefNull prop_name)
Allocate a new IDProperty of type IDP_GROUP.
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_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
std::unique_ptr< io::serialize::ArrayValue > convert_to_serialize_values(const IDProperty *properties)
Convert the given properties to Value objects for serialization.
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(StringRefNull prop_name, int32_t value)
Allocate a new IDProperty of type IDP_INT, set its name and value.
static constexpr StringRef IDP_KEY_NAME("name")
static constexpr IDPIntSerializer IDP_SERIALIZER_INT
IDProperty * convert_from_serialize_value(const blender::io::serialize::Value &value)
Convert the given value to an IDProperty.
PrimitiveValue< double, eValueType::Double > DoubleValue
PrimitiveValue< int64_t, eValueType::Int > IntValue
Helper class for parsing DictionaryValues.
std::optional< eIDPropertyType > get_subtype() const
std::optional< double > get_double_value() const
DictionaryEntryParser(const DictionaryValue &value)
const ArrayValue * get_array_value() const
std::optional< eIDPropertyType > get_type() const
std::optional< std::string > get_name() const
std::optional< Vector< float > > get_array_float_value() const
std::optional< int32_t > get_int_value() const
std::optional< float > get_float_value() const
const DictionaryValue::Lookup lookup
std::optional< Vector< double > > get_array_double_value() const
std::optional< Vector< int32_t > > get_array_int_value() const
std::optional< std::string > get_string_value() const