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 +++++++++++++++++++++++++++++++++++---- src/common/nullpo.hpp | 11 +++++++++++ src/common/timer.cpp | 6 +++--- 3 files changed, 49 insertions(+), 7 deletions(-) (limited to 'src/common') 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 diff --git a/src/common/nullpo.hpp b/src/common/nullpo.hpp index 305448f..9eb9ea9 100644 --- a/src/common/nullpo.hpp +++ b/src/common/nullpo.hpp @@ -27,4 +27,15 @@ bool nullpo_chk(const char *file, int line, const char *func, const void *target); +template +bool nullpo_chk(const char *file, int line, const char *func, T target) +{ + return nullpo_chk(file, line, func, target.operator->()); +} +template +bool nullpo_chk(const char *file, int line, const char *func, T *target) +{ + return nullpo_chk(file, line, func, static_cast(target)); +} + #endif // NULLPO_HPP diff --git a/src/common/timer.cpp b/src/common/timer.cpp index d2d355b..ec1f6b2 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp @@ -75,14 +75,14 @@ void Timer::cancel() td->owner = nullptr; td->func = do_nothing; td->interval = interval_t::zero(); - td.forget(); + td = nullptr; } void Timer::detach() { assert (this == td->owner); td->owner = nullptr; - td.forget(); + td = nullptr; } static @@ -116,7 +116,7 @@ Timer::Timer(tick_t tick, timer_func func, interval_t interval) Timer::Timer(Timer&& t) : td(t.td) { - t.td.forget(); + t.td = nullptr; if (td) { assert (td->owner == &t); -- cgit v1.2.3-70-g09d2