mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Reuse constructors and return *this from initialize()
This commit is contained in:
@@ -115,9 +115,10 @@ class Header(codegen.Base):
|
|||||||
# with the v1 data model we're back to exactly one supertype, no more virtual inheritance to handle selects
|
# with the v1 data model we're back to exactly one supertype, no more virtual inheritance to handle selects
|
||||||
assert len(superclasses) == 1
|
assert len(superclasses) == 1
|
||||||
superclass_statement = superclasses[0]
|
superclass_statement = superclasses[0]
|
||||||
|
superclass_2 = superclass_statement.split('::')[-1]
|
||||||
|
|
||||||
write(
|
write(
|
||||||
templates.simpletype, name=name, type=type_str, attr_type=attr_type, superclass=superclass_statement
|
templates.simpletype, name=name, type=type_str, attr_type=attr_type, superclass=superclass_statement, superclass_2=superclass_2
|
||||||
)
|
)
|
||||||
|
|
||||||
class_definitions = []
|
class_definitions = []
|
||||||
@@ -181,6 +182,7 @@ class Header(codegen.Base):
|
|||||||
supertypes = list(map(case_normalize, supertypes))
|
supertypes = list(map(case_normalize, supertypes))
|
||||||
assert len(supertypes) == 1
|
assert len(supertypes) == 1
|
||||||
superclass = supertypes[0]
|
superclass = supertypes[0]
|
||||||
|
superclass_2 = superclass.split('::')[-1]
|
||||||
|
|
||||||
argument_count = mapping.argument_count(type)
|
argument_count = mapping.argument_count(type)
|
||||||
|
|
||||||
|
|||||||
@@ -113,11 +113,10 @@ derived_field_statement_attrs = "idxs.insert(%d); "
|
|||||||
simpletype = """%(documentation)s
|
simpletype = """%(documentation)s
|
||||||
class IFC_PARSE_API %(name)s : public %(superclass)s {
|
class IFC_PARSE_API %(name)s : public %(superclass)s {
|
||||||
public:
|
public:
|
||||||
%(name)s() {}
|
using %(superclass)s::%(superclass_2)s;
|
||||||
explicit %(name)s (const std::weak_ptr<instance_data>& data) : %(superclass)s(data) {}
|
|
||||||
|
|
||||||
static const ifcopenshell::type_declaration& Class();
|
static const ifcopenshell::type_declaration& Class();
|
||||||
void initialize(%(type)s v);
|
%(name)s initialize(%(type)s v);
|
||||||
operator %(type)s() const;
|
operator %(type)s() const;
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
@@ -142,8 +141,7 @@ simpletype_impl_declaration = "return *((ifcopenshell::type_declaration*)%(schem
|
|||||||
select = """%(documentation)s
|
select = """%(documentation)s
|
||||||
class IFC_PARSE_API %(name)s : public express::Select {
|
class IFC_PARSE_API %(name)s : public express::Select {
|
||||||
public:
|
public:
|
||||||
%(name)s() {}
|
using express::Select::Select;
|
||||||
explicit %(name)s(const express::Base& c) : express::Select(c) {}
|
|
||||||
|
|
||||||
static const ifcopenshell::select_type& Class();
|
static const ifcopenshell::select_type& Class();
|
||||||
%(template_items)s
|
%(template_items)s
|
||||||
@@ -162,16 +160,15 @@ select_cast_function = """ %(name)s(const %(item_name)s& c) : express::Select
|
|||||||
enumeration = """%(documentation)s
|
enumeration = """%(documentation)s
|
||||||
class IFC_PARSE_API %(name)s : public express::DeclaredType {
|
class IFC_PARSE_API %(name)s : public express::DeclaredType {
|
||||||
public:
|
public:
|
||||||
%(name)s() {}
|
using express::DeclaredType::DeclaredType;
|
||||||
explicit %(name)s (const std::weak_ptr<instance_data>& data) : express::DeclaredType(data) {}
|
|
||||||
|
|
||||||
typedef enum {%(values)s} Value;
|
typedef enum {%(values)s} Value;
|
||||||
static const char* ToString(Value v);
|
static const char* ToString(Value v);
|
||||||
static Value FromString(const std::string& s);
|
static Value FromString(const std::string& s);
|
||||||
|
|
||||||
static const ifcopenshell::enumeration_type& Class();
|
static const ifcopenshell::enumeration_type& Class();
|
||||||
void initialize(Value v);
|
%(name)s initialize(Value v);
|
||||||
void initialize(const std::string& v);
|
%(name)s initialize(const std::string& v);
|
||||||
operator Value() const;
|
operator Value() const;
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
@@ -179,12 +176,11 @@ public:
|
|||||||
entity = """%(documentation)s
|
entity = """%(documentation)s
|
||||||
class IFC_PARSE_API %(name)s : public %(superclass)s {
|
class IFC_PARSE_API %(name)s : public %(superclass)s {
|
||||||
public:
|
public:
|
||||||
%(name)s() {}
|
using %(superclass)s::%(superclass_2)s;
|
||||||
explicit %(name)s (const std::weak_ptr<instance_data>& data) : %(superclass)s(data) {}
|
|
||||||
|
|
||||||
%(attributes)s %(inverse)s
|
%(attributes)s %(inverse)s
|
||||||
static const ifcopenshell::entity& Class();
|
static const ifcopenshell::entity& Class();
|
||||||
void initialize(%(constructor_arguments)s);
|
%(name)s initialize(%(constructor_arguments)s);
|
||||||
};
|
};
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -227,7 +223,7 @@ entity_implementation = """// Function implementations for %(name)s
|
|||||||
%(attributes)s
|
%(attributes)s
|
||||||
%(inverse)s
|
%(inverse)s
|
||||||
const ifcopenshell::entity& %(schema_name)s::%(name)s::Class() { return *((ifcopenshell::entity*)%(schema_name_upper)s_types[%(index_in_schema)d]); }
|
const ifcopenshell::entity& %(schema_name)s::%(name)s::Class() { return *((ifcopenshell::entity*)%(schema_name_upper)s_types[%(index_in_schema)d]); }
|
||||||
void %(schema_name)s::%(name)s::initialize(%(constructor_arguments)s) { %(constructor_implementation)s }
|
%(schema_name)s::%(name)s %(schema_name)s::%(name)s::initialize(%(constructor_arguments)s) { %(constructor_implementation)s; return *this; }
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# data_ = e;
|
# data_ = e;
|
||||||
@@ -239,7 +235,7 @@ function = "%(return_type)s %(schema_name)s::%(class_name)s::%(name)s(%(argument
|
|||||||
const_function = "%(return_type)s %(schema_name)s::%(class_name)s::%(name)s(%(arguments)s) const { %(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 = "%(schema_name)s::%(class_name)s::%(class_name)s(%(arguments)s) { %(body)s }"
|
||||||
initialize_single_initlist = (
|
initialize_single_initlist = (
|
||||||
"void %(schema_name)s::%(class_name)s::initialize(%(arguments)s) { %(body)s }"
|
"%(schema_name)s::%(class_name)s %(schema_name)s::%(class_name)s::initialize(%(arguments)s) { %(body)s; return *this; }"
|
||||||
)
|
)
|
||||||
cast_function = "%(schema_name)s::%(class_name)s::operator %(return_type)s() const { %(body)s }"
|
cast_function = "%(schema_name)s::%(class_name)s::operator %(return_type)s() const { %(body)s }"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user