Skip to content

Commit 4c13e24

Browse files
committed
Configurable pointer type; std::from_chars(); aggregate inverses in vector; skip parse_context
1 parent c8d39cc commit 4c13e24

11 files changed

Lines changed: 850 additions & 614 deletions

File tree

‎src/ifcgeom/kernel_registry.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ namespace {
8181
try {
8282
module = manager.load(path);
8383
} catch (const std::exception& e) {
84+
#ifdef IFOPSH_PLUGIN_DEBUG
8485
std::cerr << "[ifcopenshell.plugin] skip kernel plugin " << path << ": " << e.what() << std::endl;
86+
#else
87+
static_cast<void>(e);
88+
#endif
8589
continue;
8690
}
8791
if (module.meta().kind_ != ifcopenshell::plugin::kind::kernel) {

‎src/ifcparse/express.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,27 @@ uint32_t express::Base::identity() const { return data()->identity(); }
99
uint32_t express::Base::id() const { return data()->id(); }
1010

1111
const instance_data* express::Base::data() const {
12+
#ifdef IFOPSH_SAFE_INSTANCE
1213
auto sp = data_.lock();
1314
if (sp) {
1415
return sp.get();
1516
} else {
1617
throw std::runtime_error("Trying to access deleted instance reference");
1718
}
19+
#else
20+
return data_;
21+
#endif
1822
}
1923

2024
instance_data* express::Base::data() {
25+
#ifdef IFOPSH_SAFE_INSTANCE
2126
auto sp = data_.lock();
2227
if (sp) {
2328
return sp.get();
2429
} else {
2530
throw std::runtime_error("Trying to access deleted instance reference");
2631
}
32+
#else
33+
return data_;
34+
#endif
2735
}

‎src/ifcparse/express.h‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@
3131
class aggregate_of_instance;
3232

3333
namespace ifcopenshell {
34+
35+
#ifdef IFOPSH_SAFE_INSTANCE
36+
using pointer_type = std::weak_ptr<instance_data>;
37+
using shared_pointer_type = shared_pointer_type;
38+
template <typename T, typename... Args>
39+
shared_pointer_type make_pointer_type(Args&&... args) {
40+
return std::make_shared<T>(std::forward<Args>(args)...);
41+
}
42+
#else
43+
using pointer_type = instance_data*;
44+
using shared_pointer_type = instance_data*;
45+
template <typename T, typename... Args>
46+
shared_pointer_type make_pointer_type(Args&&... args) {
47+
return new T(std::forward<Args>(args)...);
48+
}
49+
#endif
50+
3451
class file;
3552
namespace impl {
3653
struct in_memory_file_storage;
@@ -49,12 +66,16 @@ class DeclaredType;
4966

5067
class IFC_PARSE_API Base {
5168
protected:
52-
std::weak_ptr<instance_data> data_;
69+
ifcopenshell::pointer_type data_;
5370
const instance_data* data() const;
5471
instance_data* data();
5572
public:
5673
operator bool() const {
74+
#ifdef IFOPSH_SAFE_INSTANCE
5775
return !data_.expired();
76+
#else
77+
return data_ != nullptr;
78+
#endif
5879
}
5980

6081
bool operator<(const Base& other) const {
@@ -69,12 +90,16 @@ class IFC_PARSE_API Base {
6990
return !(*this == other);
7091
}
7192

72-
Base() {};
93+
Base() {
94+
#ifndef IFOPSH_SAFE_INSTANCE
95+
data_ = nullptr;
96+
#endif
97+
};
7398
Base(std::nullopt_t) noexcept : Base() {}
74-
Base(const std::weak_ptr<instance_data>& data) : data_(data) {}
99+
Base(const ifcopenshell::pointer_type& data) : data_(data) {}
75100

76101
// @todo try and make this private over time too
77-
const std::weak_ptr<instance_data>& data_weak() const { return data_; }
102+
const ifcopenshell::pointer_type& data_weak() const { return data_; }
78103

79104
const ifcopenshell::declaration& declaration() const;
80105

@@ -150,7 +175,7 @@ class IFC_PARSE_API Select : public Base {
150175
public:
151176
Select() {}
152177
Select(std::nullopt_t) noexcept : Base() {}
153-
Select(const std::weak_ptr<instance_data>& data) : Base(data) {}
178+
Select(const ifcopenshell::pointer_type& data) : Base(data) {}
154179
Select(const Base& base) : Base(base.data_weak()) {}
155180

156181
Base concrete() const {

0 commit comments

Comments
 (0)