Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QExplicitlySharedDataPointer Class Reference

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

 #include <QExplicitlySharedDataPointer>

Note: All functions in this class are reentrant.

This class was introduced in Qt 4.4.

Public Types

typedef Type

Public Functions

QExplicitlySharedDataPointer ()
QExplicitlySharedDataPointer ( T * sharedData )
QExplicitlySharedDataPointer ( const QExplicitlySharedDataPointer<T> & other )
QExplicitlySharedDataPointer ( const QExplicitlySharedDataPointer<X> & other )
~QExplicitlySharedDataPointer ()
const T * constData () const
T * data () const
void detach ()
void reset ()
void swap ( QExplicitlySharedDataPointer & other )
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 & operator= ( T * sharedData )
bool operator== ( const QExplicitlySharedDataPointer<T> & other ) const
bool operator== ( const T * ptr ) const

Protected Functions

T * clone ()

Detailed Description

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 reentrant classes won't make them non-reentrant.

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.

It is instructive to compare QExplicitlySharedDataPointer with QSharedDataPointer by way of an example. Consider the Employee example in QSharedDataPointer, modified to use explicit sharing as explained in the discussion Implicit vs Explicit Sharing.

Note that if you use this class but find you are calling detach() a lot, you probably should be using QSharedDataPointer instead.

In the member function documentation, d pointer always refers to the internal pointer to the shared data object.

See also QSharedData and QSharedDataPointer.

Member Type Documentation

typedef QExplicitlySharedDataPointer::Type

This is the type of the shared data object. The d pointer points to an object of this type.

Member Function Documentation

QExplicitlySharedDataPointer::QExplicitlySharedDataPointer ()

Constructs a QExplicitlySharedDataPointer initialized with a null d pointer.

QExplicitlySharedDataPointer::QExplicitlySharedDataPointer ( T * sharedData )

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

QExplicitlySharedDataPointer::QExplicitlySharedDataPointer ( const QExplicitlySharedDataPointer<T> & other )

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.

QExplicitlySharedDataPointer::QExplicitlySharedDataPointer ( const QExplicitlySharedDataPointer<X> & other )

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.

QExplicitlySharedDataPointer::~QExplicitlySharedDataPointer ()

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.

T * QExplicitlySharedDataPointer::clone () [protected]

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 QSharedDataPointer::clone() for an explanation of how to use it.

This function was introduced in Qt 4.5.

const T * QExplicitlySharedDataPointer::constData () const

Returns a const pointer to the shared data object.

See also data().

T * QExplicitlySharedDataPointer::data () const

Returns a pointer to the shared data object.

void QExplicitlySharedDataPointer::detach ()

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.

void QExplicitlySharedDataPointer::reset ()

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.

void QExplicitlySharedDataPointer::swap ( QExplicitlySharedDataPointer & other )

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

QExplicitlySharedDataPointer::operator bool () const

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

bool QExplicitlySharedDataPointer::operator! () const

Returns true if the d pointer of this is null.

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

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

bool QExplicitlySharedDataPointer::operator!= ( const T * ptr ) const

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

T & QExplicitlySharedDataPointer::operator* () const

Provides access to the shared data object's members.

T * QExplicitlySharedDataPointer::operator-> ()

Provides access to the shared data object's members.

T * QExplicitlySharedDataPointer::operator-> () const

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

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

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

QExplicitlySharedDataPointer & QExplicitlySharedDataPointer::operator= ( T * sharedData )

Sets the d pointer of this to sharedData and increments sharedData's reference count. The reference count of the old shared data object of this is decremented. If the reference count of the old shared data object becomes 0, the old shared data object is deleted.

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

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

bool QExplicitlySharedDataPointer::operator== ( const T * ptr ) const

Returns true if the d pointer of this is ptr.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 44
  2. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
Page suivante

Le blog Digia au hasard

Logo

Déploiement d'applications Qt Commercial sur les tablettes Windows 8

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web