21 #include "kdelibs_export.h" 113 : ptr(t) {
if ( ptr ) ptr->_KShared_ref(); }
120 : ptr(p.ptr) {
if ( ptr ) ptr->_KShared_ref(); }
129 if ( ptr == p.ptr )
return *
this;
130 if ( ptr ) ptr->_KShared_unref();
132 if ( ptr ) ptr->_KShared_ref();
136 if ( ptr == p )
return *
this;
137 if ( ptr ) ptr->_KShared_unref();
139 if ( ptr ) ptr->_KShared_ref();
142 bool operator== (
const KSharedPtr<T>& p )
const {
return ( ptr == p.ptr ); }
143 bool operator!= (
const KSharedPtr<T>& p )
const {
return ( ptr != p.ptr ); }
144 bool operator== (
const T* p )
const {
return ( ptr == p ); }
145 bool operator!= (
const T* p )
const {
return ( ptr != p ); }
146 bool operator!()
const {
return ( ptr == 0 ); }
147 operator T*()
const {
return ptr; }
159 const T*
data()
const {
return ptr; }
161 const T& operator*()
const {
return *ptr; }
162 T& operator*() {
return *ptr; }
163 const T* operator->()
const {
return ptr; }
164 T* operator->() {
return ptr; }
170 int count()
const {
return ptr->_KShared_count(); }
Can be used to control the lifetime of an object that has derived KShared.
KShared()
Standard constructor.
T * data()
Returns the pointer.
~KSharedPtr()
Unreferences the object that this pointer points to.
void _KShared_ref() const
Increases the reference count by one.
void _KShared_unref() const
Releases a reference (decreases the reference count by one).
KShared(const KShared &)
Copy constructor.
KSharedPtr(T *t)
Creates a new pointer.
KShared & operator=(const KShared &)
Overloaded assignment operator.
int count() const
Returns the number of references.
KSharedPtr(const KSharedPtr &p)
Copies a pointer.
KSharedPtr()
Creates a null pointer.
int _KShared_count() const
Return the current number of references held.
const T * data() const
Returns the pointer.
Reference counting for shared objects.