author | leseb <leseb> | 2002-07-14 21:21:35 (UTC) |
---|---|---|
committer | leseb <leseb> | 2002-07-14 21:21:35 (UTC) |
commit | 4feeec8b5b41cfd3d13274411f515524f687da09 (patch) (unidiff) | |
tree | 002bbfb9997713e5d5975855d3cfbba7a71b9104 /noncore/apps/opie-write/qcleanuphandler.h | |
parent | bdef9cf23ced569a9bc80c1d4f25d85861273b4a (diff) | |
download | opie-4feeec8b5b41cfd3d13274411f515524f687da09.zip opie-4feeec8b5b41cfd3d13274411f515524f687da09.tar.gz opie-4feeec8b5b41cfd3d13274411f515524f687da09.tar.bz2 |
opie-write first draft
Diffstat (limited to 'noncore/apps/opie-write/qcleanuphandler.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-write/qcleanuphandler.h | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/noncore/apps/opie-write/qcleanuphandler.h b/noncore/apps/opie-write/qcleanuphandler.h new file mode 100644 index 0000000..5c5bf16 --- a/dev/null +++ b/noncore/apps/opie-write/qcleanuphandler.h | |||
@@ -0,0 +1,139 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** ... | ||
5 | ** | ||
6 | ** Copyright (C) 2001-2002 Trolltech AS. All rights reserved. | ||
7 | ** | ||
8 | ** This file is part of the tools module of the Qt GUI Toolkit. | ||
9 | ** | ||
10 | ** This file may be distributed under the terms of the Q Public License | ||
11 | ** as defined by Trolltech AS of Norway and appearing in the file | ||
12 | ** LICENSE.QPL included in the packaging of this file. | ||
13 | ** | ||
14 | ** This file may be distributed and/or modified under the terms of the | ||
15 | ** GNU General Public License version 2 as published by the Free Software | ||
16 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
17 | ** packaging of this file. | ||
18 | ** | ||
19 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
20 | ** licenses may use this file in accordance with the Qt Commercial License | ||
21 | ** Agreement provided with the Software. | ||
22 | ** | ||
23 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
24 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
25 | ** | ||
26 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
27 | ** information about Qt Commercial License Agreements. | ||
28 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
30 | ** | ||
31 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
32 | ** not clear to you. | ||
33 | ** | ||
34 | **********************************************************************/ | ||
35 | |||
36 | #ifndef QCLEANUPHANDLER_H | ||
37 | #define QCLEANUPHANDLER_H | ||
38 | |||
39 | #ifndef QT_H | ||
40 | #include <qlist.h> | ||
41 | #endif // QT_H | ||
42 | |||
43 | template<class Type> | ||
44 | #ifdef Q_NO_TEMPLATE_EXPORT | ||
45 | class QCleanupHandler | ||
46 | #else | ||
47 | class Q_EXPORT QCleanupHandler | ||
48 | #endif | ||
49 | { | ||
50 | public: | ||
51 | QCleanupHandler() : cleanupObjects( 0 ) {} | ||
52 | ~QCleanupHandler() { clear(); } | ||
53 | |||
54 | Type* add( Type **object ) { | ||
55 | if ( !cleanupObjects ) | ||
56 | cleanupObjects = new QPtrList<Type*>; | ||
57 | cleanupObjects->insert( 0, object ); | ||
58 | return *object; | ||
59 | } | ||
60 | |||
61 | void remove( Type **object ) { | ||
62 | if ( !cleanupObjects ) | ||
63 | return; | ||
64 | if ( cleanupObjects->findRef( object ) >= 0 ) | ||
65 | (void) cleanupObjects->take(); | ||
66 | } | ||
67 | |||
68 | bool isEmpty() const { | ||
69 | return cleanupObjects ? cleanupObjects->isEmpty() : TRUE; | ||
70 | } | ||
71 | |||
72 | void clear() { | ||
73 | if ( !cleanupObjects ) | ||
74 | return; | ||
75 | QPtrListIterator<Type*> it( *cleanupObjects ); | ||
76 | Type **object; | ||
77 | while ( ( object = it.current() ) ) { | ||
78 | delete *object; | ||
79 | *object = 0; | ||
80 | cleanupObjects->remove( object ); | ||
81 | } | ||
82 | delete cleanupObjects; | ||
83 | cleanupObjects = 0; | ||
84 | } | ||
85 | |||
86 | private: | ||
87 | QPtrList<Type*> *cleanupObjects; | ||
88 | }; | ||
89 | |||
90 | template<class Type> | ||
91 | #ifdef Q_NO_TEMPLATE_EXPORT | ||
92 | class QSingleCleanupHandler | ||
93 | #else | ||
94 | class Q_EXPORT QSingleCleanupHandler | ||
95 | #endif | ||
96 | { | ||
97 | public: | ||
98 | QSingleCleanupHandler() : object( 0 ) {} | ||
99 | ~QSingleCleanupHandler() { | ||
100 | if ( object ) { | ||
101 | delete *object; | ||
102 | *object = 0; | ||
103 | } | ||
104 | } | ||
105 | Type* set( Type **o ) { | ||
106 | object = o; | ||
107 | return *object; | ||
108 | } | ||
109 | void reset() { object = 0; } | ||
110 | private: | ||
111 | Type **object; | ||
112 | }; | ||
113 | |||
114 | template<class Type> | ||
115 | #ifdef Q_NO_TEMPLATE_EXPORT | ||
116 | class QSharedCleanupHandler | ||
117 | #else | ||
118 | class Q_EXPORT QSharedCleanupHandler | ||
119 | #endif | ||
120 | { | ||
121 | public: | ||
122 | QSharedCleanupHandler() : object( 0 ) {} | ||
123 | ~QSharedCleanupHandler() { | ||
124 | if ( object ) { | ||
125 | if ( (*object)->deref() ) | ||
126 | delete *object; | ||
127 | *object = 0; | ||
128 | } | ||
129 | } | ||
130 | Type* set( Type **o ) { | ||
131 | object = o; | ||
132 | return *object; | ||
133 | } | ||
134 | void reset() { object = 0; } | ||
135 | private: | ||
136 | Type **object; | ||
137 | }; | ||
138 | |||
139 | #endif //QCLEANUPHANDLER_H | ||