[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
Public Types | Public Member Functions
KLFSyncGuardPtr< T > Class Template Reference

Store a guarded pointer, synchronizing other copies of this pointer. More...

#include <klfutil.h>

List of all members.

Public Types

typedef T * Pointer

Public Member Functions

 KLFSyncGuardPtr ()
 ~KLFSyncGuardPtr ()
 KLFSyncGuardPtr (const KLFSyncGuardPtr &copy)
 KLFSyncGuardPtr (T *obj)
Pointer ptr ()
 operator T * ()
 operator const T * ()
T * operator() ()
const T * operator() () const
T & operator* ()
const T & operator* () const
T * operator-> ()
const T * operator-> () const
Pointer operator= (Pointer p)
const KLFSyncGuardPtroperator= (const KLFSyncGuardPtr &copy)
void invalidate ()
void reset ()

Detailed Description

template<class T>
class KLFSyncGuardPtr< T >

Store a guarded pointer, synchronizing other copies of this pointer.

Stores a pointer to any object. Copies may be made of the KLFSyncGuardPtr<T> pointer and used normally. Once you destroy the pointed object using one of these pointers, then set that pointer to NULL and automatically all copies of that pointer will be set to NULL too.

Minimal example:

  QString * a = new QString("string-A");

  KLFSyncGuardPtr<QString> ptr3;
  {
    KLFSyncGuardPtr<QString> ptr1 = a;
    KLFSyncGuardPtr<QString> ptr2 = ptr1;
    ptr3 = ptr1;
    printf("Pointer 2 is now %p\n", (QString*)ptr2);
    printf("Pointer 2 = %s\n", qPrintable(*ptr2));
    printf("Pointer 3 is now %p\n", (QString*)ptr3);
    printf("Pointer 3 = %s\n", qPrintable(*ptr3));

    ptr1 = NULL;
    printf("Pointer 2 is now %p\n", (QString*)ptr2);
  }
  printf("Pointer 3 is now %p\n", (QString*)ptr3);

Note that if you assign another KLFSyncGuardPtr-guarded pointed object to a KLFSyncGuardPtr which is already tracking a pointer, then a warning is emitted. This is to avoid design flaws where in that case, the assignment will cause the current KLFSyncGuardPtr to become a copy of the new KLFSyncGuardPtr and all copies of the original pointer will become independant and unaffected. Example:

  KLFSyncGuardPtr<Obj> ptr1 = myobject;
  KLFSyncGuardPtr<Obj> ptr2 = ptr1; // ptr2 is a copy of ptr1

  KLFSyncGuardPtr<Obj> otherptr = otherobject; // another sync-guard-ptr object

  ptr1 = otherptr; // this will result in a warning. Indeed, ptr1 now tracks otherobject pointer and
  // leaves myobject. In particular, ptr2, which was a copy of ptr1, is not modified and still points
  // to myobject.

Use reset() to detach from other copies and start fresh again.

Definition at line 836 of file klfutil.h.


Member Typedef Documentation

template<class T>
typedef T* KLFSyncGuardPtr< T >::Pointer

Definition at line 839 of file klfutil.h.


Constructor & Destructor Documentation

template<class T>
KLFSyncGuardPtr< T >::KLFSyncGuardPtr ( ) [inline]

Definition at line 841 of file klfutil.h.

template<class T>
KLFSyncGuardPtr< T >::~KLFSyncGuardPtr ( ) [inline]

Definition at line 845 of file klfutil.h.

template<class T>
KLFSyncGuardPtr< T >::KLFSyncGuardPtr ( const KLFSyncGuardPtr< T > &  copy) [inline]

Definition at line 849 of file klfutil.h.

template<class T>
KLFSyncGuardPtr< T >::KLFSyncGuardPtr ( T *  obj) [inline]

Definition at line 853 of file klfutil.h.


Member Function Documentation

template<class T>
void KLFSyncGuardPtr< T >::invalidate ( ) [inline]

Definition at line 909 of file klfutil.h.

References KLFPointerGuard::ptr.

Referenced by KLFSyncGuardPtr< T >::operator=().

template<class T>
KLFSyncGuardPtr< T >::operator const T * ( ) [inline]

Definition at line 867 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

template<class T>
KLFSyncGuardPtr< T >::operator T * ( ) [inline]

Definition at line 865 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

template<class T>
T* KLFSyncGuardPtr< T >::operator() ( ) [inline]

Definition at line 870 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

template<class T>
const T* KLFSyncGuardPtr< T >::operator() ( ) const [inline]

Definition at line 872 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

template<class T>
T& KLFSyncGuardPtr< T >::operator* ( ) [inline]

Definition at line 875 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

template<class T>
const T& KLFSyncGuardPtr< T >::operator* ( ) const [inline]

Definition at line 877 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

template<class T>
T* KLFSyncGuardPtr< T >::operator-> ( ) [inline]

Definition at line 880 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

template<class T>
const T* KLFSyncGuardPtr< T >::operator-> ( ) const [inline]

Definition at line 882 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

template<class T>
Pointer KLFSyncGuardPtr< T >::operator= ( Pointer  p) [inline]

Definition at line 886 of file klfutil.h.

References KLFSyncGuardPtr< T >::invalidate(), klfWarning, and KLFPointerGuard::ptr.

template<class T>
const KLFSyncGuardPtr& KLFSyncGuardPtr< T >::operator= ( const KLFSyncGuardPtr< T > &  copy) [inline]

Definition at line 901 of file klfutil.h.

References KLF_ASSERT_CONDITION, and KLFPointerGuard::ptr.

template<class T>
Pointer KLFSyncGuardPtr< T >::ptr ( ) [inline]
template<class T>
void KLFSyncGuardPtr< T >::reset ( ) [inline]

Definition at line 915 of file klfutil.h.

References KLFRefPtr< T >::setNull().


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

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net