[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 835 of file klfutil.h.

Member Typedef Documentation

◆ Pointer

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

Definition at line 838 of file klfutil.h.

Constructor & Destructor Documentation

◆ KLFSyncGuardPtr() [1/3]

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

Definition at line 840 of file klfutil.h.

◆ ~KLFSyncGuardPtr()

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

Definition at line 844 of file klfutil.h.

◆ KLFSyncGuardPtr() [2/3]

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

Definition at line 848 of file klfutil.h.

◆ KLFSyncGuardPtr() [3/3]

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

Definition at line 852 of file klfutil.h.

Member Function Documentation

◆ invalidate()

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

Definition at line 908 of file klfutil.h.

References KLFPointerGuard::ptr.

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

◆ operator const T *()

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

Definition at line 866 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

◆ operator T*()

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

Definition at line 864 of file klfutil.h.

◆ operator()() [1/2]

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

Definition at line 869 of file klfutil.h.

◆ operator()() [2/2]

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

Definition at line 871 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

◆ operator*() [1/2]

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

Definition at line 874 of file klfutil.h.

◆ operator*() [2/2]

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

Definition at line 876 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

◆ operator->() [1/2]

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

Definition at line 879 of file klfutil.h.

◆ operator->() [2/2]

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

Definition at line 881 of file klfutil.h.

References KLFSyncGuardPtr< T >::ptr().

◆ operator=() [1/2]

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

Definition at line 900 of file klfutil.h.

References KLF_ASSERT_CONDITION, and KLFPointerGuard::ptr.

◆ operator=() [2/2]

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

Definition at line 885 of file klfutil.h.

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

◆ ptr()

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

◆ reset()

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

Definition at line 914 of file klfutil.h.

References KLFRefPtr< T >::setNull().


The documentation for this class was generated from the following file:
KLFSyncGuardPtr
Store a guarded pointer, synchronizing other copies of this pointer.
Definition: klfutil.h:835
QString

Generated by doxygen 1.8.16