summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/osmartpointer.h
Unidiff
Diffstat (limited to 'libopie2/opiecore/osmartpointer.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/osmartpointer.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/libopie2/opiecore/osmartpointer.h b/libopie2/opiecore/osmartpointer.h
index 9000e71..8f9da7f 100644
--- a/libopie2/opiecore/osmartpointer.h
+++ b/libopie2/opiecore/osmartpointer.h
@@ -19,48 +19,49 @@ _;:, .> :=|. This program is free software; you can
19 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 19 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
20 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 20 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.= = ; Library General Public License for more 21..}^=.= = ; Library General Public License for more
22++= -. .` .: details. 22++= -. .` .: details.
23: = ...= . :.=- 23: = ...= . :.=-
24-. .:....=;==+<; You should have received a copy of the GNU 24-. .:....=;==+<; You should have received a copy of the GNU
25 -_. . . )=. = Library General Public License along with 25 -_. . . )=. = Library General Public License along with
26 -- :-=` this library; see the file COPYING.LIB. 26 -- :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation, 27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330, 28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. 29 Boston, MA 02111-1307, USA.
30*/ 30*/
31 31
32#ifndef _OSmartPointer_h 32#ifndef _OSmartPointer_h
33#define _OSmartPointer_h 33#define _OSmartPointer_h
34 34
35/*! 35/*!
36 * \file OSmartPointer.h 36 * \file OSmartPointer.h
37 * \brief smart pointer and reference counter 37 * \brief smart pointer and reference counter
38 * \author Rajko Albrecht 38 * \author Rajko Albrecht
39 * 39 *
40 */ 40 */
41 41
42namespace Opie { 42namespace Opie {
43namespace Core {
43 44
44//! simple reference counter class 45//! simple reference counter class
45class ORefCount { 46class ORefCount {
46protected: 47protected:
47 //! reference count member 48 //! reference count member
48 long m_RefCount; 49 long m_RefCount;
49public: 50public:
50 //! first reference must be added after "new" via Pointer() 51 //! first reference must be added after "new" via Pointer()
51 ORefCount() : m_RefCount(0) 52 ORefCount() : m_RefCount(0)
52 {} 53 {}
53 virtual ~ORefCount() {} 54 virtual ~ORefCount() {}
54 //! add a reference 55 //! add a reference
55 void Incr() { 56 void Incr() {
56 ++m_RefCount; 57 ++m_RefCount;
57 } 58 }
58 //! delete a reference 59 //! delete a reference
59 void Decr() { 60 void Decr() {
60 --m_RefCount; 61 --m_RefCount;
61 } 62 }
62 //! is it referenced 63 //! is it referenced
63 bool Shared() { return (m_RefCount > 0); } 64 bool Shared() { return (m_RefCount > 0); }
64}; 65};
65 66
66//! reference counting wrapper class 67//! reference counting wrapper class
@@ -119,27 +120,28 @@ public:
119 operator T* () const { return ptr; } 120 operator T* () const { return ptr; }
120 121
121 //! deref: fails for NULL pointer 122 //! deref: fails for NULL pointer
122 T& operator* () {return *ptr; } 123 T& operator* () {return *ptr; }
123 //! deref: fails for NULL pointer 124 //! deref: fails for NULL pointer
124 const T& operator* ()const {return *ptr; } 125 const T& operator* ()const {return *ptr; }
125 126
126 //! deref with method call 127 //! deref with method call
127 T* operator-> () {return ptr; } 128 T* operator-> () {return ptr; }
128 //! deref with const method call 129 //! deref with const method call
129 const T* operator-> ()const {return ptr; } 130 const T* operator-> ()const {return ptr; }
130 131
131 //! supports "if (pointer)" 132 //! supports "if (pointer)"
132 operator bool () const { return (ptr != NULL); } 133 operator bool () const { return (ptr != NULL); }
133 //! "if (pointer)" as non const 134 //! "if (pointer)" as non const
134 operator bool () { return ptr != NULL;} 135 operator bool () { return ptr != NULL;}
135 136
136 //! support if (!pointer)" 137 //! support if (!pointer)"
137 bool operator! () const { return (ptr == NULL); } 138 bool operator! () const { return (ptr == NULL); }
138 //! support if (!pointer)" as non const 139 //! support if (!pointer)" as non const
139 bool operator! () { return (ptr == NULL); } 140 bool operator! () { return (ptr == NULL); }
140}; 141};
141 142
142} 143}
144}
143 145
144#endif 146#endif
145 147