kdecore Library API Documentation

KStaticDeleter< type > Class Template Reference

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

#include <kstaticdeleter.h>

Inheritance diagram for KStaticDeleter< type >:

Inheritance graph
[legend]
Collaboration diagram for KStaticDeleter< type >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

Detailed Description

template<class type>
class KStaticDeleter< type >

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

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

A typical use is
 static KStaticDeleter<MyClass> sd;

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

Definition at line 74 of file kstaticdeleter.h.


Member Function Documentation

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

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

If the given object is 0, the former registration 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 85 of file kstaticdeleter.h.

References KGlobal::registerStaticDeleter(), and KGlobal::unregisterStaticDeleter().

Referenced by KCmdLineArgs::init(), and KCmdLineArgs::loadAppArgs().

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

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

If the given object is 0, the former registration 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

Definition at line 104 of file kstaticdeleter.h.

References KGlobal::registerStaticDeleter(), and KGlobal::unregisterStaticDeleter().

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

Destructs the object.

This has the same effect as deleting the KStaticDeleter.

Reimplemented from KStaticDeleterBase.

Definition at line 120 of file kstaticdeleter.h.


The documentation for this class was generated from the following file:
KDE Logo
This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jul 2 13:03:06 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003