CopperSpice API  1.7.2
QExplicitlySharedDataPointer< T > Class Template Reference

The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object. More...

Public Typedefs

typedef T * pointer
 
typedef T Type
 

Public Methods

 QExplicitlySharedDataPointer ()
 
 QExplicitlySharedDataPointer (const QExplicitlySharedDataPointer< T > &other)
 
template<class X >
 QExplicitlySharedDataPointer (const QExplicitlySharedDataPointer< X > &other)
 
 QExplicitlySharedDataPointer (QExplicitlySharedDataPointer &&other)
 
 QExplicitlySharedDataPointer (T *data)
 
 ~QExplicitlySharedDataPointer ()
 
const T * constData () const
 
T * data () const
 
void detach ()
 
 operator bool () const
 
bool operator! () const
 
bool operator!= (const QExplicitlySharedDataPointer< T > &other) const
 
bool operator!= (const T *ptr) const
 
T & operator* () const
 
T * operator-> ()
 
T * operator-> () const
 
QExplicitlySharedDataPointer< T > & operator= (const QExplicitlySharedDataPointer< T > &other)
 
QExplicitlySharedDataPointer< T > & operator= (QExplicitlySharedDataPointer< T > &&other)
 
QExplicitlySharedDataPointer & operator= (T *other)
 
bool operator== (const QExplicitlySharedDataPointer< T > &other) const
 
bool operator== (const T *ptr) const
 
void reset ()
 
void swap (QExplicitlySharedDataPointer &other)
 

Protected Methods

T * clone ()
 

Detailed Description

template<class T>
class QExplicitlySharedDataPointer< T >

The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object.

QExplicitlySharedDataPointer<T> makes writing your own explicitly shared classes easy. QExplicitlySharedDataPointer implements thread-safe reference counting, ensuring that adding QExplicitlySharedDataPointers to your classes will not make them stop being conditionally thread safe.

Except for one big difference, QExplicitlySharedDataPointer is just like QSharedDataPointer. The big difference is that member functions of QExplicitlySharedDataPointer do not do the automatic copy on write operation (detach()) that non-const members of QSharedDataPointer do before allowing the shared data object to be modified. There is a detach() function available, but if you really want to detach(), you have to call it yourself. This means that QExplicitlySharedDataPointers behave like regular C++ pointers, except that by doing reference counting and not deleting the shared data object until the reference count is 0, they avoid the dangling pointer problem.

If you use this class and you are calling detach() frequently, consider using QSharedDataPointer instead.

See also
QSharedData, QSharedDataPointer

Member Typedef Documentation

template<class T >
QExplicitlySharedDataPointer< T >::pointer

A typedef for T *.

template<class T >
QExplicitlySharedDataPointer< T >::Type

A typedef for T.

Constructor & Destructor Documentation

template<class T >
QExplicitlySharedDataPointer< T >::QExplicitlySharedDataPointer ( )
inline

Constructs a QExplicitlySharedDataPointer initialized with a null d pointer.

template<class T >
QExplicitlySharedDataPointer< T >::~QExplicitlySharedDataPointer ( )
inline

Decrements the reference count of the shared data object. If the reference count becomes 0, the shared data object is deleted. This is then destroyed.

template<class T >
QExplicitlySharedDataPointer< T >::QExplicitlySharedDataPointer ( T *  data)
inlineexplicit

Constructs a QExplicitlySharedDataPointer with d pointer set to sharedData and increments sharedData's reference count.

template<class T >
QExplicitlySharedDataPointer< T >::QExplicitlySharedDataPointer ( const QExplicitlySharedDataPointer< T > &  other)
inline

This standard copy constructor sets the d pointer of this to the d pointer in other and increments the reference count of the shared data object.

template<class T >
template<class X >
QExplicitlySharedDataPointer< T >::QExplicitlySharedDataPointer ( const QExplicitlySharedDataPointer< X > &  other)
inline

This copy constructor is different in that it allows other to be a different type of explicitly shared data pointer but one that has a compatible shared data object. It performs a static cast of the d pointer in other and sets the d pointer of this to the converted d pointer. It increments the reference count of the shared data object.

