forked from IfcOpenShell/IfcOpenShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfcSchema.cpp
More file actions
136 lines (117 loc) · 3.7 KB
/
IfcSchema.cpp
File metadata and controls
136 lines (117 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "IfcSchema.h"
#include "../ifcparse/IfcBaseClass.h"
#include <map>
bool IfcParse::declaration::is(const std::string& name) const {
if (name_lower_ == boost::to_lower_copy(name)) return true;
if (this->as_entity()) {
return this->as_entity()->is(name);
} else if (this->as_type_declaration()) {
const IfcParse::named_type* nt = this->as_type_declaration()->declared_type()->as_named_type();
if (nt) return nt->is(name);
}
return false;
}
bool IfcParse::declaration::is(const IfcParse::declaration& decl) const {
if (this == &decl) return true;
if (this->as_entity()) {
return this->as_entity()->is(decl);
} else if (this->as_type_declaration()) {
const IfcParse::named_type* nt = this->as_type_declaration()->declared_type()->as_named_type();
if (nt) return nt->is(decl);
}
return false;
}
bool IfcParse::named_type::is(const std::string& name) const {
return declared_type()->is(name);
}
bool IfcParse::named_type::is(const IfcParse::declaration& decl) const {
return declared_type()->is(decl);
}
static std::map<std::string, const IfcParse::schema_definition*> schemas;
IfcParse::schema_definition::schema_definition(const std::string& name, const std::vector<const declaration*>& declarations, instance_factory* factory)
: name_(name)
, declarations_(declarations)
, factory_(factory)
{
std::sort(declarations_.begin(), declarations_.end(), declaration_by_index_sort());
for (std::vector<const declaration*>::iterator it = declarations_.begin(); it != declarations_.end(); ++it) {
(**it).schema_ = this;
if ((**it).as_type_declaration()) type_declarations_.push_back((**it).as_type_declaration());
if ((**it).as_select_type()) select_types_.push_back((**it).as_select_type());
if ((**it).as_enumeration_type()) enumeration_types_.push_back((**it).as_enumeration_type());
if ((**it).as_entity()) entities_.push_back((**it).as_entity());
}
schemas[name_] = this;
}
IfcParse::schema_definition::~schema_definition() {
schemas.erase(name_);
for (std::vector<const declaration*>::const_iterator it = declarations_.begin(); it != declarations_.end(); ++it) {
delete *it;
}
}
IfcUtil::IfcBaseClass* IfcParse::schema_definition::instantiate(IfcEntityInstanceData * data) const {
if (factory_) {
return (*factory_)(data);
} else {
return new IfcUtil::IfcLateBoundEntity(data->type(), data);
}
}
void IfcParse::register_schema(schema_definition* s) {
schemas.insert({ s->name(), s });
}
#ifdef HAS_SCHEMA_2x3
#include "../ifcparse/Ifc2x3.h"
#endif
#ifdef HAS_SCHEMA_4
#include "../ifcparse/Ifc4.h"
#endif
#ifdef HAS_SCHEMA_4x1
#include "../ifcparse/Ifc4x1.h"
#endif
#ifdef HAS_SCHEMA_4x2
#include "../ifcparse/Ifc4x2.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc1
#include "../ifcparse/Ifc4x3_rc1.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc2
#include "../ifcparse/Ifc4x3_rc2.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc3
#include "../ifcparse/Ifc4x3_rc3.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc4
#include "../ifcparse/Ifc4x3_rc4.h"
#endif
const IfcParse::schema_definition* IfcParse::schema_by_name(const std::string& name) {
// TODO: initialize automatically somehow
#ifdef HAS_SCHEMA_2x3
Ifc2x3::get_schema();
#endif
#ifdef HAS_SCHEMA_4
Ifc4::get_schema();
#endif
#ifdef HAS_SCHEMA_4x1
Ifc4x1::get_schema();
#endif
#ifdef HAS_SCHEMA_4x2
Ifc4x2::get_schema();
#endif
#ifdef HAS_SCHEMA_4x3_rc1
Ifc4x3_rc1::get_schema();
#endif
#ifdef HAS_SCHEMA_4x3_rc2
Ifc4x3_rc2::get_schema();
#endif
#ifdef HAS_SCHEMA_4x3_rc3
Ifc4x3_rc3::get_schema();
#endif
#ifdef HAS_SCHEMA_4x3_rc4
Ifc4x3_rc4::get_schema();
#endif
std::map<std::string, const IfcParse::schema_definition*>::const_iterator it = schemas.find(boost::to_upper_copy(name));
if (it == schemas.end()) {
throw IfcParse::IfcException("No schema named " + name);
}
return it->second;
}