- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- Class List
- Class Hierarchy
- Class Members

Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends

# ExternalRefCount< T > Class Template Reference

Search for all occurrences

## Detailed Description

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

Definition at line 321 of file qsharedpointer_impl.h.

`#include <qsharedpointer_impl.h>`

Inheritance diagram for ExternalRefCount< T >:
[legend]

List of all members.

## Protected Types
typedef ExternalRefCountData | Data
## Protected Member Functions
void | ref () const
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 (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 | internalSet (Data *o, T *actual)
## Static Protected Member Functions
static void | deref (Data *d, T *value)
## Protected Attributes
Data * | d
## Friends
class | ExternalRefCount
template<class X >
class | QT_PREPEND_NAMESPACE (QWeakPointer)
template<class X , class Y >
QSharedPointer< X > | copyAndSetPointer (X *ptr, const QSharedPointer< Y > &src)

## Member Typedef Documentation

typedef ExternalRefCountData Data `[protected]`

Search for all occurrences

Definition at line 324 of file qsharedpointer_impl.h.

## Constructor & Destructor Documentation

ExternalRefCount | ( |  | ) | `[inline, protected]`

Definition at line 379 of file qsharedpointer_impl.h.

    : d(0) { }

ExternalRefCount | ( | Qt::Initialization | i | ) | `[inline, protected]`

Definition at line 380 of file qsharedpointer_impl.h.

    : Basic<T>(i) { }

ExternalRefCount | ( | const ExternalRefCount< T > & | other | ) | `[inline, protected]`

Definition at line 381 of file qsharedpointer_impl.h.

                                                                      : Basic<T>(other), d(other.d)
            { if (d) ref(); }

ExternalRefCount | ( | const ExternalRefCount< X > & | other | ) | `[inline, protected]`

Definition at line 384 of file qsharedpointer_impl.h.

                                                                      : Basic<T>(other.value), d(other.d)
            { if (d) ref(); }

~ExternalRefCount | ( |  | ) | `[inline, protected]`

Definition at line 386 of file qsharedpointer_impl.h.

    { deref(); }

## Member Function Documentation

void ref | ( |  | ) | const `[inline, protected]`

Search for all occurrences

Definition at line 326 of file qsharedpointer_impl.h.

    { d->weakref.ref(); d->strongref.ref(); }

void deref | ( |  | ) | `[inline, protected]`

Search for all occurrences

Definition at line 327 of file qsharedpointer_impl.h.

            { deref(d, this->value); }

static void deref | ( | Data * | d,
|  | T * | value
| ) |  | `[inline, static, protected]`

Search for all occurrences

Definition at line 329 of file qsharedpointer_impl.h.

            {
                if (!d) return;
                if (!d->strongref.deref()) {
                    if (!d->destroy())
                        delete value;
                }
                if (!d->weakref.deref())
                    delete d;
            }

void internalConstruct | ( | T * | ptr | ) | `[inline, protected]`

Search for all occurrences

Reimplemented from Basic< T >.

Definition at line 340 of file qsharedpointer_impl.h.

            {
    #ifdef QT_SHAREDPOINTER_TRACK_POINTERS
                internalConstruct<void (*)(T *)>(ptr, normalDeleter);
    #else
                if (ptr)
                    d = new Data;
                else
                    d = 0;
                internalFinishConstruction(ptr);
    #endif
            }

void internalConstruct | ( | T * | ptr,
|  | Deleter | deleter
| ) |  | `[inline, protected]`

Search for all occurrences

Definition at line 354 of file qsharedpointer_impl.h.

            {
                if (ptr)
                    d = ExternalRefCountWithCustomDeleter<T, Deleter>::create(ptr, deleter);
                else
                    d = 0;
                internalFinishConstruction(ptr);
            }

void internalCreate | ( |  | ) | `[inline, protected]`

Search for all occurrences

Definition at line 363 of file qsharedpointer_impl.h.

            {
                T *ptr;
                d = ExternalRefCountWithContiguousData<T>::create(&ptr);
                Basic<T>::internalConstruct(ptr);
            }

void internalFinishConstruction | ( | T * | ptr | ) | `[inline, protected]`

Search for all occurrences

Definition at line 370 of file qsharedpointer_impl.h.

            {
                Basic<T>::internalConstruct(ptr);
                if (ptr) d->setQObjectShared(ptr, true);
    #ifdef QT_SHAREDPOINTER_TRACK_POINTERS
                if (ptr) internalSafetyCheckAdd2(d, ptr);
    #endif
            }

void internalCopy | ( | const ExternalRefCount< X > & | other | ) | `[inline, protected]`

Search for all occurrences

Definition at line 389 of file qsharedpointer_impl.h.

            {
                internalSet(other.d, other.data());
            }

void internalSwap | ( | ExternalRefCount< T > & | other | ) | `[inline, protected]`

Search for all occurrences

Definition at line 394 of file qsharedpointer_impl.h.

            {
                qSwap(d, other.d);
                qSwap(this->value, other.value);
            }

void internalSet | ( | Data * | o,
|  | T * | actual
| ) |  | `[inline, protected]`

Search for all occurrences

Definition at line 408 of file qsharedpointer_impl.h.

            {
                if (o) {
                    // increase the strongref, but never up from zero
                    // or less (-1 is used by QWeakPointer on untracked QObject)
                    register int tmp = o->strongref;
                    while (tmp > 0) {
                        // try to increment from "tmp" to "tmp + 1"
                        if (o->strongref.testAndSetRelaxed(tmp, tmp + 1))
                            break;   // succeeded
                        tmp = o->strongref;  // failed, try again
                    }

                    if (tmp > 0)
                        o->weakref.ref();
                    else
                        o = 0;
                }

                qSwap(d, o);
                qSwap(this->value, actual);
                if (!d || d->strongref == 0)
                    this->value = 0;

                // dereference saved data
                deref(o, actual);
            }

## Friends And Related Function Documentation

friend class ExternalRefCount `[friend]`

Definition at line 403 of file qsharedpointer_impl.h.

class QT_PREPEND_NAMESPACE | ( | QWeakPointer |  | ) | `[friend]`

Search for all occurrences

Reimplemented from Basic< T >.

QSharedPointer<X> copyAndSetPointer | ( | X * | ptr,
|  | const QSharedPointer< Y > & | src
| ) |  | `[friend]`

Search for all occurrences

## Member Data Documentation

Data* d `[protected]`

Search for all occurrences

Definition at line 436 of file qsharedpointer_impl.h.

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

- QtCore/qsharedpointer_impl.h