Skip to content
Skip to link menu
Trinity API Reference
Trinity API Reference
tdecore
tdecore
tdecore
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 <tdeglobal.h>
27
39
class
TDECORE_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
TDEGlobal::registerStaticDeleter
(
this
);
91
else
92
TDEGlobal::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
TDEGlobal::registerStaticDeleter
(
this
);
110
else
111
TDEGlobal::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
TDEGlobal::unregisterStaticDeleter
(
this
);
131
destructObject
();
132
}
133
private
:
134
type *deleteit;
135
type **globalReference;
136
bool
array;
137
};
138
139
#endif
tdecore
Skip menu "tdecore"
Main Page
Modules
Namespace List
Class Hierarchy
Alphabetical List
Class List
File List
Namespace Members
Class Members
Related Pages
tdecore
Skip menu "tdecore"
arts
dcop
dnssd
interfaces
kspeech
interface
library
tdetexteditor
kate
kded
kdoctools
kimgio
kjs
libtdemid
libtdescreensaver
tdeabc
tdecmshell
tdecore
tdefx
tdehtml
tdeinit
tdeio
bookmarks
httpfilter
kpasswdserver
kssl
tdefile
tdeio
tdeioexec
tdeioslave
http
tdemdi
tdemdi
tdenewstuff
tdeparts
tdeprint
tderandr
tderesources
tdespell2
tdesu
tdeui
tdeunittest
tdeutils
tdewallet