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

KDE3Support

Public Member Functions | List of all members
K3StaticDeleter< type > Class Template Reference

#include <k3staticdeleter.h>

Inheritance diagram for K3StaticDeleter< type >:
Inheritance graph
[legend]

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)
 
- Public Member Functions inherited from K3StaticDeleterBase
virtual ~K3StaticDeleterBase ()
 

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 ( )
inlinevirtual

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 ( )
inlinevirtual

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 *  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.

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
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

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 API Reference

Skip menu "kdelibs API Reference"
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal