From 1d0e18a186f67844ccd873eabb56ebdaa3f47f11 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sat, 25 May 2013 13:49:50 -0700 Subject: Switch block_list and subclasses to dumb_ptr Now we're well-defined, since we're actually calling ctors and dtors. Most of this code will not survive long ... --- src/common/dumb_ptr.hpp | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src/common/dumb_ptr.hpp') diff --git a/src/common/dumb_ptr.hpp b/src/common/dumb_ptr.hpp index 9321036..1a0b4a1 100644 --- a/src/common/dumb_ptr.hpp +++ b/src/common/dumb_ptr.hpp @@ -28,17 +28,26 @@ template class dumb_ptr { + template + friend class dumb_ptr; T *impl; public: explicit dumb_ptr(T *p=nullptr) : impl(p) {} + template + dumb_ptr(dumb_ptr p) + : impl(p.impl) + {} + dumb_ptr(std::nullptr_t) + : impl(nullptr) + {} void delete_() { delete impl; - forget(); + *this = nullptr; } template void new_(A&&... a) @@ -51,9 +60,10 @@ public: { return dumb_ptr(new T(std::forward(a)...)); } - void forget() + dumb_ptr& operator = (std::nullptr_t) { impl = nullptr; + return *this; } T& operator *() const @@ -74,6 +84,15 @@ public: { return !impl; } + + friend bool operator == (dumb_ptr l, dumb_ptr r) + { + return l.impl == r.impl; + } + friend bool operator != (dumb_ptr l, dumb_ptr r) + { + return !(l == r); + } }; // unmanaged new/delete-able pointer @@ -85,6 +104,8 @@ class dumb_ptr size_t sz; public: dumb_ptr() : impl(), sz() {} + dumb_ptr(std::nullptr_t) + : impl(nullptr), sz(0) {} dumb_ptr(T *p, size_t z) : impl(p) , sz(z) @@ -93,7 +114,7 @@ public: void delete_() { delete[] impl; - forget(); + *this = nullptr; } void new_(size_t z) { @@ -105,10 +126,11 @@ public: { return dumb_ptr(new T[z](), z); } - void forget() + dumb_ptr& operator = (std::nullptr_t) { impl = nullptr; sz = 0; + return *this; } size_t size() const @@ -143,6 +165,15 @@ public: { return !impl; } + + friend bool operator == (dumb_ptr l, dumb_ptr r) + { + return l.impl == r.impl; + } + friend bool operator != (dumb_ptr l, dumb_ptr r) + { + return !(l == r); + } }; #endif // TMWA_COMMON_DUMB_PTR_HPP -- cgit v1.2.3-60-g2f50