15using namespace blender::io::serialize;
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);
178 if (value ==
nullptr) {
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
201 const std::shared_ptr<Value> *value =
lookup.lookup_ptr(key);
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
213 const std::shared_ptr<Value> *value =
lookup.lookup_ptr(key);
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
225 const std::shared_ptr<Value> *value =
lookup.lookup_ptr(key);
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
237 const std::shared_ptr<Value> *value =
lookup.lookup_ptr(key);
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
255 const std::shared_ptr<Value> *value =
lookup.lookup_ptr(key);
256 if (value ==
nullptr) {
259 if (value->get()->type() != eValueType::Array) {
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()) {
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);
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) {
676 for (
const std::shared_ptr<Value> &
element :
array->elements()) {
736 switch (property_type) {
759 BLI_assert_msg(
false,
"Trying to convert an unsupported/unknown property type to a string");
800 std::unique_ptr<ArrayValue>
result = std::make_unique<ArrayValue>();
801 const IDProperty *current_property = properties;
802 while (current_property !=
nullptr) {
808 current_property = current_property->
next;
823 std::optional<eIDPropertyType> property_type = entry_reader.
get_type();
824 if (!property_type.has_value()) {
843 if (last_created ==
nullptr) {
851 if (previous_added) {
852 previous_added->
next = last_created;
854 last_created->
prev = previous_added;
855 previous_added = last_created;
#define IDP_float_get(prop)
#define IDP_array_voidp_get(prop)
#define IDP_int_get(prop)
#define IDP_array_double_get(prop)
#define IDP_string_get(prop)
#define IDP_double_get(prop)
#define IDP_array_int_get(prop)
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
#define IDP_array_float_get(prop)
#define IDP_bool_get(prop)
#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.
struct IDProperty IDProperty
ATTR_WARN_UNUSED_RESULT const void * element
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?
Span< std::shared_ptr< Value > > elements() const
Map< std::string, std::shared_ptr< Value > > Lookup
const ArrayValue * as_array_value() const
static string get_string(PointerRNA &ptr, const char *name)
static constexpr StringRef IDP_KEY_SUBTYPE("subtype")
static constexpr StringRef IDP_PROPERTY_TYPENAME_FLOAT("IDP_FLOAT")
std::unique_ptr< IDProperty, IDPropertyDeleter > create_bool(StringRef prop_name, bool value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_BOOLEAN, set its name and value.
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
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
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
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
static constexpr StringRef IDP_PROPERTY_TYPENAME_ARRAY("IDP_ARRAY")
std::unique_ptr< blender::io::serialize::ArrayValue > convert_to_serialize_values(const IDProperty *properties)
Convert the given properties to Value objects for serialization.
static constexpr StringRef IDP_KEY_NAME("name")
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.
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