Skip to content
Skip to link menu
Trinity API Reference
Trinity API Reference
kdecore
kdecore
kdecore
kstaticdeleter.h
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 <kglobal.h>
27
39
class
KDECORE_EXPORT
KStaticDeleterBase
{
40
public
:
41
virtual
~
KStaticDeleterBase
() { }
47
virtual
void
destructObject();
48
};
49
74
template
<
class
type>
class
KStaticDeleter
:
public
KStaticDeleterBase
{
75
public
:
76
KStaticDeleter
() { deleteit = 0; globalReference = 0; array =
false
; }
85
KDE_DEPRECATED type *
setObject
( type *obj,
bool
isArray =
false
) {
86
deleteit = obj;
87
globalReference = 0;
88
array = isArray;
89
if
(obj)
90
KGlobal::registerStaticDeleter
(
this
);
91
else
92
KGlobal::unregisterStaticDeleter
(
this
);
93
return
obj;
94
}
104
type *
setObject
( type* & globalRef, type *obj,
bool
isArray =
false
) {
105
globalReference = &globalRef;
106
deleteit = obj;
107
array = isArray;
108
if
(obj)
109
KGlobal::registerStaticDeleter
(
this
);
110
else
111
KGlobal::unregisterStaticDeleter
(
this
);
112
globalRef = obj;
113
return
obj;
114
}
115
120
virtual
void
destructObject
() {
121
if
(globalReference)
122
*globalReference = 0;
123
if
(array)
124
delete
[] deleteit;
125
else
126
delete
deleteit;
127
deleteit = 0;
128
}
129
virtual
~
KStaticDeleter
() {
130
KGlobal::unregisterStaticDeleter
(
this
);
131
destructObject
();
132
}
133
private
:
134
type *deleteit;
135
type **globalReference;
136
bool
array;
137
};
138
139
#endif
kdecore
Skip menu "kdecore"
Main Page
Modules
Namespace List
Class Hierarchy
Alphabetical List
Class List
File List
Namespace Members
Class Members
Related Pages
kdecore
Skip menu "kdecore"
arts
dcop
dnssd
interfaces
interface
library
kspeech
ktexteditor
kabc
kate
kcmshell
kdecore
kded
kdefx
kdeprint
kdesu
kdeui
kdoctools
khtml
kimgio
kinit
kio
bookmarks
httpfilter
kfile
kio
kioexec
kpasswdserver
kssl
kioslave
http
kjs
kmdi
kmdi
knewstuff
kparts
krandr
kresources
kspell2
kunittest
kutils
kwallet
libkmid
libkscreensaver