mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
conversion rules for first citizin enum types #1276
This commit is contained in:
@@ -223,6 +223,9 @@ class Implementation(codegen.Base):
|
||||
schema_entity_statements += [
|
||||
templates.schema_entity_stmt % locals() for name, type in mapping.schema.simpletypes.items()
|
||||
]
|
||||
schema_entity_statements += [
|
||||
templates.schema_entity_stmt % locals() for name, type in mapping.schema.enumerations.items()
|
||||
]
|
||||
schema_entity_statements += [
|
||||
templates.schema_entity_stmt % locals() for name, type in mapping.schema.entities.items()
|
||||
]
|
||||
@@ -329,6 +332,8 @@ class Implementation(codegen.Base):
|
||||
("extern entity* %s_%%s_type;" % schema_name_upper) % n for n in mapping.schema.entities.keys()
|
||||
] + [
|
||||
("extern type_declaration* %s_%%s_type;" % schema_name_upper) % n for n in mapping.schema.simpletypes.keys()
|
||||
] + [
|
||||
("extern enumeration_type* %s_%%s_type;" % schema_name_upper) % n for n in mapping.schema.enumerations.keys()
|
||||
]
|
||||
|
||||
self.str = templates.implementation % {
|
||||
|
||||
@@ -488,7 +488,10 @@ class SchemaClass(codegen.Base):
|
||||
for name, tys in subtypes.items():
|
||||
x.entity_subtypes(name, tys)
|
||||
|
||||
can_be_instantiated_set = set(list(mapping.schema.entities.keys()) + list(mapping.schema.simpletypes.keys()))
|
||||
can_be_instantiated_set = set(list(mapping.schema.entities.keys()) + \
|
||||
list(mapping.schema.simpletypes.keys()) + \
|
||||
list(mapping.schema.enumerations.keys()))
|
||||
|
||||
x.finalize(can_be_instantiated_set)
|
||||
|
||||
self.str = str(x)
|
||||
|
||||
@@ -140,11 +140,19 @@ select = """%(documentation)s
|
||||
typedef IfcUtil::IfcBaseClass %(name)s;
|
||||
"""
|
||||
|
||||
enumeration = """struct %(name)s {
|
||||
enumeration = """class IFC_PARSE_API %(name)s : public IfcUtil::IfcBaseType {
|
||||
%(documentation)s
|
||||
typedef enum {%(values)s} Value;
|
||||
IFC_PARSE_API static const char* ToString(Value v);
|
||||
IFC_PARSE_API static Value FromString(const std::string& s);
|
||||
public:
|
||||
typedef enum {%(values)s} Value;
|
||||
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 (IfcEntityInstanceData* e);
|
||||
%(name)s (Value v);
|
||||
%(name)s (const std::string& v);
|
||||
operator Value() const;
|
||||
};
|
||||
"""
|
||||
|
||||
@@ -160,6 +168,25 @@ public:
|
||||
"""
|
||||
|
||||
enumeration_function = """
|
||||
const IfcParse::enumeration_type& %(schema_name)s::%(name)s::declaration() const { return *%(schema_name_upper)s_%(name)s_type; }
|
||||
const IfcParse::enumeration_type& %(schema_name)s::%(name)s::Class() { return *%(schema_name_upper)s_%(name)s_type; }
|
||||
|
||||
%(schema_name)s::%(name)s::%(name)s(IfcEntityInstanceData* e) {
|
||||
data_ = e;
|
||||
}
|
||||
|
||||
%(schema_name)s::%(name)s::%(name)s(Value v) {
|
||||
IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();
|
||||
attr->set(IfcWrite::IfcWriteArgument::EnumerationReference(v,ToString(v)));
|
||||
data_->setArgument(0,attr);
|
||||
}
|
||||
|
||||
%(schema_name)s::%(name)s::%(name)s(const std::string& v) {
|
||||
IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();
|
||||
attr->set(IfcWrite::IfcWriteArgument::EnumerationReference(FromString(v),ToString(FromString(v))));
|
||||
data_->setArgument(0,attr);
|
||||
}
|
||||
|
||||
const char* %(schema_name)s::%(name)s::ToString(Value v) {
|
||||
if ( v < 0 || v >= %(max_id)d ) throw IfcException("Unable to find find keyword in schema");
|
||||
const char* names[] = { %(values)s };
|
||||
|
||||
Reference in New Issue
Block a user