Remove limited latebound schema representation in favour of full runtime schema representation

This commit is contained in:
Thomas Krijnen
2017-12-11 15:46:57 +01:00
parent 322dec6fd0
commit e7ccf7269a
12 changed files with 80 additions and 9637 deletions
+1 -2
View File
@@ -428,9 +428,8 @@ function(files_for_ifc_version IFC_VERSION RESULT_NAME)
set(${RESULT_NAME}
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}.h
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}enum.h
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}-latebound.h
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}.cpp
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}-latebound.cpp
${IFC_PARSE_DIR}/Ifc${IFC_VERSION}-schema.cpp
PARENT_SCOPE
)
endfunction()
-4
View File
@@ -199,15 +199,11 @@ else:
import header
import enum_header
import implementation
import latebound_header
import latebound_implementation
import schema_class
header.Header(mapping).emit()
enum_header.EnumHeader(mapping).emit()
implementation.Implementation(mapping).emit()
latebound_header.LateBoundHeader(mapping).emit()
latebound_implementation.LateBoundImplementation(mapping).emit()
schema_class.SchemaClass(mapping).emit()
sys.stdout.write(schema.name)
-36
View File
@@ -1,36 +0,0 @@
###############################################################################
# #
# This file is part of IfcOpenShell. #
# #
# IfcOpenShell is free software: you can redistribute it and/or modify #
# it under the terms of the Lesser GNU General Public License as published by #
# the Free Software Foundation, either version 3.0 of the License, or #
# (at your option) any later version. #
# #
# IfcOpenShell is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# Lesser GNU General Public License for more details. #
# #
# You should have received a copy of the Lesser GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
import codegen
import templates
class LateBoundHeader(codegen.Base):
def __init__(self, mapping):
self.str = templates.lb_header % {
'schema_name_upper' : mapping.schema.name.upper(),
'schema_name' : mapping.schema.name.capitalize()
}
self.schema_name = mapping.schema.name.capitalize()
self.file_name = '%s-latebound.h'%self.schema_name
def __repr__(self):
return self.str
@@ -1,119 +0,0 @@
###############################################################################
# #
# This file is part of IfcOpenShell. #
# #
# IfcOpenShell is free software: you can redistribute it and/or modify #
# it under the terms of the Lesser GNU General Public License as published by #
# the Free Software Foundation, either version 3.0 of the License, or #
# (at your option) any later version. #
# #
# IfcOpenShell is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# Lesser GNU General Public License for more details. #
# #
# You should have received a copy of the Lesser GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
import codegen
import templates
class LateBoundImplementation(codegen.Base):
def __init__(self, mapping):
schema_name = mapping.schema.name.capitalize()
entity_descriptors = []
enumeration_descriptors = []
derived_field_statements = []
inverse_implementations = []
for name, type in mapping.schema.simpletypes.items():
entity_descriptors.append(templates.entity_descriptor % {
'type' : name,
'parent_statement' : '0',
'entity_descriptor_attributes' : templates.entity_descriptor_attribute_without_entity % {
'name' : 'wrappedValue',
'optional' : 'false',
'type' : mapping.make_argument_type(mapping.schema.types[name].type)
}
})
emitted_entities = set()
while len(emitted_entities) < len(mapping.schema.entities):
for name, type in mapping.schema.entities.items():
if name.lower() in emitted_entities: continue
if len(type.supertypes) == 0 or set(map(str.lower, type.supertypes)) <= emitted_entities:
constructor_arguments = mapping.get_assignable_arguments(type, include_derived = True)
entity_descriptor_attributes = []
for arg in constructor_arguments:
if not arg['is_inherited']:
is_enumeration = arg['argument_type_enum'] == 'IfcUtil::Argument_ENUMERATION'
tmpl = templates.entity_descriptor_attribute_with_entity
entity_name = arg['argument_type'] if is_enumeration else arg['argument_entity'].split('::')[1]
entity_descriptor_attributes.append(tmpl % {
'name' : arg['name'],
'optional' : 'true' if arg['is_optional'] else 'false',
'type' : arg['argument_type_enum'],
'entity_name': entity_name
})
emitted_entities.add(name)
parent_statement = '0' if len(type.supertypes) != 1 else templates.entity_descriptor_parent % {
'type' : [k for k in mapping.schema.entities.keys() if k.lower() == type.supertypes[0].lower()][0]
}
entity_descriptors.append(templates.entity_descriptor % {
'type' : name,
'parent_statement' : parent_statement,
'entity_descriptor_attributes' : '\n'.join(entity_descriptor_attributes)
})
for name, enum in mapping.schema.enumerations.items():
enumeration_descriptor_values = '\n'.join([templates.enumeration_descriptor_value % {
'name' : v
} for v in enum.values])
enumeration_descriptors.append(templates.enumeration_descriptor % {
'type' : name,
'enumeration_descriptor_values' : enumeration_descriptor_values
})
for name, type in mapping.schema.entities.items():
constructor_arguments = mapping.get_assignable_arguments(type, include_derived = True)
statements = ''.join(templates.derived_field_statement_attrs % (a['index']-1) for a in constructor_arguments if a['is_derived'])
if len(statements):
derived_field_statements.append(templates.derived_field_statement % {
'type' : name,
'statements' : statements
})
for name, type in mapping.schema.entities.items():
if type.inverse:
for attr in type.inverse.elements:
related_entity = mapping.schema.entities[attr.entity]
related_attrs = [a['name'].lower() for a in mapping.get_assignable_arguments(related_entity, include_derived=True)]
inverse_implementations.append(templates.inverse_implementation % {
'type' : name,
'name' : attr.name,
'related_type' : attr.entity,
'index' : related_attrs.index(attr.attribute.lower())
})
self.str = templates.lb_implementation % {
'schema_name_upper' : mapping.schema.name.upper(),
'schema_name' : mapping.schema.name.capitalize(),
'entity_descriptors' : '\n'.join(entity_descriptors),
'enumeration_descriptors' : '\n'.join(enumeration_descriptors),
'derived_field_statements' : '\n'.join(derived_field_statements),
'inverse_implementations' : '\n'.join(inverse_implementations)
}
self.schema_name = mapping.schema.name.capitalize()
self.file_name = '%s-latebound.cpp'%self.schema_name
def __repr__(self):
return self.str
+4
View File
@@ -17,6 +17,8 @@
* *
********************************************************************************/
#include "../ifcparse/IfcSchema.h"
#ifndef ARGUMENTTYPE_H
#define ARGUMENTTYPE_H
@@ -48,6 +50,8 @@ namespace IfcUtil {
Argument_UNKNOWN
};
ArgumentType from_parameter_type(const IfcParse::parameter_type*);
ArgumentType make_aggregate(ArgumentType elem_type);
}
#endif
File diff suppressed because it is too large Load Diff
-51
View File
@@ -1,51 +0,0 @@
/********************************************************************************
* *
* This file is part of IfcOpenShell. *
* *
* IfcOpenShell is free software: you can redistribute it and/or modify *
* it under the terms of the Lesser GNU General Public License as published by *
* the Free Software Foundation, either version 3.0 of the License, or *
* (at your option) any later version. *
* *
* IfcOpenShell is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* Lesser GNU General Public License for more details. *
* *
* You should have received a copy of the Lesser GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
/********************************************************************************
* *
* This file has been generated from IFC2X3_TC1.exp. Do not make modifications *
* but instead modify the python script that has been used to generate this. *
* *
********************************************************************************/
#ifndef IFC2X3RT_H
#define IFC2X3RT_H
#define IfcSchema Ifc2x3
#include "../ifcparse/ifc_parse_api.h"
#include "../ifcparse/IfcBaseClass.h"
#include "../ifcparse/IfcEntityDescriptor.h"
namespace Ifc2x3 {
namespace Type {
IFC_PARSE_API int GetAttributeCount(Enum t);
IFC_PARSE_API int GetAttributeIndex(Enum t, const std::string& a);
IFC_PARSE_API IfcUtil::ArgumentType GetAttributeType(Enum t, unsigned char a);
IFC_PARSE_API Enum GetAttributeEntity(Enum t, unsigned char a);
IFC_PARSE_API const std::string& GetAttributeName(Enum t, unsigned char a);
IFC_PARSE_API bool GetAttributeOptional(Enum t, unsigned char a);
IFC_PARSE_API bool GetAttributeDerived(Enum t, unsigned char a);
IFC_PARSE_API std::pair<const char*, int> GetEnumerationIndex(Enum t, const std::string& a);
IFC_PARSE_API std::pair<Enum, unsigned> GetInverseAttribute(Enum t, const std::string& a);
IFC_PARSE_API std::set<std::string> GetInverseAttributeNames(Enum t);
IFC_PARSE_API void PopulateDerivedFields(IfcEntityInstanceData* e);
}}
#endif
File diff suppressed because it is too large Load Diff
-51
View File
@@ -1,51 +0,0 @@
/********************************************************************************
* *
* This file is part of IfcOpenShell. *
* *
* IfcOpenShell is free software: you can redistribute it and/or modify *
* it under the terms of the Lesser GNU General Public License as published by *
* the Free Software Foundation, either version 3.0 of the License, or *
* (at your option) any later version. *
* *
* IfcOpenShell is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* Lesser GNU General Public License for more details. *
* *
* You should have received a copy of the Lesser GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
/********************************************************************************
* *
* This file has been generated from IFC4.exp. Do not make modifications *
* but instead modify the python script that has been used to generate this. *
* *
********************************************************************************/
#ifndef IFC4RT_H
#define IFC4RT_H
#define IfcSchema Ifc4
#include "../ifcparse/ifc_parse_api.h"
#include "../ifcparse/IfcBaseClass.h"
#include "../ifcparse/IfcEntityDescriptor.h"
namespace Ifc4 {
namespace Type {
IFC_PARSE_API int GetAttributeCount(Enum t);
IFC_PARSE_API int GetAttributeIndex(Enum t, const std::string& a);
IFC_PARSE_API IfcUtil::ArgumentType GetAttributeType(Enum t, unsigned char a);
IFC_PARSE_API Enum GetAttributeEntity(Enum t, unsigned char a);
IFC_PARSE_API const std::string& GetAttributeName(Enum t, unsigned char a);
IFC_PARSE_API bool GetAttributeOptional(Enum t, unsigned char a);
IFC_PARSE_API bool GetAttributeDerived(Enum t, unsigned char a);
IFC_PARSE_API std::pair<const char*, int> GetEnumerationIndex(Enum t, const std::string& a);
IFC_PARSE_API std::pair<Enum, unsigned> GetInverseAttribute(Enum t, const std::string& a);
IFC_PARSE_API std::set<std::string> GetInverseAttributeNames(Enum t);
IFC_PARSE_API void PopulateDerivedFields(IfcEntityInstanceData* e);
}}
#endif
+10 -31
View File
@@ -41,12 +41,6 @@
#include "../ifcparse/IfcSIPrefix.h"
#include "../ifcparse/IfcSchema.h"
#ifdef USE_IFC4
#include "../ifcparse/Ifc4-latebound.h"
#else
#include "../ifcparse/Ifc2x3-latebound.h"
#endif
#ifdef USE_MMAP
#include <boost/filesystem/path.hpp>
#endif
@@ -651,27 +645,7 @@ IfcUtil::ArgumentType ArgumentList::type() const {
}
const IfcUtil::ArgumentType elem_type = list[0]->type();
if (elem_type == IfcUtil::Argument_INT) {
return IfcUtil::Argument_AGGREGATE_OF_INT;
} else if (elem_type == IfcUtil::Argument_DOUBLE) {
return IfcUtil::Argument_AGGREGATE_OF_DOUBLE;
} else if (elem_type == IfcUtil::Argument_STRING) {
return IfcUtil::Argument_AGGREGATE_OF_STRING;
} else if (elem_type == IfcUtil::Argument_BINARY) {
return IfcUtil::Argument_AGGREGATE_OF_BINARY;
} else if (elem_type == IfcUtil::Argument_ENTITY_INSTANCE) {
return IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE;
} else if (elem_type == IfcUtil::Argument_AGGREGATE_OF_INT) {
return IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_INT;
} else if (elem_type == IfcUtil::Argument_AGGREGATE_OF_DOUBLE) {
return IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_DOUBLE;
} else if (elem_type == IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE) {
return IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE;
} else if (elem_type == IfcUtil::Argument_EMPTY_AGGREGATE) {
return IfcUtil::Argument_AGGREGATE_OF_EMPTY_AGGREGATE;
} else {
return IfcUtil::Argument_UNKNOWN;
}
return IfcUtil::make_aggregate(elem_type);
}
void ArgumentList::push(Argument* l) {
@@ -1147,12 +1121,17 @@ void IfcEntityInstanceData::setArgument(unsigned int i, Argument* a, IfcUtil::Ar
copy->set(attr_value);
break; }
case IfcUtil::Argument_ENUMERATION: {
IfcSchema::Type::Enum ty = IfcSchema::Type::GetAttributeEntity(type_, (unsigned char)i);
std::string enum_literal = a->toString();
// Remove leading and trailing '.'
enum_literal = enum_literal.substr(1, enum_literal.size() - 2);
std::pair<const char*, int> enum_ref = IfcSchema::Type::GetEnumerationIndex(ty, enum_literal);
copy->set(IfcWrite::IfcWriteArgument::EnumerationReference(enum_ref.second, enum_ref.first));
const IfcParse::enumeration_type* enum_type = get_schema().declaration_by_name(type())->as_entity()->all_attributes()[i]->type_of_attribute()->as_named_type()->declared_type()->as_enumeration_type();
std::vector<std::string>::const_iterator it = std::find(enum_type->enumeration_items().begin(), enum_type->enumeration_items().end(), enum_literal);
if (it == enum_type->enumeration_items().end()) {
throw IfcParse::IfcException(enum_literal + " does not name a valid item for " + enum_type->name());
}
copy->set(IfcWrite::IfcWriteArgument::EnumerationReference(it - enum_type->enumeration_items().begin(), it->c_str()));
break; }
case IfcUtil::Argument_ENTITY_INSTANCE: {
copy->set(static_cast<IfcUtil::IfcBaseClass*>(*a));
@@ -1187,7 +1166,7 @@ void IfcEntityInstanceData::setArgument(unsigned int i, Argument* a, IfcUtil::Ar
break; }
case IfcUtil::Argument_EMPTY_AGGREGATE:
case IfcUtil::Argument_AGGREGATE_OF_EMPTY_AGGREGATE: {
IfcUtil::ArgumentType t2 = IfcSchema::Type::GetAttributeType(type(), (unsigned char)i);
IfcUtil::ArgumentType t2 = IfcUtil::from_parameter_type(get_schema().declaration_by_name(type())->as_entity()->all_attributes()[i]->type_of_attribute());
delete copy;
copy = 0;
setArgument(i, a, t2);
+65 -6
View File
@@ -22,12 +22,6 @@
#include "../ifcparse/IfcException.h"
#include "../ifcparse/IfcEntityList.h"
#ifdef USE_IFC4
#include "../ifcparse/Ifc4-latebound.h"
#else
#include "../ifcparse/Ifc2x3-latebound.h"
#endif
#include <boost/algorithm/string/replace.hpp>
#include <boost/optional.hpp>
@@ -179,3 +173,68 @@ void IfcUtil::IfcBaseClass::data(IfcEntityInstanceData* d) {
delete data_;
data_ = d;
}
IfcUtil::ArgumentType IfcUtil::make_aggregate(IfcUtil::ArgumentType elem_type) {
if (elem_type == IfcUtil::Argument_INT) {
return IfcUtil::Argument_AGGREGATE_OF_INT;
} else if (elem_type == IfcUtil::Argument_DOUBLE) {
return IfcUtil::Argument_AGGREGATE_OF_DOUBLE;
} else if (elem_type == IfcUtil::Argument_STRING) {
return IfcUtil::Argument_AGGREGATE_OF_STRING;
} else if (elem_type == IfcUtil::Argument_BINARY) {
return IfcUtil::Argument_AGGREGATE_OF_BINARY;
} else if (elem_type == IfcUtil::Argument_ENTITY_INSTANCE) {
return IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE;
} else if (elem_type == IfcUtil::Argument_AGGREGATE_OF_INT) {
return IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_INT;
} else if (elem_type == IfcUtil::Argument_AGGREGATE_OF_DOUBLE) {
return IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_DOUBLE;
} else if (elem_type == IfcUtil::Argument_AGGREGATE_OF_ENTITY_INSTANCE) {
return IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE;
} else if (elem_type == IfcUtil::Argument_EMPTY_AGGREGATE) {
return IfcUtil::Argument_AGGREGATE_OF_EMPTY_AGGREGATE;
} else {
return IfcUtil::Argument_UNKNOWN;
}
}
IfcUtil::ArgumentType IfcUtil::from_parameter_type(const IfcParse::parameter_type* pt) {
// TODO: How to detect derived types here without a reference to the refering entity?
const IfcParse::aggregation_type* at = pt->as_aggregation_type();
const IfcParse::named_type* nt = pt->as_named_type();
const IfcParse::simple_type* st = pt->as_simple_type();
if (at) {
return make_aggregate(from_parameter_type(at->type_of_element()));
} else if (nt) {
if (nt->declared_type()->as_entity()) {
return IfcUtil::Argument_ENTITY_INSTANCE;
} else if (nt->declared_type()->as_enumeration_type()) {
return IfcUtil::Argument_ENUMERATION;
} else if (nt->declared_type()->as_select_type()) {
return IfcUtil::Argument_ENTITY_INSTANCE;
} else if (nt->declared_type()->as_type_declaration()) {
return from_parameter_type(nt->declared_type()->as_type_declaration()->declared_type());
}
} else if (st) {
switch (st->declared_type()) {
case IfcParse::simple_type::binary_type:
return IfcUtil::Argument_BINARY;
case IfcParse::simple_type::boolean_type:
return IfcUtil::Argument_BOOL;
case IfcParse::simple_type::integer_type:
return IfcUtil::Argument_INT;
case IfcParse::simple_type::logical_type:
return IfcUtil::Argument_BOOL;
case IfcParse::simple_type::number_type:
return IfcUtil::Argument_DOUBLE;
case IfcParse::simple_type::real_type:
return IfcUtil::Argument_DOUBLE;
case IfcParse::simple_type::string_type:
return IfcUtil::Argument_STRING;
}
}
return IfcUtil::Argument_UNKNOWN;
}
-6
View File
@@ -28,12 +28,6 @@
#include "../ifcparse/IfcCharacterDecoder.h"
#include "../ifcparse/IfcFile.h"
#ifdef USE_IFC4
#include "../ifcparse/Ifc4-latebound.h"
#else
#include "../ifcparse/Ifc2x3-latebound.h"
#endif
using namespace IfcWrite;
class SizeVisitor : public boost::static_visitor<int> {