ExternalRefCount< T > Class Template Reference

#include <qsharedpointer_impl.h>

Class Description

template<class T>
class QtSharedPointer::ExternalRefCount< T >

Definition at line 105 of file qsharedpointer_impl.h.

+ Inheritance diagram for ExternalRefCount< T >:

Protected Types

typedef ExternalRefCountData Data
 

Protected Member Functions

void deref ()
 
void internalConstruct (T *ptr)
 
template<typename Deleter >
void internalConstruct (T *ptr, Deleter deleter)
 
void internalCreate ()
 
void internalFinishConstruction (T *ptr)
 
 ExternalRefCount ()
 
 ExternalRefCount (Qt::Initialization i)
 
 ExternalRefCount (T *ptr)
 
template<typename Deleter >
 ExternalRefCount (T *ptr, Deleter deleter)
 
 ExternalRefCount (const ExternalRefCount< T > &other)
 
template<class X >
 ExternalRefCount (const ExternalRefCount< X > &other)
 
 ~ExternalRefCount ()
 
template<class X >
void internalCopy (const ExternalRefCount< X > &other)
 
void internalSwap (ExternalRefCount &other)
 
void ref () const
 
void internalSet (Data *o, T *actual)
 
- Protected Member Functions inherited from Basic< T >
 Basic (T *ptr=0)
 
 Basic (Qt::Initialization)
 
void internalConstruct (T *ptr)
 

Static Protected Member Functions

static void deref (Data *d, T *value)
 

Protected Attributes

Datad
 
- Protected Attributes inherited from Basic< T >
Typevalue
 

Friends

template<class X >
class ExternalRefCount
 
template<class X >
class QT_PREPEND_NAMESPACE (QWeakPointer)
 
template<class X , class Y >
QSharedPointer< X > copyAndSetPointer (X *ptr, const QSharedPointer< Y > &src)
 

Additional Inherited Members

- Public Types inherited from Basic< T >
typedef T Type
 
typedef T element_type
 
typedef T value_type
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef qptrdiff difference_type
 
- Public Member Functions inherited from Basic< T >
T * data () const
 
bool isNull () const
 
 operator RestrictedBool () const
 
bool operator! () const
 
T & operator* () const
 
T * operator-> () const
 

Member Typedef Documentation

typedef ExternalRefCountData Data
protected

Definition at line 333 of file qsharedpointer_impl.h.

Constructor & Destructor Documentation

ExternalRefCount ( )
inlineprotected

Definition at line 387 of file qsharedpointer_impl.h.

ExternalRefCount ( Qt::Initialization  i)
inlineprotected

Definition at line 388 of file qsharedpointer_impl.h.

388 : Basic<T>(i) { }
ExternalRefCount ( T *  ptr)
inlineprotected

Definition at line 390 of file qsharedpointer_impl.h.

390  : Basic<T>(Qt::Uninitialized) // throws
391  { internalConstruct(ptr); }
ExternalRefCount ( T *  ptr,
Deleter  deleter 
)
inlineprotected

Definition at line 393 of file qsharedpointer_impl.h.

393  : Basic<T>(Qt::Uninitialized) // throws
394  { internalConstruct(ptr, deleter); }
ExternalRefCount ( const ExternalRefCount< T > &  other)
inlineprotected

Definition at line 396 of file qsharedpointer_impl.h.

396  : Basic<T>(other), d(other.d)
397  { if (d) ref(); }
ExternalRefCount ( const ExternalRefCount< X > &  other)
inlineprotected

Definition at line 399 of file qsharedpointer_impl.h.

399  : Basic<T>(other.value), d(other.d)
400  { if (d) ref(); }
~ExternalRefCount ( )
inlineprotected

Definition at line 401 of file qsharedpointer_impl.h.

Member Function Documentation

void deref ( )
inlineprotected

Definition at line 335 of file qsharedpointer_impl.h.

336  { deref(d, this->value); }
GLsizei const GLfloat * value
Definition: GLee.h:1742
static void deref ( Data d,
T *  value 
)
inlinestaticprotected

Definition at line 337 of file qsharedpointer_impl.h.

