QtCore/qatomic.h File Reference

qatomic.h File Reference

Classes

class  QAtomicInt
 
class  QAtomicPointer< T >
 

Functions

template<typename T >
void qAtomicAssign (T *&d, T *x)
 This is a helper for the assignment operators of implicitly shared classes. More...
 
template<typename T >
void qAtomicDetach (T *&d)
 This is a helper for the detach method of implicitly shared classes. More...
 

Function Documentation

void qAtomicAssign ( T *&  d,
T *  x 
)
inline

This is a helper for the assignment operators of implicitly shared classes.

Your assignment operator should look like this:

Definition at line 195 of file qatomic.h.

196 {
197  if (d == x)
198  return;
199  x->ref.ref();
200  if (!d->ref.deref())
201  delete d;
202  d = x;
203 }
GLenum GLint x
Definition: GLee.h:876
void qAtomicDetach ( T *&  d)
inline

This is a helper for the detach method of implicitly shared classes.

Your private class needs a copy constructor which copies the members and sets the refcount to 1. After that, your detach function should look like this:

Definition at line 214 of file qatomic.h.

215 {
216  if (d->ref == 1)
217  return;
218  T *x = d;
219  d = new T(*d);
220  if (!x->ref.deref())
221  delete x;
222 }
GLenum GLint x
Definition: GLee.h:876

Go to the source code of this file.