mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 02:07:36 +00:00
schema entity initialize() method, optional argument forwarding in file::create, populate_derived in InstanceData
This commit is contained in:
@@ -183,7 +183,7 @@ class Implementation(codegen.Base):
|
||||
if arg["is_derived"]:
|
||||
constructor_implementations.append(templates.constructor_stmt_derived % {"index": arg["index"] - 1})
|
||||
else:
|
||||
is_optional_non_naked_ptr = arg["is_optional"] and not arg["non_optional_type"].endswith("*")
|
||||
is_optional_non_naked_ptr = arg["full_type"].startswith("std::optional")
|
||||
arg_name = "v%(index)d_%(name)s" % arg
|
||||
deref_name = ("*%s" % arg_name) if is_optional_non_naked_ptr else arg_name
|
||||
|
||||
@@ -318,7 +318,7 @@ class Implementation(codegen.Base):
|
||||
else templates.simpletype_impl_is_without_supertype
|
||||
)
|
||||
|
||||
constructor = templates.constructor_single_initlist# if superclass else templates.constructor
|
||||
initializer = templates.initialize_single_initlist
|
||||
|
||||
simpletype_impl_cast = (
|
||||
templates.simpletype_impl_cast_templated
|
||||
@@ -371,7 +371,7 @@ class Implementation(codegen.Base):
|
||||
# ("const std::weak_ptr<InstanceData>& e",),
|
||||
# "",
|
||||
# ),
|
||||
# ("", "", constructor, "", ("%s v" % type_str,), ("set_attribute_value(0, v%s);" % ("->generalize()" 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 ""))) if mapping.simple_type_parent(class_name) is None else \
|
||||
# ("v", "", constructor, "", ("%s v" % type_str,), ""),
|
||||
("", "", templates.cast_function, type_str, (), simpletype_impl_cast),
|
||||
),
|
||||
|
||||
@@ -116,9 +116,8 @@ public:
|
||||
%(name)s() {}
|
||||
explicit %(name)s (const std::weak_ptr<InstanceData>& data) : %(superclass)s(data) {}
|
||||
|
||||
// virtual const IfcParse::type_declaration& declaration() const;
|
||||
static const IfcParse::type_declaration& Class();
|
||||
// %(name)s (%(type)s v);
|
||||
void initialize(%(type)s v);
|
||||
operator %(type)s() const;
|
||||
};
|
||||
"""
|
||||
@@ -134,7 +133,7 @@ simpletype_impl_explicit_constructor = "data_ = e;"
|
||||
simpletype_impl_constructor = (
|
||||
"data_ = new const std::weak_ptr<InstanceData>&(%(schema_name_upper)s_types[%(index_in_schema)d]); set_attribute_value(0, v);"
|
||||
)
|
||||
simpletype_impl_constructor_templated = "data_ = new const std::weak_ptr<InstanceData>&(%(schema_name_upper)s_types[%(index_in_schema)d]); set_attribute_value(0, v->generalize());"
|
||||
simpletype_impl_constructor_templated = "data_ = new const std::weak_ptr<InstanceData>&(%(schema_name_upper)s_types[%(index_in_schema)d]); set_attribute_value(0, cast_vector<express::Base>(v));"
|
||||
simpletype_impl_cast = "return get_attribute_value(0);"
|
||||
simpletype_impl_cast_templated = "std::vector<express::Base> es = get_attribute_value(0); return cast_vector<%(underlying_type)s>(es);"
|
||||
|
||||
@@ -170,10 +169,9 @@ public:
|
||||
static const char* ToString(Value v);
|
||||
static Value FromString(const std::string& s);
|
||||
|
||||
// virtual const IfcParse::enumeration_type& declaration() const;
|
||||
static const IfcParse::enumeration_type& Class();
|
||||
// %(name)s (Value v);
|
||||
// %(name)s (const std::string& v);
|
||||
void initialize(Value v);
|
||||
void initialize(const std::string& v);
|
||||
operator Value() const;
|
||||
};
|
||||
"""
|
||||
@@ -184,9 +182,9 @@ public:
|
||||
%(name)s() {}
|
||||
explicit %(name)s (const std::weak_ptr<InstanceData>& data) : %(superclass)s(data) {}
|
||||
|
||||
%(attributes)s %(inverse)s // virtual const IfcParse::entity& declaration() const;
|
||||
%(attributes)s %(inverse)s
|
||||
static const IfcParse::entity& Class();
|
||||
// %(name)s (%(constructor_arguments)s);
|
||||
void initialize(%(constructor_arguments)s);
|
||||
};
|
||||
"""
|
||||
|
||||
@@ -228,10 +226,8 @@ const char* %(schema_name)s::%(name)s::ToString(Value v) {
|
||||
entity_implementation = """// Function implementations for %(name)s
|
||||
%(attributes)s
|
||||
%(inverse)s
|
||||
// const IfcParse::entity& %(schema_name)s::%(name)s::declaration() const { return *((IfcParse::entity*)%(schema_name_upper)s_types[%(index_in_schema)d]); }
|
||||
const IfcParse::entity& %(schema_name)s::%(name)s::Class() { return *((IfcParse::entity*)%(schema_name_upper)s_types[%(index_in_schema)d]); }
|
||||
// %(schema_name)s::%(name)s::%(name)s(const std::weak_ptr<InstanceData>& e) : %(superclass)s { }
|
||||
// %(schema_name)s::%(name)s::%(name)s(%(constructor_arguments)s) : %(superclass_num_attrs)s { %(constructor_implementation)s; populate_derived(); }
|
||||
void %(schema_name)s::%(name)s::initialize(%(constructor_arguments)s) { %(constructor_implementation)s }
|
||||
"""
|
||||
|
||||
# data_ = e;
|
||||
@@ -242,8 +238,8 @@ optional_attribute_description = "/// Whether the optional attribute %s is defin
|
||||
function = "%(return_type)s %(schema_name)s::%(class_name)s::%(name)s(%(arguments)s) { %(body)s }"
|
||||
const_function = "%(return_type)s %(schema_name)s::%(class_name)s::%(name)s(%(arguments)s) const { %(body)s }"
|
||||
constructor = "%(schema_name)s::%(class_name)s::%(class_name)s(%(arguments)s) { %(body)s }"
|
||||
constructor_single_initlist = (
|
||||
"%(schema_name)s::%(class_name)s::%(class_name)s(%(arguments)s) : %(superclass)s(%(superclass_init)s) { %(body)s }"
|
||||
initialize_single_initlist = (
|
||||
"void %(schema_name)s::%(class_name)s::initialize(%(arguments)s) { %(body)s }"
|
||||
)
|
||||
cast_function = "%(schema_name)s::%(class_name)s::operator %(return_type)s() const { %(body)s }"
|
||||
|
||||
@@ -293,13 +289,13 @@ constructor_stmt_enum = (
|
||||
"set_attribute_value(%(index)d, (EnumerationReference(&%(type)s::Class(),(size_t)%(name)s)));"
|
||||
)
|
||||
constructor_stmt_array = (
|
||||
"set_attribute_value(%(index)d, (%(name)s)->generalize());"
|
||||
"set_attribute_value(%(index)d, cast_vector<express::Base>(%(name)s));"
|
||||
)
|
||||
constructor_stmt_derived = (
|
||||
""
|
||||
)
|
||||
constructor_stmt_instance = (
|
||||
"set_attribute_value(%(index)d, %(name)s ? %(name)s->as<IfcUtil::IfcBaseClass>() : (IfcUtil::IfcBaseClass*) nullptr);"
|
||||
"set_attribute_value(%(index)d, %(name)s);"
|
||||
)
|
||||
|
||||
constructor_stmt_optional = " if (%(name)s) {%(stmt)s }"
|
||||
|
||||
@@ -17,11 +17,11 @@ extern declaration* HEADER_SECTION_SCHEMA_types[5];
|
||||
|
||||
// Function implementations for schema_name
|
||||
const IfcParse::type_declaration& Header_section_schema::schema_name::Class() { return *((IfcParse::type_declaration*)HEADER_SECTION_SCHEMA_types[3]); }
|
||||
Header_section_schema::schema_name::operator std::string() const { return get_attribute_value(0); }
|
||||
void Header_section_schema::schema_name::initialize(std::string v) { set_attribute_value(0, (v)); }
|
||||
|
||||
// Function implementations for time_stamp_text
|
||||
const IfcParse::type_declaration& Header_section_schema::time_stamp_text::Class() { return *((IfcParse::type_declaration*)HEADER_SECTION_SCHEMA_types[4]); }
|
||||
Header_section_schema::time_stamp_text::operator std::string() const { return get_attribute_value(0); }
|
||||
void Header_section_schema::time_stamp_text::initialize(std::string v) { set_attribute_value(0, (v)); }
|
||||
|
||||
|
||||
// Function implementations for file_description
|
||||
@@ -31,10 +31,8 @@ std::string Header_section_schema::file_description::implementation_level() cons
|
||||
void Header_section_schema::file_description::setimplementation_level(const std::string& v) { set_attribute_value(1, v);if constexpr (false)unset_attribute_value(1); }
|
||||
|
||||
|
||||
// const IfcParse::entity& Header_section_schema::file_description::declaration() const { return *((IfcParse::entity*)HEADER_SECTION_SCHEMA_types[0]); }
|
||||
const IfcParse::entity& Header_section_schema::file_description::Class() { return *((IfcParse::entity*)HEADER_SECTION_SCHEMA_types[0]); }
|
||||
// Header_section_schema::file_description::file_description(const std::weak_ptr<InstanceData>& e) : express::Entity(e) { }
|
||||
// Header_section_schema::file_description::file_description(std::vector< std::string > /*[1:?]*/ v1_description, std::string v2_implementation_level) : express::Entity(const std::weak_ptr<InstanceData>&(in_memory_attribute_storage(2))) { set_attribute_value(0, (v1_description));set_attribute_value(1, (v2_implementation_level));; populate_derived(); }
|
||||
void Header_section_schema::file_description::initialize(std::vector< std::string > /*[1:?]*/ v1_description, std::string v2_implementation_level) { set_attribute_value(0, (v1_description));set_attribute_value(1, (v2_implementation_level)); }
|
||||
|
||||
// Function implementations for file_name
|
||||
std::string Header_section_schema::file_name::name() const { std::string v = get_attribute_value(0); return v; }
|
||||
@@ -53,18 +51,14 @@ std::string Header_section_schema::file_name::authorization() const { std::stri
|
||||
void Header_section_schema::file_name::setauthorization(const std::string& v) { set_attribute_value(6, v);if constexpr (false)unset_attribute_value(6); }
|
||||
|
||||
|
||||
// const IfcParse::entity& Header_section_schema::file_name::declaration() const { return *((IfcParse::entity*)HEADER_SECTION_SCHEMA_types[1]); }
|
||||
const IfcParse::entity& Header_section_schema::file_name::Class() { return *((IfcParse::entity*)HEADER_SECTION_SCHEMA_types[1]); }
|
||||
// Header_section_schema::file_name::file_name(const std::weak_ptr<InstanceData>& e) : express::Entity(e) { }
|
||||
// Header_section_schema::file_name::file_name(std::string v1_name, std::string v2_time_stamp, std::vector< std::string > /*[1:?]*/ v3_author, std::vector< std::string > /*[1:?]*/ v4_organization, std::string v5_preprocessor_version, std::string v6_originating_system, std::string v7_authorization) : express::Entity(const std::weak_ptr<InstanceData>&(in_memory_attribute_storage(7))) { set_attribute_value(0, (v1_name));set_attribute_value(1, (v2_time_stamp));set_attribute_value(2, (v3_author));set_attribute_value(3, (v4_organization));set_attribute_value(4, (v5_preprocessor_version));set_attribute_value(5, (v6_originating_system));set_attribute_value(6, (v7_authorization));; populate_derived(); }
|
||||
void Header_section_schema::file_name::initialize(std::string v1_name, std::string v2_time_stamp, std::vector< std::string > /*[1:?]*/ v3_author, std::vector< std::string > /*[1:?]*/ v4_organization, std::string v5_preprocessor_version, std::string v6_originating_system, std::string v7_authorization) { set_attribute_value(0, (v1_name));set_attribute_value(1, (v2_time_stamp));set_attribute_value(2, (v3_author));set_attribute_value(3, (v4_organization));set_attribute_value(4, (v5_preprocessor_version));set_attribute_value(5, (v6_originating_system));set_attribute_value(6, (v7_authorization)); }
|
||||
|
||||
// Function implementations for file_schema
|
||||
std::vector< std::string > /*[1:?]*/ Header_section_schema::file_schema::schema_identifiers() const { std::vector< std::string > /*[1:?]*/ v = get_attribute_value(0); return v; }
|
||||
void Header_section_schema::file_schema::setschema_identifiers(const std::vector< std::string > /*[1:?]*/& v) { set_attribute_value(0, v);if constexpr (false)unset_attribute_value(0); }
|
||||
|
||||
|
||||
// const IfcParse::entity& Header_section_schema::file_schema::declaration() const { return *((IfcParse::entity*)HEADER_SECTION_SCHEMA_types[2]); }
|
||||
const IfcParse::entity& Header_section_schema::file_schema::Class() { return *((IfcParse::entity*)HEADER_SECTION_SCHEMA_types[2]); }
|
||||
// Header_section_schema::file_schema::file_schema(const std::weak_ptr<InstanceData>& e) : express::Entity(e) { }
|
||||
// Header_section_schema::file_schema::file_schema(std::vector< std::string > /*[1:?]*/ v1_schema_identifiers) : express::Entity(const std::weak_ptr<InstanceData>&(in_memory_attribute_storage(1))) { set_attribute_value(0, (v1_schema_identifiers));; populate_derived(); }
|
||||
void Header_section_schema::file_schema::initialize(std::vector< std::string > /*[1:?]*/ v1_schema_identifiers) { set_attribute_value(0, (v1_schema_identifiers)); }
|
||||
|
||||
|
||||
@@ -35,9 +35,8 @@ public:
|
||||
schema_name() {}
|
||||
explicit schema_name (const std::weak_ptr<InstanceData>& data) : express::DeclaredType(data) {}
|
||||
|
||||
// virtual const IfcParse::type_declaration& declaration() const;
|
||||
static const IfcParse::type_declaration& Class();
|
||||
// schema_name (std::string v);
|
||||
void initialize(std::string v);
|
||||
operator std::string() const;
|
||||
};
|
||||
|
||||
@@ -46,9 +45,8 @@ public:
|
||||
time_stamp_text() {}
|
||||
explicit time_stamp_text (const std::weak_ptr<InstanceData>& data) : express::DeclaredType(data) {}
|
||||
|
||||
// virtual const IfcParse::type_declaration& declaration() const;
|
||||
static const IfcParse::type_declaration& Class();
|
||||
// time_stamp_text (std::string v);
|
||||
void initialize(std::string v);
|
||||
operator std::string() const;
|
||||
};
|
||||
|
||||
@@ -63,9 +61,9 @@ public:
|
||||
void setdescription(const std::vector< std::string > /*[1:?]*/& v);
|
||||
std::string implementation_level() const;
|
||||
void setimplementation_level(const std::string& v);
|
||||
// virtual const IfcParse::entity& declaration() const;
|
||||
|
||||
static const IfcParse::entity& Class();
|
||||
// file_description (std::vector< std::string > /*[1:?]*/ v1_description, std::string v2_implementation_level);
|
||||
void initialize(std::vector< std::string > /*[1:?]*/ v1_description, std::string v2_implementation_level);
|
||||
};
|
||||
|
||||
class IFC_PARSE_API file_name : public express::Entity {
|
||||
@@ -87,9 +85,9 @@ public:
|
||||
void setoriginating_system(const std::string& v);
|
||||
std::string authorization() const;
|
||||
void setauthorization(const std::string& v);
|
||||
// virtual const IfcParse::entity& declaration() const;
|
||||
|
||||
static const IfcParse::entity& Class();
|
||||
// file_name (std::string v1_name, std::string v2_time_stamp, std::vector< std::string > /*[1:?]*/ v3_author, std::vector< std::string > /*[1:?]*/ v4_organization, std::string v5_preprocessor_version, std::string v6_originating_system, std::string v7_authorization);
|
||||
void initialize(std::string v1_name, std::string v2_time_stamp, std::vector< std::string > /*[1:?]*/ v3_author, std::vector< std::string > /*[1:?]*/ v4_organization, std::string v5_preprocessor_version, std::string v6_originating_system, std::string v7_authorization);
|
||||
};
|
||||
|
||||
class IFC_PARSE_API file_schema : public express::Entity {
|
||||
@@ -99,9 +97,9 @@ public:
|
||||
|
||||
std::vector< std::string > /*[1:?]*/ schema_identifiers() const;
|
||||
void setschema_identifiers(const std::vector< std::string > /*[1:?]*/& v);
|
||||
// virtual const IfcParse::entity& declaration() const;
|
||||
|
||||
static const IfcParse::entity& Class();
|
||||
// file_schema (std::vector< std::string > /*[1:?]*/ v1_schema_identifiers);
|
||||
void initialize(std::vector< std::string > /*[1:?]*/ v1_schema_identifiers);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
+765
-2071
File diff suppressed because it is too large
Load Diff
+1751
-2032
File diff suppressed because it is too large
Load Diff
+898
-2450
File diff suppressed because it is too large
Load Diff
+2096
-2433
File diff suppressed because it is too large
Load Diff
+923
-2525
File diff suppressed because it is too large
Load Diff
+2152
-2492
File diff suppressed because it is too large
Load Diff
+938
-2570
File diff suppressed because it is too large
Load Diff
+2196
-2543
File diff suppressed because it is too large
Load Diff
+994
-2738
File diff suppressed because it is too large
Load Diff
+2370
-2748
File diff suppressed because it is too large
Load Diff
+1000
-2752
File diff suppressed because it is too large
Load Diff
+2370
-2745
File diff suppressed because it is too large
Load Diff
+1000
-2752
File diff suppressed because it is too large
Load Diff
+2370
-2745
File diff suppressed because it is too large
Load Diff
+1001
-2759
File diff suppressed because it is too large
Load Diff
+2372
-2744
File diff suppressed because it is too large
Load Diff
+1007
-2777
File diff suppressed because it is too large
Load Diff
+2390
-2765
File diff suppressed because it is too large
Load Diff
+999
-2753
File diff suppressed because it is too large
Load Diff
+2376
-2752
File diff suppressed because it is too large
Load Diff
+998
-2750
File diff suppressed because it is too large
Load Diff
+2374
-2750
File diff suppressed because it is too large
Load Diff
+995
-2739
File diff suppressed because it is too large
Load Diff
+2361
-2735
File diff suppressed because it is too large
Load Diff
+11
-1
@@ -410,8 +410,18 @@ public:
|
||||
|
||||
void build_inverses_(const express::Base&);
|
||||
|
||||
// @nb this does not support id assignment
|
||||
template <typename T, typename... Ts>
|
||||
T create(Ts&&... args) {
|
||||
T t = create(&T::Class()).template as<T>();
|
||||
if constexpr (sizeof...(Ts) > 0) {
|
||||
t.initialize(std::forward<Ts>(args)...);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T create(int id=-1) {
|
||||
T create(int id = -1) {
|
||||
return create(&T::Class(), id).template as<T>();
|
||||
}
|
||||
|
||||
|
||||
@@ -122,13 +122,14 @@ void IfcUtil::unescape_xml(std::string& str) {
|
||||
boost::replace_all(str, ">", ">");
|
||||
}
|
||||
|
||||
void express::Entity::populate_derived() {
|
||||
for (auto it = declaration().as_entity()->derived().begin(); it != declaration().as_entity()->derived().end(); ++it) {
|
||||
if (*it) {
|
||||
set_attribute_value(
|
||||
std::distance(declaration().as_entity()->derived().begin(), it),
|
||||
Derived{}
|
||||
);
|
||||
void InstanceData::populate_derived_() {
|
||||
if (auto* ent = declaration_->as_entity()) {
|
||||
for (auto it = ent->derived().begin(); it != ent->derived().end(); ++it) {
|
||||
if (*it) {
|
||||
set_attribute_value(
|
||||
std::distance(ent->derived().begin(), it),
|
||||
Derived{});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,6 +420,8 @@ class IFC_PARSE_API InstanceData {
|
||||
template <typename T>
|
||||
T* get_storage_of_type() const;
|
||||
|
||||
void populate_derived_();
|
||||
|
||||
public:
|
||||
// Since rocks_db_attribute_storage has no members this is not a variant<in_memory, rocks> but in_memory*, where nullptr means a rocks_db_attribute_storage is constructed on the fly given the context from instance data.
|
||||
in_memory_attribute_storage* storage_;
|
||||
@@ -442,11 +444,15 @@ class IFC_PARSE_API InstanceData {
|
||||
|
||||
InstanceData(IfcParse::IfcFile* file, const IfcParse::declaration* declaration, uint32_t id, in_memory_attribute_storage&& storage)
|
||||
: file_(file), declaration_(declaration), identity_(counter_++), id_(id), storage_(new in_memory_attribute_storage(std::move(storage)))
|
||||
{}
|
||||
{
|
||||
populate_derived_();
|
||||
}
|
||||
|
||||
InstanceData(IfcParse::IfcFile* file, const IfcParse::declaration* declaration, uint32_t id, rocks_db_attribute_storage&&)
|
||||
: file_(file), declaration_(declaration), identity_(counter_++), id_(id), storage_(nullptr)
|
||||
{}
|
||||
{
|
||||
populate_derived_();
|
||||
}
|
||||
|
||||
/*
|
||||
// now that there are referenced as shared_ptr there is no move constructor anymore
|
||||
|
||||
@@ -144,10 +144,6 @@ class IFC_PARSE_API Entity : public Base {
|
||||
T get_value(const std::string& name, const T& default_value) const;
|
||||
|
||||
std::vector<express::Entity> get_inverse(const std::string& name) const;
|
||||
|
||||
// unsigned set_id(const std::optional<unsigned>& i);
|
||||
|
||||
void populate_derived();
|
||||
};
|
||||
|
||||
class IFC_PARSE_API Select : public Base {
|
||||
|
||||
Reference in New Issue
Block a user