![]() |
CopperSpice API
1.8.1
|
Represents a pointer to an implicitly shared object. More...
Public Typedefs | |
typedef T * | pointer |
typedef T | Type |
Public Methods | |
QSharedDataPointer () | |
QSharedDataPointer (const QSharedDataPointer< T > &other) | |
QSharedDataPointer (QSharedDataPointer &&other) | |
QSharedDataPointer (T *data) | |
~QSharedDataPointer () | |
const T * | constData () const |
T * | data () |
const T * | data () const |
void | detach () |
operator const T * () const | |
operator T * () | |
bool | operator! () const |
bool | operator!= (const QSharedDataPointer< T > &other) const |
T & | operator* () |
const T & | operator* () const |
T * | operator-> () |
const T * | operator-> () const |
QSharedDataPointer< T > & | operator= (const QSharedDataPointer< T > &other) |
QSharedDataPointer< T > & | operator= (QSharedDataPointer< T > &&other) |
QSharedDataPointer & | operator= (T *other) |
bool | operator== (const QSharedDataPointer< T > &other) const |
void | swap (QSharedDataPointer &other) |
Protected Methods | |
T * | clone () |
The QSharedDataPointer class represents a pointer to an implicitly shared object. QSharedDataPointer<T> simplifies the process of writing your own implicitly shared classes. QSharedDataPointer implements thread safe reference counting.
This example shows an implicitly shared implementation of the class Employee
.
Employee
to have a single data member of type QSharedDataPointer<EmployeeData>
. EmployeeData
class derived from QSharedData to contain all the data members which would typically have been declared in the Employee
class. The copy constructor for Employee
is not strictly required in this example because a definition of the class EmployeeData
is in scope when the class Employee
is defined. However, it is common to only have a forward declaration for the data in scope so the copy constructor should be explicitly defined.
Implementing a class which uses copy on write has significant drawbacks and is not recommended.
QSharedDataPointer< T >::pointer |
Typedef for T*.
QSharedDataPointer< T >::Type |
Typedef for T.
|
inline |
Constructs a QSharedDataPointer initialized with a null data pointer.
|
inline |
Decrements the reference count of the shared data object. If the reference count becomes 0 the object is deleted.
|
inlineexplicit |
Constructs a QSharedDataPointer with the data pointer set to data and increments the reference count.
|
inline |
Sets the data pointer of this to the data pointer in other and increments the reference count of the shared data object.
|
inline |
Move constructs a new QSharedDataPointer from other.
|
inlineprotected |
Creates and returns a deep copy of the current data. This method is called by detach() when the reference count is greater than 1 in order to create the new copy. This method uses operator new and calls the copy constructor of the type T.
This method is provided so that you may support "virtual copy constructors" for your own types.
In order to do so declare a template specialization of this method for your own type. In this example, the template specialization for the clone() method calls the EmployeeData::clone() virtual method. A class derived from EmployeeData could override that method and return the proper polymorphic type.
|
inline |
|
inline |
Returns a pointer to the shared data object. This method calls detach().
|
inline |
Returns a pointer to the shared data object. This method does not call detach().
|
inline |
If the shared data object reference count is greater than 1, this method creates a deep copy of the shared data object and sets the current QSharedDataPointer to the copy.
|
inline |
Returns a pointer to the shared data object. This method does not call detach().
|
inline |
Returns a pointer to the shared data object. This method calls detach().
|
inline |
Returns true if the current QSharedDataPointer is null.
|
inline |
Returns true if other and the current QSharedDataPointer point to different objects. This method does not call detach().
|
inline |
Returns a lvalue reference to the object. This method calls detach().
|
inline |
Returns a const reference to the object. This method does not call detach().
|
inline |
Returns a pointer to the object. This method calls detach().
|
inline |
Returns a const pointer to the object. This method does not call detach().
|
inline |
Copy assigns from other and returns a reference to this object.
The reference count is incremented and the shared data is decremented. If the reference count of the old shared data object becomes 0 then the old shared data object is deleted.
|
inline |
Move assigns from other and returns a reference to this object.
|
inline |
Sets the current QSharedDataPointer 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 then the old shared data object is deleted.
|
inline |
Returns true if other and the current QSharedDataPointer, point to the same object. This method does not call detach().
|
inline |
Swap this instance's shared data pointer with the shared data pointer in other.