3131class aggregate_of_instance ;
3232
3333namespace 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+
3451class file ;
3552namespace impl {
3653struct in_memory_file_storage ;
@@ -49,12 +66,16 @@ class DeclaredType;
4966
5067class 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