• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDE3Support

Public Member Functions
K3StaticDeleter Class Reference

#include <k3staticdeleter.h>

Inheritance diagram for K3StaticDeleter:
Inheritance graph
[legend]

List of all members.

Public Member Functions

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

Detailed Description

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.

Constructor & Destructor Documentation

K3StaticDeleter::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.

virtual K3StaticDeleter::~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

virtual void K3StaticDeleter::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.

type* K3StaticDeleter::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:
objthe object to delete
isArraytells the destructor to delete an array instead of an object
Deprecated:
See the other setObject variant.

Definition at line 131 of file k3staticdeleter.h.

type* K3StaticDeleter::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:
globalRefthe static pointer where this object is stored. This pointer will be reset to 0 after deletion of the object.
objthe object to delete
isArraytells the destructor to delete an array instead of an object
Returns:
the object to delete, obj

Definition at line 152 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
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.5
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