mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 10:06:47 +00:00
Work in progress on mapping templates
This commit is contained in:
@@ -28,7 +28,7 @@ class Mapping:
|
||||
|
||||
express_to_cpp_typemapping = {
|
||||
"boolean": "bool",
|
||||
"logical": "bool",
|
||||
"logical": "boost::logic::tribool",
|
||||
"integer": "int",
|
||||
"real": "double",
|
||||
"number": "double",
|
||||
@@ -40,6 +40,7 @@ class Mapping:
|
||||
[
|
||||
"INT",
|
||||
"BOOL",
|
||||
"LOGICAL",
|
||||
"DOUBLE",
|
||||
"STRING",
|
||||
"BINARY",
|
||||
@@ -141,7 +142,10 @@ class Mapping:
|
||||
raise ValueError("Unable to map type %r for attribute %r" % (type, 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:
|
||||
import pdb; pdb.set_trace()
|
||||
print("Attribute %r mapped as 'unknown'" % (attr), file=sys.stderr)
|
||||
ty = "UNKNOWN"
|
||||
return "IfcUtil::Argument_%s" % ty
|
||||
@@ -152,7 +156,7 @@ class Mapping:
|
||||
else:
|
||||
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)
|
||||
|
||||
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)
|
||||
elif isinstance(type_str, 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):
|
||||
type_str = templates.untyped_list
|
||||
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
|
||||
type_str = tmpl % {"instance_type": ty}
|
||||
elif self.schema.is_entity(type_str) or self.schema.is_select(type_str):
|
||||
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*"
|
||||
type_str = "::%s::%s*" % (self.schema.name.capitalize(), attr_type)
|
||||
is_ptr = True
|
||||
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
|
||||
return type_str
|
||||
|
||||
@@ -262,9 +262,9 @@ class Mapping:
|
||||
{
|
||||
"index": i + 1,
|
||||
"name": attr.name,
|
||||
"full_type": self.get_parameter_type(attr, allow_optional=True, allow_entities=True),
|
||||
"specialized_type": self.get_parameter_type(attr, allow_optional=True, allow_entities=False),
|
||||
"non_optional_type": self.get_parameter_type(attr, allow_optional=False, allow_entities=False),
|
||||
"full_type": self.get_parameter_type(attr),
|
||||
"specialized_type": self.get_parameter_type(attr),
|
||||
"non_optional_type": self.get_parameter_type(attr, allow_optional=False),
|
||||
"list_instance_type": self.list_instance_type(attr),
|
||||
"is_optional": attr.optional,
|
||||
"is_inherited": i < num_inherited,
|
||||
|
||||
Reference in New Issue
Block a user