forked from IfcOpenShell/IfcOpenShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfcWrite.h
More file actions
198 lines (186 loc) · 7.55 KB
/
IfcWrite.h
File metadata and controls
198 lines (186 loc) · 7.55 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
/********************************************************************************
* *
* 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 namespace provides implementations of Argument and Entity that use STL *
* containers for their datatypes and are not just lazy references to the *
* IFC-SPF file. Therefore they can be modified by the client application. *
* *
********************************************************************************/
#ifndef IFCWRITE_H
#define IFCWRITE_H
#include <boost/variant.hpp>
#include <boost/optional.hpp>
#include "../ifcparse/IfcUtil.h"
#include "../ifcparse/IfcParse.h"
#include "../ifcparse/IfcException.h"
namespace IfcWrite {
/// This class is a writable container for attributes. A fundamental
/// difference with the attribute types counterparts defined in the
/// IfcParse namespace is that this class has a Boost.Variant member
/// for storing its value, whereas the IfcParse classes only contain
/// lazy references to byte offsets in the IFC-SPF file.
class IfcWriteArgument : public Argument {
public:
class EnumerationReference {
public:
int data;
const char* enumeration_value;
EnumerationReference(int data, const char* enumeration_value)
: data(data), enumeration_value(enumeration_value) {}
};
class Derived {};
private:
IfcAbstractEntity* entity;
boost::variant<
// A null argument, it will always serialize to $
boost::none_t,
// A derived argument, it will always serialize to *
Derived,
// An integer argument, e.g. 123
int,
// A boolean argument, it will serialize to either .T. or .F.
bool,
// A floating point argument, e.g. 12.3
double,
// A character string argument, e.g. 'IfcOpenShell'
std::string,
// A list of integers, e.g. (1,2,3)
std::vector<int>,
// A list of floats, e.g. (12.3,4.)
std::vector<double>,
// A list of strings, e.g. ('Ifc','Open','Shell')
std::vector<std::string>,
// An enumeration argument, e.g. .USERDEFINED.
// To initialize the argument a string representation
// has to be explicitely passed of the enumeration value
// which is stored internally as an integer. The argument
// itself does not keep track of what schema enumeration
// type is represented.
EnumerationReference,
// An entity instance argument. It will either serialize to
// e.g. #123 or datatype identifier for simple types, e.g.
// IFCREAL(12.3)
IfcUtil::IfcSchemaEntity,
// An entity list argument. It will either serialize to
// e.g. (#1,#2,#3) or datatype identifier for simple types,
// e.g. (IFCREAL(1.2),IFCINTEGER(3.))
IfcEntities
> container;
public:
enum argument_type {
argument_type_null,
argument_type_derived,
argument_type_int,
argument_type_bool,
argument_type_double,
argument_type_string,
argument_type_vector_int,
argument_type_vector_double,
argument_type_vector_string,
argument_type_enumeration,
argument_type_schema_entity,
argument_type_entities
};
IfcWriteArgument(IfcAbstractEntity* e) : entity(e) {}
template <typename T> const T& as() const {
if (const T* val = boost::get<T>(&container)) {
return *val;
} else {
throw IfcParse::IfcException("Invalid cast");
}
}
template <typename T> void set(const T& t) {
container = 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 IfcEntities() const;
bool isNull() const;
ArgumentPtr operator [] (unsigned int i) const;
std::string toString(bool upper=false) const;
unsigned int Size() const;
argument_type argumentType() const;
};
/// An entity to help with passing of SELECT arguments that
/// consist of simple types, for example useful to initialize
/// a new IfcProperty.
/// Proper memory management is difficult for now, so beware.
class IfcSelectHelperEntity : public IfcAbstractEntity {
private:
IfcSchema::Type::Enum _type;
IfcWriteArgument* arg;
public:
// FIXME: Make this a non-pointer argument and implement a copy constructor
IfcSelectHelperEntity(IfcSchema::Type::Enum t, IfcWriteArgument* a) : _type(t), arg(a) {}
IfcEntities getInverse(IfcSchema::Type::Enum,int,const std::string &);
IfcEntities getInverse(IfcSchema::Type::Enum);
std::string datatype();
ArgumentPtr getArgument(unsigned int i);
unsigned int getArgumentCount();
IfcSchema::Type::Enum type() const;
bool is(IfcSchema::Type::Enum t) const;
std::string toString(bool upper = false);
unsigned int id();
bool isWritable();
};
/// A helper class for passing of SELECT arguments that
/// consist of simple types, for example useful to initialize
/// a new IfcProperty.
/// Proper memory management is difficult for now, so beware.
class IfcSelectHelper : public IfcUtil::IfcBaseClass {
public:
IfcSelectHelper(const std::string& v, IfcSchema::Type::Enum t=IfcSchema::Type::IfcText);
IfcSelectHelper(const char* const v, IfcSchema::Type::Enum t=IfcSchema::Type::IfcText);
IfcSelectHelper(int v, IfcSchema::Type::Enum t=IfcSchema::Type::IfcInteger);
IfcSelectHelper(double v, IfcSchema::Type::Enum t=IfcSchema::Type::IfcReal);
IfcSelectHelper(bool v, IfcSchema::Type::Enum t=IfcSchema::Type::IfcBoolean);
bool is(IfcSchema::Type::Enum t) const;
IfcSchema::Type::Enum type() const;
};
/// A helper class for the creation of IFC GlobalIds.
class IfcGuidHelper {
private:
std::string data;
static bool seeded;
public:
static const unsigned int length = 22;
IfcGuidHelper();
operator std::string() const;
};
// Accumulates all schema instances created from constructors
// This way they can be added in a single batch to the IfcFile
class EntityBuffer {
private:
IfcEntities buffer;
static EntityBuffer* i;
static EntityBuffer* instance();
public:
static IfcEntities Get();
static void Clear();
static void Add(IfcUtil::IfcSchemaEntity e);
};
}
#endif