mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +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 += [
|
schema_entity_statements += [
|
||||||
templates.schema_entity_stmt % locals() for name, type in mapping.schema.simpletypes.items()
|
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 += [
|
schema_entity_statements += [
|
||||||
templates.schema_entity_stmt % locals() for name, type in mapping.schema.entities.items()
|
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 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 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 % {
|
self.str = templates.implementation % {
|
||||||
|
|||||||
@@ -488,7 +488,10 @@ class SchemaClass(codegen.Base):
|
|||||||
for name, tys in subtypes.items():
|
for name, tys in subtypes.items():
|
||||||
x.entity_subtypes(name, tys)
|
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)
|
x.finalize(can_be_instantiated_set)
|
||||||
|
|
||||||
self.str = str(x)
|
self.str = str(x)
|
||||||
|
|||||||
@@ -140,11 +140,19 @@ select = """%(documentation)s
|
|||||||
typedef IfcUtil::IfcBaseClass %(name)s;
|
typedef IfcUtil::IfcBaseClass %(name)s;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
enumeration = """struct %(name)s {
|
enumeration = """class IFC_PARSE_API %(name)s : public IfcUtil::IfcBaseType {
|
||||||
%(documentation)s
|
%(documentation)s
|
||||||
typedef enum {%(values)s} Value;
|
public:
|
||||||
IFC_PARSE_API static const char* ToString(Value v);
|
typedef enum {%(values)s} Value;
|
||||||
IFC_PARSE_API static Value FromString(const std::string& s);
|
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 = """
|
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) {
|
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");
|
if ( v < 0 || v >= %(max_id)d ) throw IfcException("Unable to find find keyword in schema");
|
||||||
const char* names[] = { %(values)s };
|
const char* names[] = { %(values)s };
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ namespace IfcUtil {
|
|||||||
IfcBaseType() : IfcBaseClass() {}
|
IfcBaseType() : IfcBaseClass() {}
|
||||||
IfcBaseType(IfcEntityInstanceData* d) : IfcBaseClass(d) {}
|
IfcBaseType(IfcEntityInstanceData* d) : IfcBaseClass(d) {}
|
||||||
|
|
||||||
virtual const IfcParse::type_declaration& declaration() const = 0;
|
virtual const IfcParse::declaration& declaration() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user