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 = (
+30 -9
View File
@@ -205,8 +205,37 @@ struct hash<express::Entity> {
} // namespace boost } // namespace boost
namespace {
template <typename>
struct is_std_vector : std::false_type {};
template <typename X, typename A>
struct is_std_vector<std::vector<X, A>> : 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;
}
template <typename T, typename U> template <typename T, typename U>
std::vector<T> cast_vector(const std::vector<U>& vs) { auto cast_vector(const std::vector<U>& vs) {
if constexpr (is_std_vector<U>::value) {
using V = typename U::value_type;
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; std::vector<T> result;
for (const auto& v : vs) { for (const auto& v : vs) {
if constexpr (std::is_base_of_v<T, U>) { if constexpr (std::is_base_of_v<T, U>) {
@@ -222,15 +251,7 @@ std::vector<T> cast_vector(const std::vector<U>& vs) {
} }
} }
return result; return result;
}
template <typename T, typename U>
std::vector<std::vector<T>> cast_vector_vector(const std::vector<std::vector<U>>& vs) {
std::vector<std::vector<T>> result;
for (const auto& v : vs) {
result.push_back(cast_vector<T>(v));
} }
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");