mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
Work in progress on mapping templates
This commit is contained in:
@@ -77,13 +77,10 @@ class Header(codegen.Base):
|
|||||||
attr_lines = []
|
attr_lines = []
|
||||||
|
|
||||||
def write_method(attr):
|
def write_method(attr):
|
||||||
if attr.optional:
|
|
||||||
attr_lines.append(templates.optional_attribute_description % (attr.name, name))
|
|
||||||
attr_lines.append("bool has%s() const;" % (attr.name))
|
|
||||||
attr_lines.extend(
|
attr_lines.extend(
|
||||||
["/// %s" % d for d in documentation.description(".".join((name, attr.name)))]
|
["/// %s" % d for d in documentation.description(".".join((name, attr.name)))]
|
||||||
)
|
)
|
||||||
type_str = mapping.get_parameter_type(attr, allow_optional=False, allow_entities=False)
|
type_str = mapping.get_parameter_type(attr)
|
||||||
if mapping.make_argument_type(attr) != "IfcUtil::Argument_UNKNOWN":
|
if mapping.make_argument_type(attr) != "IfcUtil::Argument_UNKNOWN":
|
||||||
attr_lines.append("%s %s() const;" % (type_str, attr.name))
|
attr_lines.append("%s %s() const;" % (type_str, attr.name))
|
||||||
attr_lines.append("void set%s(%s v);" % (attr.name, type_str))
|
attr_lines.append("void set%s(%s v);" % (attr.name, type_str))
|
||||||
|
|||||||
@@ -74,17 +74,6 @@ class Implementation(codegen.Base):
|
|||||||
write_attr = lambda str, **kwargs: attributes.append(str % kwargs)
|
write_attr = lambda str, **kwargs: attributes.append(str % kwargs)
|
||||||
for arg in constructor_arguments:
|
for arg in constructor_arguments:
|
||||||
if not arg["is_inherited"] and not arg["is_derived"]:
|
if not arg["is_inherited"] and not arg["is_derived"]:
|
||||||
if arg["is_optional"]:
|
|
||||||
write_attr(
|
|
||||||
templates.const_function,
|
|
||||||
class_name=name,
|
|
||||||
schema_name=schema_name,
|
|
||||||
schema_name_upper=schema_name_upper,
|
|
||||||
name="has%s" % arg["name"],
|
|
||||||
arguments="",
|
|
||||||
return_type="bool",
|
|
||||||
body=templates.optional_attr_stmt % {"index": arg["index"] - 1},
|
|
||||||
)
|
|
||||||
|
|
||||||
def find_template(arg):
|
def find_template(arg):
|
||||||
simple = mapping.schema.is_simpletype(arg["list_instance_type"])
|
simple = mapping.schema.is_simpletype(arg["list_instance_type"])
|
||||||
@@ -111,11 +100,12 @@ class Implementation(codegen.Base):
|
|||||||
arguments="",
|
arguments="",
|
||||||
schema_name=schema_name,
|
schema_name=schema_name,
|
||||||
schema_name_upper=schema_name_upper,
|
schema_name_upper=schema_name_upper,
|
||||||
return_type=arg["non_optional_type"],
|
return_type=arg["full_type"],
|
||||||
body=tmpl
|
body=tmpl
|
||||||
% {
|
% {
|
||||||
"index": arg["index"] - 1,
|
"index": arg["index"] - 1,
|
||||||
"type": arg["non_optional_type"].replace("::Value", ""),
|
"type": arg["full_type"].replace("::Value", ""),
|
||||||
|
"non_optional_type": arg["non_optional_type"].replace("::Value", ""),
|
||||||
"list_instance_type": arg["list_instance_type"],
|
"list_instance_type": arg["list_instance_type"],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -136,12 +126,17 @@ class Implementation(codegen.Base):
|
|||||||
templates.function,
|
templates.function,
|
||||||
class_name=name,
|
class_name=name,
|
||||||
name="set%s" % arg["name"],
|
name="set%s" % arg["name"],
|
||||||
arguments="%s v" % arg["non_optional_type"],
|
arguments="%s v" % arg["full_type"],
|
||||||
return_type="void",
|
return_type="void",
|
||||||
schema_name=schema_name,
|
schema_name=schema_name,
|
||||||
schema_name_upper=schema_name_upper,
|
schema_name_upper=schema_name_upper,
|
||||||
body=tmpl
|
body=tmpl
|
||||||
% {"index": arg["index"] - 1, "type": arg["non_optional_type"].replace("::Value", "")},
|
% {
|
||||||
|
"index": arg["index"] - 1,
|
||||||
|
"type": arg["full_type"].replace("::Value", ""),
|
||||||
|
"non_optional_type": arg["non_optional_type"].replace("::Value", ""),
|
||||||
|
"star_if_optional": "*" if arg["is_optional"] else ""
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if arg["is_derived"]:
|
if arg["is_derived"]:
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class Mapping:
|
|||||||
|
|
||||||
express_to_cpp_typemapping = {
|
express_to_cpp_typemapping = {
|
||||||
"boolean": "bool",
|
"boolean": "bool",
|
||||||
"logical": "bool",
|
"logical": "boost::logic::tribool",
|
||||||
"integer": "int",
|
"integer": "int",
|
||||||
"real": "double",
|
"real": "double",
|
||||||
"number": "double",
|
"number": "double",
|
||||||
@@ -40,6 +40,7 @@ class Mapping:
|
|||||||
[
|
[
|
||||||
"INT",
|
"INT",
|
||||||
"BOOL",
|
"BOOL",
|
||||||
|
"LOGICAL",
|
||||||
"DOUBLE",
|
"DOUBLE",
|
||||||
"STRING",
|
"STRING",
|
||||||
"BINARY",
|
"BINARY",
|
||||||
@@ -141,7 +142,10 @@ class Mapping:
|
|||||||
raise ValueError("Unable to map type %r for attribute %r" % (type, attr))
|
raise ValueError("Unable to map type %r for attribute %r" % (type, attr))
|
||||||
|
|
||||||
ty = _make_argument_type(attr.type if hasattr(attr, "type") else attr)
|
ty = _make_argument_type(attr.type if hasattr(attr, "type") else attr)
|
||||||
|
if ty == "TRIBOOL": ty = "LOGICAL"
|
||||||
|
|
||||||
if ty not in self.supported_argument_types:
|
if ty not in self.supported_argument_types:
|
||||||
|
import pdb; pdb.set_trace()
|
||||||
print("Attribute %r mapped as 'unknown'" % (attr), file=sys.stderr)
|
print("Attribute %r mapped as 'unknown'" % (attr), file=sys.stderr)
|
||||||
ty = "UNKNOWN"
|
ty = "UNKNOWN"
|
||||||
return "IfcUtil::Argument_%s" % ty
|
return "IfcUtil::Argument_%s" % ty
|
||||||
@@ -152,7 +156,7 @@ class Mapping:
|
|||||||
else:
|
else:
|
||||||
return self.get_type_dep(type.type)
|
return self.get_type_dep(type.type)
|
||||||
|
|
||||||
def get_parameter_type(self, attr, allow_optional, allow_entities, allow_pointer=True):
|
def get_parameter_type(self, attr, allow_optional=True):
|
||||||
attr_type = self.flatten_type(attr.type)
|
attr_type = self.flatten_type(attr.type)
|
||||||
|
|
||||||
if (isinstance(attr_type, nodes.SimpleType) and isinstance(attr_type.type, nodes.StringType)) or isinstance(
|
if (isinstance(attr_type, nodes.SimpleType) and isinstance(attr_type.type, nodes.StringType)) or isinstance(
|
||||||
@@ -168,7 +172,7 @@ class Mapping:
|
|||||||
type_str = "::%s::%s::Value" % (self.schema.name.capitalize(), attr_type)
|
type_str = "::%s::%s::Value" % (self.schema.name.capitalize(), attr_type)
|
||||||
elif isinstance(type_str, nodes.AggregationType):
|
elif isinstance(type_str, nodes.AggregationType):
|
||||||
is_nested_list = isinstance(attr_type.type, nodes.AggregationType)
|
is_nested_list = isinstance(attr_type.type, nodes.AggregationType)
|
||||||
ty = self.get_parameter_type(attr_type.type if is_nested_list else attr_type, False, allow_entities, False)
|
ty = self.get_parameter_type(attr_type.type if is_nested_list else attr_type)
|
||||||
if self.schema.is_select(attr_type.type):
|
if self.schema.is_select(attr_type.type):
|
||||||
type_str = templates.untyped_list
|
type_str = templates.untyped_list
|
||||||
elif self.schema.is_simpletype(ty) or str(ty) in self.express_to_cpp_typemapping.values():
|
elif self.schema.is_simpletype(ty) or str(ty) in self.express_to_cpp_typemapping.values():
|
||||||
@@ -179,14 +183,10 @@ class Mapping:
|
|||||||
tmpl = templates.list_list_type if is_nested_list else templates.list_type
|
tmpl = templates.list_list_type if is_nested_list else templates.list_type
|
||||||
type_str = tmpl % {"instance_type": ty}
|
type_str = tmpl % {"instance_type": ty}
|
||||||
elif self.schema.is_entity(type_str) or self.schema.is_select(type_str):
|
elif self.schema.is_entity(type_str) or self.schema.is_select(type_str):
|
||||||
type_str = "::%s::%s" % (self.schema.name.capitalize(), attr_type)
|
type_str = "::%s::%s*" % (self.schema.name.capitalize(), attr_type)
|
||||||
if allow_pointer:
|
|
||||||
type_str += "*"
|
|
||||||
is_ptr = True
|
|
||||||
elif not allow_pointer and self.schema.is_select(type_str):
|
|
||||||
type_str = "IfcUtil::IfcBaseClass*"
|
|
||||||
is_ptr = True
|
is_ptr = True
|
||||||
if allow_optional and attr.optional and not is_ptr:
|
if allow_optional and attr.optional and not is_ptr:
|
||||||
|
# pointers are still handled with nullptr for the time being
|
||||||
type_str = "boost::optional< %s >" % type_str
|
type_str = "boost::optional< %s >" % type_str
|
||||||
return type_str
|
return type_str
|
||||||
|
|
||||||
@@ -262,9 +262,9 @@ class Mapping:
|
|||||||
{
|
{
|
||||||
"index": i + 1,
|
"index": i + 1,
|
||||||
"name": attr.name,
|
"name": attr.name,
|
||||||
"full_type": self.get_parameter_type(attr, allow_optional=True, allow_entities=True),
|
"full_type": self.get_parameter_type(attr),
|
||||||
"specialized_type": self.get_parameter_type(attr, allow_optional=True, allow_entities=False),
|
"specialized_type": self.get_parameter_type(attr),
|
||||||
"non_optional_type": self.get_parameter_type(attr, allow_optional=False, allow_entities=False),
|
"non_optional_type": self.get_parameter_type(attr, allow_optional=False),
|
||||||
"list_instance_type": self.list_instance_type(attr),
|
"list_instance_type": self.list_instance_type(attr),
|
||||||
"is_optional": attr.optional,
|
"is_optional": attr.optional,
|
||||||
"is_inherited": i < num_inherited,
|
"is_inherited": i < num_inherited,
|
||||||
|
|||||||
@@ -239,9 +239,9 @@ parent_type_test = " || %s::is(v)"
|
|||||||
|
|
||||||
optional_attr_stmt = "return !data_->getArgument(%(index)d)->isNull();"
|
optional_attr_stmt = "return !data_->getArgument(%(index)d)->isNull();"
|
||||||
|
|
||||||
get_attr_stmt = "return *data_->getArgument(%(index)d);"
|
get_attr_stmt = "return (%(non_optional_type)s) *data_->getArgument(%(index)d);"
|
||||||
get_attr_stmt_enum = "return %(type)s::FromString(*data_->getArgument(%(index)d));"
|
get_attr_stmt_enum = "return %(non_optional_type)s::FromString(*data_->getArgument(%(index)d));"
|
||||||
get_attr_stmt_entity = "return (%(type)s)((IfcUtil::IfcBaseClass*)(*data_->getArgument(%(index)d)));"
|
get_attr_stmt_entity = "return (%(non_optional_type)s)((IfcUtil::IfcBaseClass*)(*data_->getArgument(%(index)d)));"
|
||||||
get_attr_stmt_array = (
|
get_attr_stmt_array = (
|
||||||
"IfcEntityList::ptr es = *data_->getArgument(%(index)d); return es->as< %(list_instance_type)s >();"
|
"IfcEntityList::ptr es = *data_->getArgument(%(index)d); return es->as< %(list_instance_type)s >();"
|
||||||
)
|
)
|
||||||
@@ -255,7 +255,7 @@ set_attr_stmt = (
|
|||||||
"{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(v"
|
"{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(v"
|
||||||
+ ");data_->setArgument(%(index)d,attr);}"
|
+ ");data_->setArgument(%(index)d,attr);}"
|
||||||
)
|
)
|
||||||
set_attr_stmt_enum = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(IfcWrite::IfcWriteArgument::EnumerationReference(v,%(type)s::ToString(v)));data_->setArgument(%(index)d,attr);}"
|
set_attr_stmt_enum = "{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(IfcWrite::IfcWriteArgument::EnumerationReference(%(star_if_optional)sv,%(non_optional_type)s::ToString(%(star_if_optional)sv)));data_->setArgument(%(index)d,attr);}"
|
||||||
set_attr_stmt_array = (
|
set_attr_stmt_array = (
|
||||||
"{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(v->generalize()"
|
"{IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument();attr->set(v->generalize()"
|
||||||
+ ");data_->setArgument(%(index)d,attr);}"
|
+ ");data_->setArgument(%(index)d,attr);}"
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/dynamic_bitset.hpp>
|
#include <boost/dynamic_bitset.hpp>
|
||||||
|
#include <boost/logic/tribool.hpp>
|
||||||
|
|
||||||
class Argument;
|
class Argument;
|
||||||
class IfcEntityList;
|
class IfcEntityList;
|
||||||
@@ -54,6 +55,7 @@ public:
|
|||||||
virtual operator int() const;
|
virtual operator int() const;
|
||||||
virtual operator bool() const;
|
virtual operator bool() const;
|
||||||
virtual operator double() const;
|
virtual operator double() const;
|
||||||
|
virtual operator boost::logic::tribool() const;
|
||||||
virtual operator std::string() const;
|
virtual operator std::string() const;
|
||||||
virtual operator boost::dynamic_bitset<>() const;
|
virtual operator boost::dynamic_bitset<>() const;
|
||||||
virtual operator IfcUtil::IfcBaseClass*() const;
|
virtual operator IfcUtil::IfcBaseClass*() const;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ namespace IfcUtil {
|
|||||||
Argument_DERIVED,
|
Argument_DERIVED,
|
||||||
Argument_INT,
|
Argument_INT,
|
||||||
Argument_BOOL,
|
Argument_BOOL,
|
||||||
|
Argument_LOGICAL,
|
||||||
Argument_DOUBLE,
|
Argument_DOUBLE,
|
||||||
Argument_STRING,
|
Argument_STRING,
|
||||||
Argument_BINARY,
|
Argument_BINARY,
|
||||||
|
|||||||
Reference in New Issue
Block a user