template<class T >
QExplicitlySharedDataPointer< T >::QExplicitlySharedDataPointer ( QExplicitlySharedDataPointer< T > &&  other)
inline

Move constructs a new QExplicitlySharedDataPointer from other.

Method Documentation

template<class T >
T * QExplicitlySharedDataPointer< T >::clone ( )
inlineprotected

Creates and returns a deep copy of the current data. This function is called by detach() when the reference count is greater than 1 in order to create the new copy. This function uses the operator new and calls the copy constructor of the type T.

See also
QSharedDataPointer::clone()
template<class T >
const T * QExplicitlySharedDataPointer< T >::constData ( ) const
inline

Returns a const pointer to the shared data object.

See also
data()
template<class T >
T * QExplicitlySharedDataPointer< T >::data ( ) const
inline

Returns a pointer to the shared data object.

template<class T >
void QExplicitlySharedDataPointer< T >::detach ( )
inline

If the shared data object's reference count is greater than 1, this function creates a deep copy of the shared data object and sets the d pointer of this to the copy.

Because QExplicitlySharedDataPointer does not do the automatic copy on write operations that members of QSharedDataPointer do, detach() is not called automatically anywhere in the member functions of this class. If you find that you are calling detach() everywhere in your code, consider using QSharedDataPointer instead.

template<class T >
QExplicitlySharedDataPointer< T >::operator bool ( ) const
inline

Returns true if the d pointer of this is not null.

template<class T >
bool QExplicitlySharedDataPointer< T >::operator! ( ) const
inline

Returns true if the d pointer of this is null.

template<class T >
bool QExplicitlySharedDataPointer< T >::operator!= ( const QExplicitlySharedDataPointer< T > &  other) const
inline

Returns true if other and this do not have the same d pointer.

template<class T >
bool QExplicitlySharedDataPointer< T >::operator!= ( const T *  ptr) const
inline

Returns true if the d pointer of this is not ptr.

template<class T >
T & QExplicitlySharedDataPointer< T >::operator* ( ) const
inline

Provides access to the shared data object's members.

template<class T >
T * QExplicitlySharedDataPointer< T >::operator-> ( )
inline

Provides access to the shared data object's members.

template<class T >
T * QExplicitlySharedDataPointer< T >::operator-> ( ) const
inline

Provides const access to the shared data object's members.

template<class T >
QExplicitlySharedDataPointer< T > & QExplicitlySharedDataPointer< T >::operator= ( const QExplicitlySharedDataPointer< T > &  other)
inline

Assigns other to the current QSharedDataPointer and increments the reference count. The reference count of the old shared data object is decremented. If the reference count of the old shared data object becomes 0, the old shared data object is deleted.

template<class T >
QExplicitlySharedDataPointer< T > & QExplicitlySharedDataPointer< T >::operator= ( QExplicitlySharedDataPointer< T > &&  other)
inline

Move assigns from other and returns a reference to this object.

template<class T >
QExplicitlySharedDataPointer & QExplicitlySharedDataPointer< T >::operator= ( T *  other)
inline

Sets the current QExplicitlySharedDataPointer to other and increments the reference count. The reference count of the old shared data is decremented. If the reference count of the old shared data object becomes 0, the old shared data object is deleted.

template<class T >
bool QExplicitlySharedDataPointer< T >::operator== ( const QExplicitlySharedDataPointer< T > &  other) const
inline

Returns true if this object points to the same object as other.

template<class T >
bool QExplicitlySharedDataPointer< T >::operator== ( const T *  ptr) const
inline

Returns true if this object points to the same object as ptr.

template<class T >
void QExplicitlySharedDataPointer< T >::reset ( )
inline

Resets this to be null. i.e., this function sets the d pointer of this to 0, but first it decrements the reference count of the shared data object and deletes the shared data object if the reference count became 0.

template<class T >
void QExplicitlySharedDataPointer< T >::swap ( QExplicitlySharedDataPointer< T > &  other)
inline

Swap this instance's explicitly shared data pointer with the explicitly shared data pointer in other.