Fix some schema generation issues

This commit is contained in:
Thomas Krijnen
2026-03-26 10:39:29 +01:00
parent 4ec643d4e1
commit 95a094d596
4 changed files with 46 additions and 43 deletions
@@ -371,7 +371,7 @@ class Implementation(codegen.Base):
# ("const std::weak_ptr<InstanceData>& e",), # ("const std::weak_ptr<InstanceData>& e",),
# "", # "",
# ), # ),
("", "", initializer, "", ("%s v" % type_str,), ("set_attribute_value(0, %s(v));" % ("cast_vector<express::Base>" if mapping.is_templated_list(type) else ""))) if mapping.simple_type_parent(class_name) is None else \ ("", "", initializer, "", ("%s v" % type_str,), ("set_attribute_value(0, %s(v));" % ("cast_vector<express::Base>" if mapping.is_templated_list(type) else ""))),
# ("v", "", constructor, "", ("%s v" % type_str,), ""), # ("v", "", constructor, "", ("%s v" % type_str,), ""),
("", "", templates.cast_function, type_str, (), simpletype_impl_cast), ("", "", templates.cast_function, type_str, (), simpletype_impl_cast),
), ),
@@ -264,7 +264,7 @@ get_attr_stmt = "%(null_check)s %(non_optional_type)s v = get_attribute_value(%(
get_attr_stmt_enum = "%(null_check)s return %(non_optional_type)s::FromString(get_attribute_value(%(index)d));" get_attr_stmt_enum = "%(null_check)s return %(non_optional_type)s::FromString(get_attribute_value(%(index)d));"
get_attr_stmt_entity = "%(null_check)s return ((express::Base)(get_attribute_value(%(index)d))).as<%(non_optional_type_no_pointer)s>();" get_attr_stmt_entity = "%(null_check)s return ((express::Base)(get_attribute_value(%(index)d))).as<%(non_optional_type_no_pointer)s>();"
get_attr_stmt_array = "%(null_check)s std::vector<express::Base> es = get_attribute_value(%(index)d); return cast_vector<%(list_instance_type)s>(es);" get_attr_stmt_array = "%(null_check)s std::vector<express::Base> es = get_attribute_value(%(index)d); return cast_vector<%(list_instance_type)s>(es);"
get_attr_stmt_nested_array = "%(null_check)s std::vector<std::vector<express::Base>> es = get_attribute_value(%(index)d); return cast_vector_vector<%(list_instance_type)s>(es);" get_attr_stmt_nested_array = "%(null_check)s std::vector<std::vector<express::Base>> es = get_attribute_value(%(index)d); return cast_vector<%(list_instance_type)s>(es);"
get_inverse = "return cast_vector<%(type)s>(file()->getInverse(data()->id(), %(schema_name_upper)s_types[%(type_index)d], %(index)d));" get_inverse = "return cast_vector<%(type)s>(file()->getInverse(data()->id(), %(schema_name_upper)s_types[%(type_index)d], %(index)d));"
@@ -279,7 +279,7 @@ set_attr_stmt_array = (
"%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::Base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s" "%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::Base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
) )
set_attr_stmt_nested_array = ( set_attr_stmt_nested_array = (
"%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector_vector<express::Base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s" "%(check_optional_set_begin)sset_attribute_value(%(index)d, cast_vector<express::Base>(%(star_if_optional)sv));%(check_optional_set_else)sunset_attribute_value(%(index)d);%(check_optional_set_end)s"
) )
constructor_stmt = ( constructor_stmt = (
+43 -22
View File
@@ -205,32 +205,53 @@ struct hash<express::Entity> {
} // namespace boost } // namespace boost
template <typename T, typename U> namespace {
std::vector<T> cast_vector(const std::vector<U>& vs) { template <typename>
std::vector<T> result; struct is_std_vector : std::false_type {};
for (const auto& v : vs) {
if constexpr (std::is_base_of_v<T, U>) { template <typename X, typename A>
// For a base or identity transform we can just rely on static cast struct is_std_vector<std::vector<X, A>> : std::true_type {};
result.push_back(v);
} else if constexpr (std::is_base_of_v<express::Select, U> && std::is_same_v<T, express::Base>) { template <typename T>
// From a select to concrete we simply call the appropriate method constexpr bool is_std_vector_v = is_std_vector<T>::value;
result.push_back(v.concrete());
} else { template <typename T>
if (auto u = v.template as<T>()) { struct is_std_vector_vector : std::false_type {};
result.push_back(u);
} template <typename T, typename Alloc, typename Alloc2>
} struct is_std_vector_vector<std::vector<std::vector<T, Alloc>, Alloc2>> : std::true_type {};
}
return result; template <typename T>
constexpr bool is_std_vector_vector_v = is_std_vector_vector<T>::value;
} }
template <typename T, typename U> template <typename T, typename U>
std::vector<std::vector<T>> cast_vector_vector(const std::vector<std::vector<U>>& vs) { auto cast_vector(const std::vector<U>& vs) {
std::vector<std::vector<T>> result; if constexpr (is_std_vector<U>::value) {
for (const auto& v : vs) { using V = typename U::value_type;
result.push_back(cast_vector<T>(v)); std::vector<std::vector<T>> result;
result.reserve(vs.size());
for (const auto& v : vs) {
result.push_back(cast_vector<T>(v));
}
return result;
} else {
std::vector<T> result;
for (const auto& v : vs) {
if constexpr (std::is_base_of_v<T, U>) {
// For a base or identity transform we can just rely on static cast
result.push_back(v);
} else if constexpr (std::is_base_of_v<express::Select, U> && std::is_same_v<T, express::Base>) {
// From a select to concrete we simply call the appropriate method
result.push_back(v.concrete());
} else {
if (auto u = v.template as<T>()) {
result.push_back(u);
}
}
}
return result;
} }
return result;
} }
#endif #endif
-18
View File
@@ -262,24 +262,6 @@
#endif #endif
%} %}
%{
template<typename T>
struct is_std_vector : std::false_type {};
template<typename T, typename Alloc>
struct is_std_vector<std::vector<T, Alloc>> : std::true_type {};
template<typename T>
constexpr bool is_std_vector_v = is_std_vector<T>::value;
template<typename T>
struct is_std_vector_vector : std::false_type {};
template<typename T, typename Alloc, typename Alloc2>
struct is_std_vector_vector<std::vector<std::vector<T, Alloc>, Alloc2>> : std::true_type {};
template<typename T>
constexpr bool is_std_vector_vector_v = is_std_vector_vector<T>::value;
%}
// Create docstrings for generated python code. // Create docstrings for generated python code.
%feature("autodoc", "1"); %feature("autodoc", "1");