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

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

#include <klfutil.h>

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");
{
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

◆ Pointer

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

Definition at line 839 of file klfutil.h.

Constructor & Destructor Documentation

◆ KLFSyncGuardPtr() [1/3]

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

Definition at line 841 of file klfutil.h.

◆ ~KLFSyncGuardPtr()

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

Definition at line 845 of file klfutil.h.

◆ KLFSyncGuardPtr() [2/3]

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

Definition at line 849 of file klfutil.h.

◆ KLFSyncGuardPtr() [3/3]

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

Definition at line 853 of file klfutil.h.

Member Function Documentation

◆ invalidate()

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

Definition at line 909 of file klfutil.h.

◆ operator const T *()

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

Definition at line 867 of file klfutil.h.

◆ operator T*()

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

Definition at line 865 of file klfutil.h.

◆ operator()() [1/2]

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

Definition at line 870 of file klfutil.h.

◆ operator()() [2/2]

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

Definition at line 872 of file klfutil.h.

◆ operator*() [1/2]

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

Definition at line 875 of file klfutil.h.

◆ operator*() [2/2]

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

Definition at line 877 of file klfutil.h.

◆ operator->() [1/2]

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

Definition at line 880 of file klfutil.h.

◆ operator->() [2/2]

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

Definition at line 882 of file klfutil.h.

◆ operator=() [1/2]

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

Definition at line 886 of file klfutil.h.

References klfWarning, and KLFPointerGuard::ptr.

◆ operator=() [2/2]

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.

◆ ptr()

template<class T>
Pointer KLFSyncGuardPtr< T >::ptr ( )
inline

Definition at line 858 of file klfutil.h.

◆ reset()

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

Definition at line 915 of file klfutil.h.


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

Generated by doxygen 1.8.13