forked from IfcOpenShell/IfcOpenShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfcParse.h
More file actions
236 lines (213 loc) · 8.42 KB
/
IfcParse.h
File metadata and controls
236 lines (213 loc) · 8.42 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
224
225
226
227
228
229
230
231
232
233
234
235
236
/********************************************************************************
* *
* 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 provides functions for loading an IFC file into memory and access *
* its entities either by ID, by an IfcSchema::Type or by reference *
* *
********************************************************************************/
#ifndef IFCPARSE_H
#define IFCPARSE_H
#define IFCOPENSHELL_VERSION "0.5.0-dev"
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <fstream>
#include <cstring>
#include <map>
#include "../ifcparse/SharedPointer.h"
#include "../ifcparse/IfcCharacterDecoder.h"
#include "../ifcparse/IfcUtil.h"
#include "../ifcparse/IfcUntypedEntity.h"
#ifdef USE_IFC4
#include "../ifcparse/Ifc4.h"
#else
#include "../ifcparse/Ifc2x3.h"
#endif
#include "../ifcparse/IfcSpfStream.h"
namespace IfcParse {
class Entity;
class Entities;
class IfcFile;
typedef Entity* EntityPtr;
typedef SHARED_PTR<Entities> EntitiesPtr;
class Tokens;
typedef std::pair<Tokens*,unsigned> Token;
/// Provides functions to convert Tokens to binary data
/// Tokens are merely offsets to where they can be read in the file
class TokenFunc {
private:
static bool startsWith(const Token& t, char c);
public:
/// Returns the offset at which the token is read from the file
// static unsigned int Offset(const Token& t);
/// Returns whether the token can be interpreted as a string
static bool isString(const Token& t);
/// Returns whether the token can be interpreted as an identifier
static bool isIdentifier(const Token& t);
/// Returns whether the token can be interpreted as an syntactical operator
static bool isOperator(const Token& t, char op = 0);
/// Returns whether the token can be interpreted as an enumerated value
static bool isEnumeration(const Token& t);
/// Returns whether the token can be interpreted as an datatype name
static bool isDatatype(const Token& t);
/// Returns the token interpreted as an integer
static int asInt(const Token& t);
/// Returns the token interpreted as an boolean (.T. or .F.)
static bool asBool(const Token& t);
/// Returns the token as a floating point number
static double asFloat(const Token& t);
/// Returns the token as a string (without the dot or apostrophe)
static std::string asString(const Token& t);
/// Returns a string representation of the token (including the dot or apostrophe)
static std::string toString(const Token& t);
};
//
// Functions for creating Tokens from an arbitary file offset
// The first 4 bits are reserved for Tokens of type ()=,;$*
//
Token TokenPtr(Tokens* tokens, unsigned int offset);
Token TokenPtr(char c);
Token TokenPtr();
/// A stream of tokens to be read from a IfcSpfStream.
class Tokens {
private:
IfcCharacterDecoder* decoder;
unsigned int skipWhitespace();
unsigned int skipComment();
public:
IfcSpfStream* stream;
IfcFile* file;
Tokens(IfcSpfStream* s, IfcFile* f);
Token Next();
~Tokens();
std::string TokenString(unsigned int offset);
};
/// Argument of type list, e.g.
/// #1=IfcDirection((1.,0.,0.));
/// ==========
class ArgumentList: public Argument {
private:
std::vector<ArgumentPtr> list;
void Push(ArgumentPtr l);
public:
ArgumentList(Tokens* t, std::vector<unsigned int>& ids);
~ArgumentList();
operator int() const;
operator bool() const;
operator double() const;
operator std::string() const;
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator IfcUtil::IfcSchemaEntity() const;
//operator IfcUtil::IfcAbstractSelect::ptr() const;
operator IfcEntities() const;
unsigned int Size() const;
ArgumentPtr operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
bool isNull() const;
};
/// Argument of type scalar or string, e.g.
/// #1=IfcVector(#2,1.0);
/// == ===
class TokenArgument : public Argument {
private:
public:
Token token;
TokenArgument(const Token& t);
operator int() const;
operator bool() const;
operator double() const;
operator std::string() const;
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator IfcUtil::IfcSchemaEntity() const;
//operator IfcUtil::IfcAbstractSelect::ptr() const;
operator IfcEntities() const;
unsigned int Size() const;
ArgumentPtr operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
bool isNull() const;
};
/// Argument of an IFC simple type
/// #1=IfcTrimmedCurve(#2,(IFCPARAMETERVALUE(0.)),(IFCPARAMETERVALUE(1.)),.T.,.PARAMETER.);
/// ===================== =====================
class EntityArgument : public Argument {
private:
IfcUntypedEntity* entity;
public:
EntityArgument(IfcSchema::Type::Enum ty, const Token& t);
~EntityArgument();
operator int() const;
operator bool() const;
operator double() const;
operator std::string() const;
operator std::vector<double>() const;
operator std::vector<int>() const;
operator std::vector<std::string>() const;
operator IfcUtil::IfcSchemaEntity() const;
//operator IfcUtil::IfcAbstractSelect::ptr() const;
operator IfcEntities() const;
unsigned int Size() const;
ArgumentPtr operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
bool isNull() const;
};
/// Entity defined in an IFC file, e.g.
/// #1=IfcDirection((1.,0.,0.));
/// ============================
class Entity : public IfcAbstractEntity {
private:
//IfcFile* file;
ArgumentPtr args;
IfcSchema::Type::Enum _type;
public:
/// The EXPRESS ENTITY_INSTANCE_NAME
unsigned int _id;
/// The offset at which the entity is read
unsigned int offset;
Entity(unsigned int i, IfcFile* t);
Entity(unsigned int i, IfcFile* t, unsigned int o);
~Entity();
IfcEntities getInverse(IfcSchema::Type::Enum c = IfcSchema::Type::ALL);
IfcEntities getInverse(IfcSchema::Type::Enum c, int i, const std::string& a);
void Load(std::vector<unsigned int>& ids, bool seek=false);
ArgumentPtr getArgument (unsigned int i);
unsigned int getArgumentCount();
std::string toString(bool upper=false);
std::string datatype();
IfcSchema::Type::Enum type() const;
bool is(IfcSchema::Type::Enum v) const;
unsigned int id();
bool isWritable();
};
typedef IfcUtil::IfcSchemaEntity IfcEntity;
//typedef IfcEntities IfcEntities;
typedef std::map<IfcSchema::Type::Enum,IfcEntities> MapEntitiesByType;
typedef std::map<unsigned int,IfcEntity> MapEntityById;
typedef std::map<std::string,IfcSchema::IfcRoot::ptr> MapEntityByGuid;
typedef std::map<unsigned int,IfcEntities> MapEntitiesByRef;
typedef std::map<unsigned int,unsigned int> MapOffsetById;
double UnitPrefixToValue( IfcSchema::IfcSIPrefix::IfcSIPrefix v );
}
std::ostream& operator<< (std::ostream& os, const IfcParse::IfcFile& f);
#endif