338  {
339  if (!d) return;
340  if (!d->strongref.deref()) {
341  if (!d->destroy())
342  delete value;
343  }
344  if (!d->weakref.deref())
345  delete d;
346  }
GLsizei const GLfloat * value
Definition: GLee.h:1742
void internalConstruct ( T *  ptr)
inlineprotected

Definition at line 348 of file qsharedpointer_impl.h.

349  {
350 #ifdef QT_SHAREDPOINTER_TRACK_POINTERS
351  internalConstruct<void (*)(T *)>(ptr, normalDeleter);
352 #else
353  if (ptr)
354  d = new Data;
355  else
356  d = 0;
358 #endif
359  }
void internalConstruct ( T *  ptr,
Deleter  deleter 
)
inlineprotected

Definition at line 362 of file qsharedpointer_impl.h.

363  {
364  if (ptr)
366  else
367  d = 0;
369  }
static Self * create(T *ptr, Deleter userDeleter)
void internalCreate ( )
inlineprotected

Definition at line 371 of file qsharedpointer_impl.h.

void internalFinishConstruction ( T *  ptr)
inlineprotected

Definition at line 378 of file qsharedpointer_impl.h.

379  {
381 #ifdef QT_SHAREDPOINTER_TRACK_POINTERS
382  if (ptr) internalSafetyCheckAdd2(d, ptr);
383 #endif
384  if (ptr) d->setQObjectShared(ptr, true);
385  }
Q_CORE_EXPORT void internalSafetyCheckAdd2(const void *, const volatile void *)
Q_CORE_EXPORT void setQObjectShared(const QObject *, bool enable)
void internalCopy ( const ExternalRefCount< X > &  other)
inlineprotected

Definition at line 404 of file qsharedpointer_impl.h.

405  {
406  Data *o = other.d;
407  T *actual = other.value;
408  if (o)
409  other.ref();
410  qSwap(d, o);
411  qSwap(this->value, actual);
412  deref(o, actual);
413  }
GLsizei const GLfloat * value
Definition: GLee.h:1742
void qSwap(QSharedPointer< T > &p1, QSharedPointer< T > &p2)
void internalSwap ( ExternalRefCount< T > &  other)
inlineprotected

Definition at line 415 of file qsharedpointer_impl.h.

416  {
417  qSwap(d, other.d);
418  qSwap(this->value, other.value);
419  }
GLsizei const GLfloat * value
Definition: GLee.h:1742
void qSwap(QSharedPointer< T > &p1, QSharedPointer< T > &p2)
void ref ( ) const
inlineprotected
void internalSet ( Data o,
T *  actual 
)
inlineprotected

Definition at line 430 of file qsharedpointer_impl.h.

431  {
432  if (o) {
433  // increase the strongref, but never up from zero
434  // or less (-1 is used by QWeakPointer on untracked QObject)
435  register int tmp = o->strongref;
436  while (tmp > 0) {
437  // try to increment from "tmp" to "tmp + 1"
438  if (o->strongref.testAndSetRelaxed(tmp, tmp + 1))
439  break; // succeeded
440  tmp = o->strongref; // failed, try again
441  }
442 
443  if (tmp > 0)
444  o->weakref.ref();
445  else
446  o = 0;
447  }
448 
449  qSwap(d, o);
450  qSwap(this->value, actual);
451  if (!d || d->strongref == 0)
452  this->value = 0;
453 
454  // dereference saved data
455  deref(o, actual);
456  }
GLsizei const GLfloat * value
Definition: GLee.h:1742
void qSwap(QSharedPointer< T > &p1, QSharedPointer< T > &p2)

Friends And Related Function Documentation

friend class ExternalRefCount
friend

Definition at line 424 of file qsharedpointer_impl.h.

class QT_PREPEND_NAMESPACE ( QWeakPointer  )
friend
QSharedPointer<X> copyAndSetPointer ( X *  ptr,
const QSharedPointer< Y > &  src 
)
friend

Member Data Documentation

Data* d
protected

Definition at line 458 of file qsharedpointer_impl.h.


The documentation for this class was generated from the following file: