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()));
211 template<
typename T>
inline uint
qHash(
const WeakPtr<T> &ptr);
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));
SharedPtr(T *d)
Definition: shared-ptr.h:102
static SharedPtr< T > dynamicCast(const SharedPtr< X > &src)
Definition: shared-ptr.h:182
bool operator!=(const SharedPtr< T > &o) const
Definition: shared-ptr.h:158
SharedPtr(const SharedPtr< T > &o)
Definition: shared-ptr.h:105
The ContactManager class is responsible for managing contacts.
Definition: contact-manager.h:50
uint qHash(const ChannelClassSpec &spec)
Definition: channel-class-spec.h:283
SharedPtr()
Definition: shared-ptr.h:101
T * operator->() const
Definition: shared-ptr.h:151
~WeakPtr()
Definition: shared-ptr.h:239
SharedPtr< T > & operator=(const SharedPtr< T > &o)
Definition: shared-ptr.h:162
bool isNull() const
Definition: shared-ptr.h:153
T * data() const
Definition: shared-ptr.h:148
WeakPtr< T > & operator=(const WeakPtr< T > &o)
Definition: shared-ptr.h:250
bool operator!=(const T *ptr) const
Definition: shared-ptr.h:160
virtual ~RefCounted()
Definition: shared-ptr.h:72
WeakPtr< T > & operator=(const SharedPtr< T > &o)
Definition: shared-ptr.h:256
static SharedPtr< T > constCast(const SharedPtr< X > &src)
Definition: shared-ptr.h:188
The SharedPtr class is a pointer to an explicitly shared object.
Definition: shared-ptr.h:39
T * operator->()
Definition: shared-ptr.h:150
WeakPtr(T *d)
Definition: shared-ptr.h:220
bool operator!() const
Definition: shared-ptr.h:154
SharedPtr(const WeakPtr< T > &o)
Definition: shared-ptr.h:106
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
friend class SharedPtr< T >
Definition: shared-ptr.h:272
WeakPtr()
Definition: shared-ptr.h:219
void reset()
Definition: shared-ptr.h:143
bool operator==(const T *ptr) const
Definition: shared-ptr.h:159
bool isNull() const
Definition: shared-ptr.h:246
static SharedPtr< T > qObjectCast(const SharedPtr< X > &src)
Definition: shared-ptr.h:194
bool operator!() const
Definition: shared-ptr.h:247
~SharedPtr()
Definition: shared-ptr.h:134
static SharedPtr< T > staticCast(const SharedPtr< X > &src)
Definition: shared-ptr.h:176
void swap(SharedPtr< T > &o)
Definition: shared-ptr.h:168
const T * constData() const
Definition: shared-ptr.h:149
WeakPtr(const SharedPtr< T > &o)
Definition: shared-ptr.h:230
Definition: abstract-adaptor.cpp:31
WeakPtr(const WeakPtr< T > &o)
Definition: shared-ptr.h:229
SharedPtr(const SharedPtr< Subclass > &o)
Definition: shared-ptr.h:104
SharedPtr< T > toStrongRef() const
Definition: shared-ptr.h:269
RefCounted()
Definition: shared-ptr.h:67
The WeakPtr class holds a weak reference to an object managed by SharedPtr.
Definition: shared-ptr.h:40
bool operator==(const SharedPtr< T > &o) const
Definition: shared-ptr.h:157