summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/dumb_ptr.hpp39
-rw-r--r--src/common/nullpo.hpp11
-rw-r--r--src/common/timer.cpp6
3 files changed, 49 insertions, 7 deletions
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 T>
class dumb_ptr
{
+ template<class U>
+ friend class dumb_ptr;
T *impl;
public:
explicit
dumb_ptr(T *p=nullptr)
: impl(p)
{}
+ template<class U>
+ dumb_ptr(dumb_ptr<U> p)
+ : impl(p.impl)
+ {}
+ dumb_ptr(std::nullptr_t)
+ : impl(nullptr)
+ {}
void delete_()
{
delete impl;
- forget();
+ *this = nullptr;
}
template<class... A>
void new_(A&&... a)
@@ -51,9 +60,10 @@ public:
{
return dumb_ptr<T>(new T(std::forward<A>(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<T[]>
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<T[]>(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<class T>
+bool nullpo_chk(const char *file, int line, const char *func, T target)
+{
+ return nullpo_chk(file, line, func, target.operator->());
+}
+template<class T>
+bool nullpo_chk(const char *file, int line, const char *func, T *target)
+{
+ return nullpo_chk(file, line, func, static_cast<const void *>(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);