forked from IfcOpenShell/IfcOpenShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfcUtil.h
More file actions
223 lines (199 loc) · 7.66 KB
/
IfcUtil.h
File metadata and controls
223 lines (199 loc) · 7.66 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCUTIL_H
#define IFCUTIL_H
#include <string>
#include <vector>
#include <sstream>
#include "../ifcparse/SharedPointer.h"
#ifdef USE_IFC4
#include "../ifcparse/Ifc4enum.h"
#else
#include "../ifcparse/Ifc2x3enum.h"
#endif
class IfcAbstractEntity;
//typedef SHARED_PTR<IfcAbstractEntity> IfcAbstractEntityPtr;
typedef IfcAbstractEntity* IfcAbstractEntityPtr;
class IfcEntityList;
typedef SHARED_PTR<IfcEntityList> IfcEntities;
class Argument;
//typedef SHARED_PTR<Argument> ArgumentPtr;
typedef Argument* ArgumentPtr;
template <class F, class T>
inline T* reinterpret_pointer_cast(F* from) {
return (T*)from;
//SHARED_PTR<void> v = std::tr1::static_pointer_cast<void,F>(from);
//return std::tr1::static_pointer_cast<T,void>(v);
}
namespace IfcUtil {
enum ArgumentType {
Argument_INT, Argument_BOOL, Argument_DOUBLE, Argument_STRING, Argument_VECTOR_INT, Argument_VECTOR_DOUBLE, Argument_VECTOR_STRING, Argument_ENTITY, Argument_ENTITY_LIST, Argument_ENTITY_LIST_LIST, Argument_ENUMERATION, Argument_DERIVED, Argument_UNKNOWN
};
}
namespace IfcUtil {
class IfcBaseClass {
public:
IfcAbstractEntityPtr entity;
virtual bool is(IfcSchema::Type::Enum v) const = 0;
virtual IfcSchema::Type::Enum type() const = 0;
};
class IfcBaseEntity : public IfcBaseClass {
public:
virtual unsigned int getArgumentCount() const = 0;
virtual ArgumentType getArgumentType(unsigned int i) const = 0;
virtual ArgumentPtr getArgument(unsigned int i) const = 0;
virtual const char* getArgumentName(unsigned int i) const = 0;
};
//typedef SHARED_PTR<IfcBaseClass> IfcSchemaEntity;
typedef IfcBaseClass* IfcSchemaEntity;
}
template <class T>
class IfcTemplatedEntityList;
class IfcEntityList {
std::vector<IfcUtil::IfcSchemaEntity> ls;
public:
typedef std::vector<IfcUtil::IfcSchemaEntity>::const_iterator it;
IfcEntities getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL);
IfcEntities getInverse(IfcSchema::Type::Enum c, int i, const std::string& a);
void push(IfcUtil::IfcSchemaEntity l);
void push(IfcEntities l);
it begin();
it end();
IfcUtil::IfcSchemaEntity operator[] (int i);
int Size() const;
template <class U>
typename U::list as() {
typename U::list r(new IfcTemplatedEntityList<U>());
for ( it i = begin(); i != end(); ++ i ) if ((*i)->is(U::Class())) r->push((U*)*i);
return r;
}
};
template <class T>
class IfcTemplatedEntityList {
std::vector<T*> ls;
public:
typedef typename std::vector<T*>::const_iterator it;
inline void push(T* t) {if (t) ls.push_back(t);}
inline void push(SHARED_PTR< IfcTemplatedEntityList<T> > t) { for ( typename T::it it = t->begin(); it != t->end(); ++it ) push(*it); }
inline it begin() { return ls.begin(); }
inline it end() { return ls.end(); }
inline unsigned int Size() const { return (unsigned int) ls.size(); }
IfcEntities generalize() {
IfcEntities r (new IfcEntityList());
for ( it i = begin(); i != end(); ++ i ) r->push(*i);
return r;
}
template <class U>
typename U::list as() {
typename U::list r(new IfcTemplatedEntityList<U>());
for ( it i = begin(); i != end(); ++ i ) if ((*i)->is(U::Class())) r->push(*i);
return r;
}
};
namespace IfcUtil {
class IfcAbstractSelect : public IfcBaseClass {
public:
typedef SHARED_PTR< IfcTemplatedEntityList<IfcAbstractSelect> > list;
typedef IfcTemplatedEntityList<IfcAbstractSelect>::it it;
typedef IfcAbstractSelect* ptr;
virtual bool isSimpleType() = 0;
};
class IfcEntitySelect : public IfcAbstractSelect {
public:
typedef IfcEntitySelect* ptr;
IfcEntitySelect(IfcSchemaEntity b);
IfcEntitySelect(IfcAbstractEntityPtr e);
~IfcEntitySelect();
bool is(IfcSchema::Type::Enum v) const;
IfcSchema::Type::Enum type() const;
bool isSimpleType();
};
class IfcArgumentSelect : public IfcAbstractSelect {
IfcSchema::Type::Enum _type;
ArgumentPtr arg;
public:
typedef IfcArgumentSelect* ptr;
IfcArgumentSelect(IfcSchema::Type::Enum t, ArgumentPtr a);
~IfcArgumentSelect();
ArgumentPtr wrappedValue();
bool is(IfcSchema::Type::Enum v) const;
IfcSchema::Type::Enum type() const;
bool isSimpleType();
};
}
namespace IfcParse {
class IfcFile;
}
class Argument {
public:
//void* file;
//public:
virtual operator int() const = 0;
virtual operator bool() const = 0;
virtual operator double() const = 0;
virtual operator std::string() const = 0;
virtual operator std::vector<double>() const = 0;
virtual operator std::vector<int>() const = 0;
virtual operator std::vector<std::string>() const = 0;
virtual operator IfcUtil::IfcSchemaEntity() const = 0;
//virtual operator IfcUtil::IfcAbstractSelect::ptr() const = 0;
virtual operator IfcEntities() const = 0;
virtual unsigned int Size() const = 0;
virtual ArgumentPtr operator [] (unsigned int i) const = 0;
virtual std::string toString(bool upper=false) const = 0;
virtual bool isNull() const = 0;
virtual ~Argument() {};
};
class IfcAbstractEntity {
public:
IfcParse::IfcFile* file;
virtual IfcEntities getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL) = 0;
virtual IfcEntities getInverse(IfcSchema::Type::Enum c, int i, const std::string& a) = 0;
virtual std::string datatype() = 0;
virtual ArgumentPtr getArgument (unsigned int i) = 0;
virtual unsigned int getArgumentCount() = 0;
virtual ~IfcAbstractEntity() {};
virtual IfcSchema::Type::Enum type() const = 0;
virtual bool is(IfcSchema::Type::Enum v) const = 0;
virtual std::string toString(bool upper=false) = 0;
virtual unsigned int id() = 0;
virtual bool isWritable() = 0;
};
class Logger {
public:
typedef enum { LOG_NOTICE, LOG_WARNING, LOG_ERROR } Severity;
private:
static std::ostream* log1;
static std::ostream* log2;
static std::stringstream log_stream;
static Severity verbosity;
static const char* severity_strings[];
public:
/// Determines to what stream respectively progress and errors are logged
static void SetOutput(std::ostream* l1, std::ostream* l2);
/// Determines the types of log messages to get logged
static void Verbosity(Severity v);
static Severity Verbosity();
/// Log a message to the output stream
static void Message(Severity type, const std::string& message, const IfcAbstractEntityPtr entity=0);
static void Status(const std::string& message, bool new_line=true);
static void ProgressBar(int progress);
static std::string GetLog();
};
#endif