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

KDE3Support

K3StaticDeleter< type > Class Template Reference

Automatically deletes an object on termination. More...

#include <k3staticdeleter.h>

Inheritance diagram for K3StaticDeleter< type >:

Inheritance graph
[legend]

List of all members.


Public Member Functions

virtual void destructObject ()
 K3StaticDeleter ()
type * setObject (type *&globalRef, type *obj, bool isArray=false)
KDE_DEPRECATED type * setObject (type *obj, bool isArray=false)
virtual ~K3StaticDeleter ()

Detailed Description

template<class type>
class K3StaticDeleter< type >

Automatically deletes an object on termination.

Little helper class to clean up static objects that are held as a pointer.

Static deleters are used to manage static resources. They can register themselves with K3StaticDeleterHelpers. K3StaticDeleterHelpers will call destructObject() when K3StaticDeleterHelpers::deleteStaticDeleters() is called or when the process finishes.

When the library is unloaded, or the app is terminated, all static deleters will be destroyed, which in turn destroys those static objects properly. There are some rules that you should accept in the K3StaticDeleter managed class:

  • Don't rely on the global reference variable in the destructor of the object, it will be '0' at destruction time.
  • Don't rely on other K3StaticDeleter managed objects in the destructor of the object, because they may be destroyed before your destructor get called. This one can be tricky, because you might not know that you are actually using a K3StaticDeleter managed class. So try to keep your destructor simple.
A typical use is
 static K3StaticDeleter<MyClass> sd;

 MyClass &MyClass::self() {
   if (!_self) { sd.setObject(_self, new MyClass()); }
   return *_self;
 }

Warning:
Don't delete an object which is managed by K3StaticDeleter without calling setObject() with a null pointer.
Deprecated:
Use K_GLOBAL_STATIC instead of K3StaticDeleter.

Definition at line 115 of file k3staticdeleter.h.


Constructor & Destructor Documentation

template<class type >
K3StaticDeleter< type >::K3StaticDeleter (  )  [inline]

Constructor.

Initializes the K3StaticDeleter. Note that the static deleter is not registered by the constructor.

Definition at line 121 of file k3staticdeleter.h.

template<class type >
virtual K3StaticDeleter< type >::~K3StaticDeleter (  )  [inline, virtual]

Destructor.

Unregisters the static deleter and destroys the registered object by calling destructObject().

Definition at line 182 of file k3staticdeleter.h.


Member Function Documentation

template<class type >
virtual void K3StaticDeleter< type >::destructObject (  )  [inline, virtual]

Destructs the registered object.

This has the same effect as deleting the K3StaticDeleter.

Reimplemented from K3StaticDeleterBase.

Definition at line 168 of file k3staticdeleter.h.

template<class type >
type* K3StaticDeleter< type >::setObject ( type *&  globalRef,
type *  obj,
bool  isArray = false 
) [inline]

Sets the object to delete and registers the object to be deleted to K3StaticDeleterHelpers.

If the given object is 0, the previously registered object is unregistered.

Parameters:
globalRef the static pointer where this object is stored. This pointer will be reset to 0 after deletion of the object.
obj the object to delete
isArray tells the destructor to delete an array instead of an object
Returns:
the object to delete, obj

Definition at line 152 of file k3staticdeleter.h.

template<class type >
KDE_DEPRECATED type* K3StaticDeleter< type >::setObject ( type *  obj,
bool  isArray = false 
) [inline]

Sets the object to delete and registers that object to K3StaticDeleterHelpers.

If the given object is 0, the formerly registered object is unregistered.

Parameters:
obj the object to delete
isArray tells the destructor to delete an array instead of an object
Deprecated:
See the other setObject variant.

Definition at line 131 of file k3staticdeleter.h.


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

KDE3Support

Skip menu "KDE3Support"
  • Main Page
  • 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
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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