23 #ifndef _TelepathyQt_shared_ptr_h_HEADER_GUARD_ 24 #define _TelepathyQt_shared_ptr_h_HEADER_GUARD_ 26 #ifndef IN_TP_QT_HEADER 27 #error IN_TP_QT_HEADER 30 #include <TelepathyQt/Global> 48 Q_DISABLE_COPY(SharedCount)
52 : d(d), strongref(0), weakref(0)
57 template <
class T>
friend class SharedPtr;
58 template <
class T>
friend class WeakPtr;
62 mutable QAtomicInt strongref;
63 mutable QAtomicInt weakref;
75 if (!sc->weakref.deref()) {
89 inline void ref()
const { sc->strongref.ref(); }
90 inline bool deref()
const {
return sc->strongref.deref(); }
98 typedef bool (
SharedPtr<T>::*UnspecifiedBoolType)()
const;
102 explicit inline SharedPtr(T *d) : d(d) {
if (d) { d->ref(); } }
103 template <
typename Sub
class>
108 RefCounted::SharedCount *sc = o.sc;
112 register int tmp = sc->strongref.fetchAndAddOrdered(0);
115 if (sc->strongref.testAndSetRelaxed(tmp, tmp + 1)) {
120 tmp = sc->strongref.fetchAndAddOrdered(0);
124 d =
dynamic_cast<T*
>(sc->d);
136 if (d && !d->deref()) {
148 inline T *
data()
const {
return d; }
153 inline bool isNull()
const {
return !d; }
159 inline bool operator==(
const T *ptr)
const {
return d == ptr; }
160 inline bool operator!=(
const T *ptr)
const {
return d != ptr; }
208 return QT_PREPEND_NAMESPACE(qHash<T>(ptr.
data()));
216 typedef bool (
WeakPtr<T>::*UnspecifiedBoolType)()
const;
241 if (sc && !sc->weakref.deref()) {
246 inline bool isNull()
const {
return !sc || sc->strongref.fetchAndAddOrdered(0) <= 0; }
264 RefCounted::SharedCount *tmp = sc;
275 RefCounted::SharedCount *sc;
281 T *actualPtr = ptr.sc ? ptr.sc.d : 0;
282 return QT_PREPEND_NAMESPACE(qHash<T>(actualPtr));
uint qHash(const ChannelClassSpec &spec)
Definition: channel-class-spec.h:283
bool operator==(const T *ptr) const
Definition: shared-ptr.h:159
static SharedPtr< T > dynamicCast(const SharedPtr< X > &src)
Definition: shared-ptr.h:182
SharedPtr(const SharedPtr< Subclass > &o)
Definition: shared-ptr.h:104
bool operator==(const SharedPtr< T > &o) const
Definition: shared-ptr.h:157
void swap(WeakPtr< T > &o)
Definition: shared-ptr.h:262
The RefCounted class is a base class for shared objects used by SharedPtr.
Definition: shared-ptr.h:42
SharedPtr(const SharedPtr< T > &o)
Definition: shared-ptr.h:105
SharedPtr< T > & operator=(const SharedPtr< T > &o)
Definition: shared-ptr.h:162
SharedPtr< T > toStrongRef() const
Definition: shared-ptr.h:269
void swap(SharedPtr< T > &o)
Definition: shared-ptr.h:168
static SharedPtr< T > qObjectCast(const SharedPtr< X > &src)
Definition: shared-ptr.h:194
T * operator->() const
Definition: shared-ptr.h:151
WeakPtr(const SharedPtr< T > &o)
Definition: shared-ptr.h:230
The ContactManager class is responsible for managing contacts.
Definition: contact-manager.h:50
static SharedPtr< T > constCast(const SharedPtr< X > &src)
Definition: shared-ptr.h:188
WeakPtr(const WeakPtr< T > &o)
Definition: shared-ptr.h:229
The WeakPtr class holds a weak reference to an object managed by SharedPtr.
Definition: shared-ptr.h:40
bool operator!() const
Definition: shared-ptr.h:154
RefCounted()
Definition: shared-ptr.h:67
virtual ~RefCounted()
Definition: shared-ptr.h:72
~SharedPtr()
Definition: shared-ptr.h:134
WeakPtr< T > & operator=(const SharedPtr< T > &o)
Definition: shared-ptr.h:256
T * operator->()
Definition: shared-ptr.h:150
SharedPtr()
Definition: shared-ptr.h:101
WeakPtr()
Definition: shared-ptr.h:219
WeakPtr< T > & operator=(const WeakPtr< T > &o)
Definition: shared-ptr.h:250
static SharedPtr< T > staticCast(const SharedPtr< X > &src)
Definition: shared-ptr.h:176
bool operator!=(const SharedPtr< T > &o) const
Definition: shared-ptr.h:158
T * data() const
Definition: shared-ptr.h:148
~WeakPtr()
Definition: shared-ptr.h:239
bool isNull() const
Definition: shared-ptr.h:246
SharedPtr(T *d)
Definition: shared-ptr.h:102
bool operator!() const
Definition: shared-ptr.h:247
void reset()
Definition: shared-ptr.h:143
bool operator!=(const T *ptr) const
Definition: shared-ptr.h:160
bool isNull() const
Definition: shared-ptr.h:153
const T * constData() const
Definition: shared-ptr.h:149
Definition: abstract-adaptor.cpp:31
SharedPtr(const WeakPtr< T > &o)
Definition: shared-ptr.h:106
The SharedPtr class is a pointer to an explicitly shared object.
Definition: shared-ptr.h:39
WeakPtr(T *d)
Definition: shared-ptr.h:220