• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

KSharedPtr< T > Class Template Reference

#include <KSharedPtr>

Inheritance diagram for KSharedPtr< T >:

Inheritance graph
[legend]

List of all members.


Detailed Description

template<class T>
class KSharedPtr< T >

Can be used to control the lifetime of an object that has derived QSharedData.

As long a someone holds a KSharedPtr on some QSharedData object it won't become deleted but is deleted once its reference count is 0. This struct emulates C++ pointers virtually perfectly. So just use it like a simple C++ pointer.

The difference with using QSharedDataPointer is that QSharedDataPointer is a building block for implementing a value class with implicit sharing (like QString), whereas KSharedPtr provides refcounting to code that uses pointers.

Author:
Waldo Bastian <bastian@kde.org>

Definition at line 53 of file ksharedptr.h.


Public Member Functions

void attach (T *p)
void clear ()
const T * constData () const
int count () const
const T * data () const
T * data ()
bool isNull () const
bool isUnique () const
 KSharedPtr (const KSharedPtr &o)
 KSharedPtr (T *p)
 KSharedPtr ()
T & operator * ()
const T & operator * () const
 operator bool () const
bool operator!= (const T *p) const
bool operator!= (const KSharedPtr &o) const
T * operator-> ()
const T * operator-> () const
bool operator< (const KSharedPtr &o) const
KSharedPtr< T > & operator= (T *p)
KSharedPtr< T > & operator= (const KSharedPtr &o)
bool operator== (const T *p) const
bool operator== (const KSharedPtr &o) const
 ~KSharedPtr ()

Static Public Member Functions

template<class U>
static KSharedPtr< T > dynamicCast (const KSharedPtr< U > &o)
template<class U>
static KSharedPtr< T > staticCast (const KSharedPtr< U > &o)

Protected Attributes

T * d

Constructor & Destructor Documentation

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

Creates a null pointer.

Definition at line 59 of file ksharedptr.h.

template<class T>
KSharedPtr< T >::KSharedPtr ( T *  p  )  [inline, explicit]

Creates a new pointer.

Parameters:
p the pointer

Definition at line 66 of file ksharedptr.h.

template<class T>
KSharedPtr< T >::KSharedPtr ( const KSharedPtr< T > &  o  )  [inline]

Copies a pointer.

Parameters:
o the pointer to copy

Definition at line 73 of file ksharedptr.h.

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

Unreferences the object that this pointer points to.

If it was the last reference, the object will be deleted.

Definition at line 80 of file ksharedptr.h.


Member Function Documentation

template<class T>
Q_INLINE_TEMPLATE void KSharedPtr< T >::attach ( T *  p  )  [inline]

Attach the given pointer to the current KSharedPtr.

If the previous shared pointer is not owned by any KSharedPtr, it is deleted.

Definition at line 199 of file ksharedptr.h.

template<class T>
Q_INLINE_TEMPLATE void KSharedPtr< T >::clear (  )  [inline]

Clear the pointer, i.e.

make it a null pointer.

Definition at line 210 of file ksharedptr.h.

template<class T>
const T* KSharedPtr< T >::constData (  )  const [inline]

Returns:
a const pointer to the shared object.

Definition at line 111 of file ksharedptr.h.

template<class T>
int KSharedPtr< T >::count (  )  const [inline]

Returns the number of references.

Returns:
the number of references

Definition at line 134 of file ksharedptr.h.

template<class T>
const T* KSharedPtr< T >::data (  )  const [inline]

Returns:
the pointer

Definition at line 106 of file ksharedptr.h.

template<class T>
T* KSharedPtr< T >::data (  )  [inline]

Returns:
the pointer

Definition at line 101 of file ksharedptr.h.

template<class T>
template<class U>
static KSharedPtr<T> KSharedPtr< T >::dynamicCast ( const KSharedPtr< U > &  o  )  [inline, static]

Convert KSharedPtr<U> to KSharedPtr<T>, using a dynamic_cast.

This will compile whenever T* and U* are compatible, i.e. T is a subclass of U or vice-versa. Example syntax: KSharedPtr<T> tPtr; KSharedPtr<U> uPtr = KSharedPtr<U>::dynamicCast( tPtr ); Since a dynamic_cast is used, if U derives from T, and tPtr isn't an instance of U, uPtr will be 0.

Definition at line 178 of file ksharedptr.h.

template<class T>
bool KSharedPtr< T >::isNull (  )  const [inline]

Test if the shared pointer is null.

Returns:
true if the pointer is null, false otherwise.
See also:
opertor (bool)

Definition at line 141 of file ksharedptr.h.

template<class T>
bool KSharedPtr< T >::isUnique (  )  const [inline]

Returns:
Whether this is the only shared pointer pointing to to the pointee, or whether it's shared among multiple shared pointers.

Definition at line 148 of file ksharedptr.h.

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

Definition at line 114 of file ksharedptr.h.

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

Definition at line 113 of file ksharedptr.h.

template<class T>
KSharedPtr< T >::operator bool (  )  const [inline]

Test if the shared pointer is NOT null.

Returns:
true if the shared pointer is NOT null, false otherwise.
See also:
isNull

Definition at line 96 of file ksharedptr.h.

template<class T>
bool KSharedPtr< T >::operator!= ( const T *  p  )  const [inline]

Definition at line 89 of file ksharedptr.h.

template<class T>
bool KSharedPtr< T >::operator!= ( const KSharedPtr< T > &  o  )  const [inline]

Definition at line 84 of file ksharedptr.h.

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

Definition at line 116 of file ksharedptr.h.

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

Definition at line 115 of file ksharedptr.h.

template<class T>
bool KSharedPtr< T >::operator< ( const KSharedPtr< T > &  o  )  const [inline]

Definition at line 85 of file ksharedptr.h.

template<class T>
KSharedPtr<T>& KSharedPtr< T >::operator= ( T *  p  )  [inline]

Definition at line 87 of file ksharedptr.h.

template<class T>
KSharedPtr<T>& KSharedPtr< T >::operator= ( const KSharedPtr< T > &  o  )  [inline]

Definition at line 82 of file ksharedptr.h.

template<class T>
bool KSharedPtr< T >::operator== ( const T *  p  )  const [inline]

Definition at line 88 of file ksharedptr.h.

template<class T>
bool KSharedPtr< T >::operator== ( const KSharedPtr< T > &  o  )  const [inline]

Definition at line 83 of file ksharedptr.h.

template<class T>
template<class U>
static KSharedPtr<T> KSharedPtr< T >::staticCast ( const KSharedPtr< U > &  o  )  [inline, static]

Convert KSharedPtr<U> to KSharedPtr<T>, using a static_cast.

This will compile whenever T* and U* are compatible, i.e. T is a subclass of U or vice-versa. Example syntax: KSharedPtr<T> tPtr; KSharedPtr<U> uPtr = KSharedPtr<U>::staticCast( tPtr );

Definition at line 163 of file ksharedptr.h.


Member Data Documentation

template<class T>
T* KSharedPtr< T >::d [protected]

Definition at line 183 of file ksharedptr.h.


The documentation for this class was generated from the following file:
  • ksharedptr.h

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal