diff options
Diffstat (limited to 'src/FbTk/RefCount.hh')
-rw-r--r-- | src/FbTk/RefCount.hh | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/FbTk/RefCount.hh b/src/FbTk/RefCount.hh index 6d1b9b7..597f847 100644 --- a/src/FbTk/RefCount.hh +++ b/src/FbTk/RefCount.hh | |||
@@ -27,6 +27,8 @@ namespace FbTk { | |||
27 | /// holds a pointer with reference counting, similar to std:auto_ptr | 27 | /// holds a pointer with reference counting, similar to std:auto_ptr |
28 | template <typename Pointer> | 28 | template <typename Pointer> |
29 | class RefCount { | 29 | class RefCount { |
30 | typedef Pointer* RefCount::*bool_type; | ||
31 | |||
30 | public: | 32 | public: |
31 | RefCount(); | 33 | RefCount(); |
32 | explicit RefCount(Pointer *p); | 34 | explicit RefCount(Pointer *p); |
@@ -35,9 +37,11 @@ public: | |||
35 | ~RefCount(); | 37 | ~RefCount(); |
36 | RefCount<Pointer> &operator = (const RefCount<Pointer> ©); | 38 | RefCount<Pointer> &operator = (const RefCount<Pointer> ©); |
37 | RefCount<Pointer> &operator = (Pointer *p); | 39 | RefCount<Pointer> &operator = (Pointer *p); |
38 | Pointer *operator * () const { return get(); } | 40 | Pointer &operator * () const { return *get(); } |
39 | Pointer *operator -> () const { return get(); } | 41 | Pointer *operator -> () const { return get(); } |
40 | Pointer *get() const { return m_data; } | 42 | Pointer *get() const { return m_data; } |
43 | /// conversion to "bool" | ||
44 | operator bool_type() const { return m_data ? &RefCount::m_data : 0; } | ||
41 | 45 | ||
42 | private: | 46 | private: |
43 | /// increase reference count | 47 | /// increase reference count |
@@ -45,7 +49,7 @@ private: | |||
45 | /// decrease reference count | 49 | /// decrease reference count |
46 | void decRefCount(); | 50 | void decRefCount(); |
47 | Pointer *m_data; ///< data holder | 51 | Pointer *m_data; ///< data holder |
48 | mutable unsigned int *m_refcount; ///< holds reference counting | 52 | unsigned int *m_refcount; ///< holds reference counting |
49 | }; | 53 | }; |
50 | 54 | ||
51 | // implementation | 55 | // implementation |