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

KDE3Support

  • kde3support
  • kdecore
k3staticdeleter.h
Go to the documentation of this file.
1/*
2 * This file is part of the KDE Libraries
3 * Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
4 * 2001 KDE Team
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef _KSTATIC_DELETER_H_
24#define _KSTATIC_DELETER_H_
25
26#include <kde3support_export.h>
27
28class K3StaticDeleterBase;
29
30namespace K3StaticDeleterHelpers
31{
38 KDE3SUPPORT_EXPORT void registerStaticDeleter(K3StaticDeleterBase *d);
39
46 KDE3SUPPORT_EXPORT void unregisterStaticDeleter(K3StaticDeleterBase *d);
47
54 KDE3SUPPORT_EXPORT void deleteStaticDeleters();
55} // namespace K3StaticDeleterHelpers
56
68class KDE3SUPPORT_EXPORT K3StaticDeleterBase {
69public:
70 virtual ~K3StaticDeleterBase();
76 virtual void destructObject();
77};
78
115template<class type> class KDE_DEPRECATED K3StaticDeleter : public K3StaticDeleterBase {
116public:
121 K3StaticDeleter() { deleteit = 0; globalReference = 0; array = false; }
122
131 KDE_DEPRECATED type *setObject( type *obj, bool isArray = false) {
132 deleteit = obj;
133 globalReference = 0;
134 array = isArray;
135 if (obj)
136 K3StaticDeleterHelpers::registerStaticDeleter(this);
137 else
138 K3StaticDeleterHelpers::unregisterStaticDeleter(this);
139 return obj;
140 }
141
152 type *setObject( type* & globalRef, type *obj, bool isArray = false) {
153 globalReference = &globalRef;
154 deleteit = obj;
155 array = isArray;
156 if (obj)
157 K3StaticDeleterHelpers::registerStaticDeleter(this);
158 else
159 K3StaticDeleterHelpers::unregisterStaticDeleter(this);
160 globalRef = obj;
161 return obj;
162 }
163
168 virtual void destructObject() {
169 if (globalReference)
170 *globalReference = 0;
171 if (array)
172 delete [] deleteit;
173 else
174 delete deleteit;
175 deleteit = 0;
176 }
177
182 virtual ~K3StaticDeleter() {
183 K3StaticDeleterHelpers::unregisterStaticDeleter(this);
184 destructObject();
185 }
186private:
187 type *deleteit;
188 type **globalReference;
189 bool array;
190};
191
192#endif
K3StaticDeleterBase
Base class for K3StaticDeleter.
Definition: k3staticdeleter.h:68
K3StaticDeleter
Automatically deletes an object on termination.
Definition: k3staticdeleter.h:115
K3StaticDeleter::destructObject
virtual void destructObject()
Destructs the registered object.
Definition: k3staticdeleter.h:168
K3StaticDeleter::setObject
type * setObject(type *obj, bool isArray=false)
Sets the object to delete and registers that object to K3StaticDeleterHelpers.
Definition: k3staticdeleter.h:131
K3StaticDeleter::setObject
type * setObject(type *&globalRef, type *obj, bool isArray=false)
Sets the object to delete and registers the object to be deleted to K3StaticDeleterHelpers.
Definition: k3staticdeleter.h:152
K3StaticDeleter::~K3StaticDeleter
virtual ~K3StaticDeleter()
Destructor.
Definition: k3staticdeleter.h:182
K3StaticDeleter::K3StaticDeleter
K3StaticDeleter()
Constructor.
Definition: k3staticdeleter.h:121
kde3support_export.h
K3StaticDeleterHelpers
Definition: k3staticdeleter.h:31
K3StaticDeleterHelpers::deleteStaticDeleters
void deleteStaticDeleters()
Calls K3StaticDeleterBase::destructObject() on all registered static deleters and unregisters them al...
Definition: k3staticdeleter.cpp:76
K3StaticDeleterHelpers::registerStaticDeleter
void registerStaticDeleter(K3StaticDeleterBase *d)
Registers a static deleter.
Definition: k3staticdeleter.cpp:60
K3StaticDeleterHelpers::unregisterStaticDeleter
void unregisterStaticDeleter(K3StaticDeleterBase *d)
Unregisters a static deleter.
Definition: k3staticdeleter.cpp:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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