Skip to content

Commit d80bcd1

Browse files
authored
Unify variant storage (#5118)
1 parent e2001e8 commit d80bcd1

File tree

107 files changed

+118419
-142785
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+118419
-142785
lines changed

src/examples/IfcParseExamples.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "../ifcparse/IfcFile.h"
2424
#include "../ifcparse/IfcLogger.h"
25+
#include "../ifcparse/Ifc2x3.h"
2526

2627
#include <boost/preprocessor/stringize.hpp>
2728
#include <boost/preprocessor/seq/for_each.hpp>
@@ -79,31 +80,31 @@ struct is_ifc4_or_higher<T, std::void_t<decltype(T::IfcMaterialDefinition)>> : s
7980

8081
typedef std::map<std::string, std::map<std::string, std::string>> element_properties;
8182

82-
std::string format_string(const Argument* argument) {
83+
std::string format_string(const AttributeValue& argument) {
8384
// Argument is a runtime tagged variant for the various data types in a IFC model,
8485
// in this particular case we only care about flattening it to a string.
8586
// @todo mostly duplicated from XmlSerializer.cpp
86-
if (argument->isNull()) {
87+
if (argument.isNull()) {
8788
return "-";
8889
}
89-
auto argument_type = argument->type();
90+
auto argument_type = argument.type();
9091
switch (argument_type) {
9192
case IfcUtil::Argument_BOOL: {
92-
const bool b = *argument;
93+
const bool b = argument;
9394
return b ? "true" : "false";
9495
}
9596
case IfcUtil::Argument_DOUBLE: {
96-
const double d = *argument;
97+
const double d = argument;
9798
std::stringstream stream;
9899
stream << std::setprecision(std::numeric_limits< double >::max_digits10) << d;
99100
return stream.str();
100101
break; }
101102
case IfcUtil::Argument_STRING:
102103
case IfcUtil::Argument_ENUMERATION: {
103-
return static_cast<std::string>(*argument);
104+
return static_cast<std::string>(argument);
104105
break; }
105106
case IfcUtil::Argument_INT: {
106-
const int v = *argument;
107+
const int v = argument;
107108
std::stringstream stream;
108109
stream << v;
109110
return stream.str();
@@ -136,7 +137,7 @@ void process_pset(element_properties& props, const T* inst) {
136137
if (!singleval->NominalValue()) {
137138
propvalue = "-";
138139
} else {
139-
props[*pset->Name()][propname] = format_string(singleval->NominalValue()->template as<IfcUtil::IfcBaseClass>()->data().getArgument(0));
140+
props[*pset->Name()][propname] = format_string(singleval->NominalValue()->template as<IfcUtil::IfcBaseClass>()->data().get_attribute_value(0));
140141
}
141142
}
142143
}
@@ -148,8 +149,8 @@ void process_pset(element_properties& props, const T* inst) {
148149
auto qs = qset->Quantities();
149150
for (auto it = qs->begin(); it != qs->end(); ++it) {
150151
auto& q = *it;
151-
if (q->template as<typename Schema::IfcPhysicalSimpleQuantity>() && q->data().getArgument(3)->type() == IfcUtil::Argument_DOUBLE) {
152-
double v = *q->data().getArgument(3);
152+
if (q->template as<typename Schema::IfcPhysicalSimpleQuantity>() && q->data().get_attribute_value(3).type() == IfcUtil::Argument_DOUBLE) {
153+
double v = q->data().get_attribute_value(3);
153154
props[*qset->Name()][q->Name()] = std::to_string(v);
154155
}
155156
}
@@ -264,7 +265,8 @@ int main(int argc, char** argv) {
264265

265266
for (auto it = elements->begin(); it != elements->end(); ++it) {
266267
const auto* element = *it;
267-
std::cout << element->data().toString() << std::endl;
268+
element->toString(std::cout);
269+
std::cout << std::endl;
268270

269271
const IfcSchema::IfcWindow* window;
270272
if ((window = element->as<IfcSchema::IfcWindow>()) != 0) {

src/ifcconvert/IfcConvert.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ namespace latebound_access {
14861486
enum_type->enumeration_items().end(),
14871487
t);
14881488

1489-
return set(inst, attr, IfcWrite::IfcWriteArgument::EnumerationReference(it - enum_type->enumeration_items().begin(), it->c_str()));
1489+
return set(inst, attr, EnumerationReference(enum_type, it - enum_type->enumeration_items().begin()));
14901490
}
14911491

14921492
template <typename T>
@@ -1495,19 +1495,17 @@ namespace latebound_access {
14951495
auto i = decl->attribute_index(attr);
14961496

14971497
auto attr_type = decl->attribute_by_index(i)->type_of_attribute();
1498-
if (attr_type->as_named_type() && attr_type->as_named_type()->declared_type()->as_enumeration_type() && !std::is_same<T, IfcWrite::IfcWriteArgument::EnumerationReference>::value) {
1498+
if (attr_type->as_named_type() && attr_type->as_named_type()->declared_type()->as_enumeration_type() && !std::is_same<T, EnumerationReference>::value) {
14991499
set_enumeration(inst, attr, attr_type->as_named_type()->declared_type()->as_enumeration_type(), t);
15001500
} else {
1501-
IfcWrite::IfcWriteArgument* a = new IfcWrite::IfcWriteArgument;
1502-
a->set(t);
1503-
inst->data().attributes()[i] = a;
1501+
inst->set_attribute_value(i, t);
15041502
}
15051503
}
15061504

15071505
IfcUtil::IfcBaseClass* create(IfcParse::IfcFile& f, const std::string& entity) {
15081506
auto decl = f.schema()->declaration_by_name(entity);
1509-
auto data = new IfcEntityInstanceData(decl);
1510-
auto inst = f.schema()->instantiate(data);
1507+
auto data = IfcEntityInstanceData(storage_t(decl->as_entity()->attribute_count()));
1508+
auto inst = f.schema()->instantiate(decl, std::move(data));
15111509
if (decl->is("IfcRoot")) {
15121510
IfcParse::IfcGlobalId guid;
15131511
latebound_access::set(inst, "GlobalId", (std::string) guid);
@@ -1547,7 +1545,7 @@ void fix_quantities(IfcParse::IfcFile& f, bool no_progress, bool quiet, bool std
15471545
auto IfcRelDefinesByProperties = f.schema()->declaration_by_name("IfcRelDefinesByProperties");
15481546
if (element_quantities) {
15491547
for (auto& eq : *element_quantities) {
1550-
auto rels = eq->data().getInverse(IfcRelDefinesByProperties, -1);
1548+
auto rels = eq->file_->getInverse(eq->id(), IfcRelDefinesByProperties, -1);
15511549
for (auto& rel : *rels) {
15521550
relationships.push_back(rel);
15531551
}

src/ifcconvert/validation_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ struct intersection_validator {
471471
}
472472

473473
std::stringstream ss;
474-
ss << geom_object->product()->data().toString();
474+
geom_object->product()->toString(ss);
475475
auto sss = ss.str();
476476
std::wcout << sss.c_str() << std::endl;
477477

src/ifcgeom/Converter.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
3535

3636
auto place = place_;
3737

38-
representation_id_builder << representation_node->instance->data().id();
38+
representation_id_builder << representation_node->instance->as<IfcUtil::IfcBaseEntity>()->id();
3939

4040
IfcGeom::Representation::BRep* shape;
4141
IfcGeom::ConversionResults shapes;
@@ -137,7 +137,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
137137
}
138138

139139
if (material_style_applied) {
140-
representation_id_builder << "-material-" << single_material->data().id();
140+
representation_id_builder << "-material-" << single_material->id();
141141
}
142142

143143
if (settings_.get<ifcopenshell::geometry::settings::ForceSpaceTransparency>().has() && product->declaration().is("IfcSpace")) {
@@ -153,7 +153,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
153153
try {
154154
IfcUtil::IfcBaseEntity* parent_object = mapping_->get_decomposing_entity(product);
155155
if (parent_object) {
156-
parent_id = parent_object->data().id();
156+
parent_id = parent_object->id();
157157
}
158158
} catch (const std::exception& e) {
159159
Logger::Error(e);
@@ -171,7 +171,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
171171
if (!settings_.get<ifcopenshell::geometry::settings::DisableOpeningSubtractions>().get() && openings && openings->size()) {
172172
representation_id_builder << "-openings";
173173
for (auto it = openings->begin(); it != openings->end(); ++it) {
174-
representation_id_builder << "-" << (*it)->data().id();
174+
representation_id_builder << "-" << (*it)->id();
175175
}
176176

177177
IfcGeom::ConversionResults opened_shapes;
@@ -236,19 +236,19 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
236236
// IfcShapeRepresentation.
237237
const IfcUtil::IfcBaseEntity *representation = representation_node->instance->as<IfcUtil::IfcBaseEntity>();
238238
auto representation_identifier = representation->get("RepresentationIdentifier");
239-
if (!representation_identifier->isNull()) {
240-
context_string = (std::string) *representation_identifier;
239+
if (!representation_identifier.isNull()) {
240+
context_string = (std::string) representation_identifier;
241241
}
242242
else {
243-
IfcUtil::IfcBaseClass *context = (IfcUtil::IfcBaseClass *) *representation->get("ContextOfItems");
243+
IfcUtil::IfcBaseClass *context = (IfcUtil::IfcBaseClass*)representation->get("ContextOfItems");
244244
auto context_type = context->as<IfcUtil::IfcBaseEntity>()->get("ContextType");
245-
if (!context_type->isNull()) {
246-
context_string = (std::string) *context_type;
245+
if (!context_type.isNull()) {
246+
context_string = (std::string)context_type;
247247
}
248248
}
249249

250250
auto elem = new IfcGeom::BRepElement(
251-
product->data().id(),
251+
product->id(),
252252
parent_id,
253253
name,
254254
product_type,
@@ -340,7 +340,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_process
340340
try {
341341
IfcUtil::IfcBaseEntity* parent_object = mapping_->get_decomposing_entity(product);
342342
if (parent_object) {
343-
parent_id = parent_object->data().id();
343+
parent_id = parent_object->id();
344344
}
345345
} catch (const std::exception& e) {
346346
Logger::Error(e);
@@ -352,7 +352,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_process
352352
const std::string context_string = brep->context();
353353

354354
return new IfcGeom::BRepElement(
355-
product->data().id(),
355+
product->id(),
356356
parent_id,
357357
name,
358358
product_type,

src/ifcgeom/IfcGeomElement.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ namespace IfcGeom {
7373
friend bool operator < (const Element& element1, const Element& element2) {
7474
if (element1.type() == "IfcBuildingStorey" && element2.type() == "IfcBuildingStorey") {
7575
size_t attr_index = element1.product()->declaration().attribute_index("Elevation");
76-
Argument* elev_attr1 = element1.product()->data().getArgument(attr_index);
77-
Argument* elev_attr2 = element2.product()->data().getArgument(attr_index);
76+
auto elev_attr1 = element1.product()->data().get_attribute_value(attr_index);
77+
auto elev_attr2 = element2.product()->data().get_attribute_value(attr_index);
7878

79-
if (!elev_attr1->isNull() && !elev_attr2->isNull()) {
80-
double elev1 = *elev_attr1;
81-
double elev2 = *elev_attr2;
79+
if (!elev_attr1.isNull() && !elev_attr2.isNull()) {
80+
double elev1 = elev_attr1;
81+
double elev2 = elev_attr2;
8282

8383
return elev1 < elev2;
8484
}

src/ifcgeom/IfcGeomFilter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace IfcGeom {
7676
// schema.
7777
// @todo pass settings
7878
ifcopenshell::geometry::Settings s;
79-
static auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(prod->data().file, s);
79+
static auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(prod->file_, s);
8080
while ((parent = mapping->get_decomposing_entity(current, traverse_openings)) != nullptr) {
8181
if (pred(parent)) {
8282
return true;
@@ -138,7 +138,7 @@ namespace IfcGeom {
138138

139139
std::string value(IfcUtil::IfcBaseEntity* prod) const {
140140
try {
141-
return (std::string) *prod->get(attribute_name);
141+
return (std::string) prod->get(attribute_name);
142142
} catch (...) {
143143
// Either
144144
// (a) not an attribute name for this entity instance
@@ -184,7 +184,7 @@ namespace IfcGeom {
184184
bool match(IfcUtil::IfcBaseEntity* prod) const {
185185
// @todo
186186
ifcopenshell::geometry::Settings s;
187-
static auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(prod->data().file, s);
187+
static auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(prod->file_, s);
188188
layer_map_t layers = mapping->get_layers(prod);
189189
return std::find_if(layers.begin(), layers.end(), wildcards_match(values)) != layers.end();
190190
}
@@ -255,7 +255,7 @@ namespace IfcGeom {
255255
, instance_ids_(instance_ids) {}
256256

257257
bool match(IfcUtil::IfcBaseEntity* prod) const {
258-
return instance_ids_.find(prod->data().id()) != instance_ids_.end();
258+
return instance_ids_.find(prod->id()) != instance_ids_.end();
259259
}
260260

261261
bool operator()(IfcUtil::IfcBaseEntity* prod) const {

src/ifcgeom/IfcGeomRepresentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
154154
surface_styles_.push_back(clr(1));
155155
surface_styles_.push_back(clr(2));
156156

157-
sid = it->Style().instance ? it->Style().instance->data().id() : -1;
157+
sid = it->Style().instance ? it->Style().instance->as<IfcUtil::IfcBaseEntity>()->id() : -1;
158158
} else {
159159
surface_styles_.push_back(-1.);
160160
surface_styles_.push_back(-1.);

src/ifcgeom/Iterator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ namespace IfcGeom {
518518

519519
Logger::SetProduct(product);
520520

521-
IfcGeom::BRepElement* brep = static_cast<IfcGeom::BRepElement*>(decorate_with_cache_(GeometrySerializer::READ_BREP, (std::string)*product->get("GlobalId"), std::to_string(representation->instance->data().id()), [kernel, settings, product, place, representation]() {
521+
IfcGeom::BRepElement* brep = static_cast<IfcGeom::BRepElement*>(decorate_with_cache_(GeometrySerializer::READ_BREP, (std::string)product->get("GlobalId"), std::to_string(representation->instance->as<IfcUtil::IfcBaseEntity>()->id()), [kernel, settings, product, place, representation]() {
522522
return kernel->create_brep_for_representation_and_product(representation, product, place);
523523
}));
524524

@@ -539,7 +539,7 @@ namespace IfcGeom {
539539
const IfcUtil::IfcBaseEntity* product2 = p.first;
540540
const auto& place2 = p.second;
541541

542-
IfcGeom::BRepElement* brep2 = static_cast<IfcGeom::BRepElement*>(decorate_with_cache_(GeometrySerializer::READ_BREP, (std::string)*product2->get("GlobalId"), std::to_string(representation->instance->data().id()), [kernel, settings, product2, place2, representation, brep]() {
542+
IfcGeom::BRepElement* brep2 = static_cast<IfcGeom::BRepElement*>(decorate_with_cache_(GeometrySerializer::READ_BREP, (std::string)product2->get("GlobalId"), std::to_string(representation->instance->as<IfcUtil::IfcBaseEntity>()->id()), [kernel, settings, product2, place2, representation, brep]() {
543543
return kernel->create_brep_for_processed_representation(product2, place2, brep);
544544
}));
545545
if (brep2) {
@@ -746,13 +746,13 @@ namespace IfcGeom {
746746
instance_type = ifc_product->declaration().name();
747747

748748
if (ifc_product->declaration().is("IfcRoot")) {
749-
product_guid = (std::string) *ifc_product->get("GlobalId");
749+
product_guid = (std::string) ifc_product->get("GlobalId");
750750
product_name = ifc_product->get_value<std::string>("Name", "");
751751
}
752752

753753
auto parent_object = converter_->mapping()->get_decomposing_entity(ifc_product);
754754
if (parent_object) {
755-
parent_id = parent_object->data().id();
755+
parent_id = parent_object->id();
756756
}
757757

758758
// fails in case of IfcProject

src/ifcgeom/abstract_mapping.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ namespace geometry {
3030
Settings settings_;
3131

3232
bool use_caching_ = true;
33+
3334
public:
3435
abstract_mapping(Settings& s) : settings_(s) {}
36+
virtual ~abstract_mapping() {}
3537

3638
virtual ifcopenshell::geometry::taxonomy::ptr map(const IfcUtil::IfcBaseInterface*) = 0;
3739
virtual void get_representations(std::vector<geometry_conversion_task>& tasks, std::vector<filter_t>& filters) = 0;

0 commit comments

Comments
 (0)