Diffstat (limited to 'noncore/apps/opie-write/qcleanuphandler.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-write/qcleanuphandler.h | 12 |
1 files changed, 0 insertions, 12 deletions
diff --git a/noncore/apps/opie-write/qcleanuphandler.h b/noncore/apps/opie-write/qcleanuphandler.h index 5c5bf16..2d6eb7c 100644 --- a/noncore/apps/opie-write/qcleanuphandler.h +++ b/noncore/apps/opie-write/qcleanuphandler.h | |||
@@ -20,120 +20,108 @@ | |||
20 | ** licenses may use this file in accordance with the Qt Commercial License | 20 | ** licenses may use this file in accordance with the Qt Commercial License |
21 | ** Agreement provided with the Software. | 21 | ** Agreement provided with the Software. |
22 | ** | 22 | ** |
23 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 24 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
25 | ** | 25 | ** |
26 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 26 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
27 | ** information about Qt Commercial License Agreements. | 27 | ** information about Qt Commercial License Agreements. |
28 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 28 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
30 | ** | 30 | ** |
31 | ** Contact info@trolltech.com if any conditions of this licensing are | 31 | ** Contact info@trolltech.com if any conditions of this licensing are |
32 | ** not clear to you. | 32 | ** not clear to you. |
33 | ** | 33 | ** |
34 | **********************************************************************/ | 34 | **********************************************************************/ |
35 | 35 | ||
36 | #ifndef QCLEANUPHANDLER_H | 36 | #ifndef QCLEANUPHANDLER_H |
37 | #define QCLEANUPHANDLER_H | 37 | #define QCLEANUPHANDLER_H |
38 | 38 | ||
39 | #ifndef QT_H | 39 | #ifndef QT_H |
40 | #include <qlist.h> | 40 | #include <qlist.h> |
41 | #endif // QT_H | 41 | #endif // QT_H |
42 | 42 | ||
43 | template<class Type> | 43 | template<class Type> |
44 | #ifdef Q_NO_TEMPLATE_EXPORT | ||
45 | class QCleanupHandler | 44 | class QCleanupHandler |
46 | #else | ||
47 | class Q_EXPORT QCleanupHandler | ||
48 | #endif | ||
49 | { | 45 | { |
50 | public: | 46 | public: |
51 | QCleanupHandler() : cleanupObjects( 0 ) {} | 47 | QCleanupHandler() : cleanupObjects( 0 ) {} |
52 | ~QCleanupHandler() { clear(); } | 48 | ~QCleanupHandler() { clear(); } |
53 | 49 | ||
54 | Type* add( Type **object ) { | 50 | Type* add( Type **object ) { |
55 | if ( !cleanupObjects ) | 51 | if ( !cleanupObjects ) |
56 | cleanupObjects = new QPtrList<Type*>; | 52 | cleanupObjects = new QPtrList<Type*>; |
57 | cleanupObjects->insert( 0, object ); | 53 | cleanupObjects->insert( 0, object ); |
58 | return *object; | 54 | return *object; |
59 | } | 55 | } |
60 | 56 | ||
61 | void remove( Type **object ) { | 57 | void remove( Type **object ) { |
62 | if ( !cleanupObjects ) | 58 | if ( !cleanupObjects ) |
63 | return; | 59 | return; |
64 | if ( cleanupObjects->findRef( object ) >= 0 ) | 60 | if ( cleanupObjects->findRef( object ) >= 0 ) |
65 | (void) cleanupObjects->take(); | 61 | (void) cleanupObjects->take(); |
66 | } | 62 | } |
67 | 63 | ||
68 | bool isEmpty() const { | 64 | bool isEmpty() const { |
69 | return cleanupObjects ? cleanupObjects->isEmpty() : TRUE; | 65 | return cleanupObjects ? cleanupObjects->isEmpty() : TRUE; |
70 | } | 66 | } |
71 | 67 | ||
72 | void clear() { | 68 | void clear() { |
73 | if ( !cleanupObjects ) | 69 | if ( !cleanupObjects ) |
74 | return; | 70 | return; |
75 | QPtrListIterator<Type*> it( *cleanupObjects ); | 71 | QPtrListIterator<Type*> it( *cleanupObjects ); |
76 | Type **object; | 72 | Type **object; |
77 | while ( ( object = it.current() ) ) { | 73 | while ( ( object = it.current() ) ) { |
78 | delete *object; | 74 | delete *object; |
79 | *object = 0; | 75 | *object = 0; |
80 | cleanupObjects->remove( object ); | 76 | cleanupObjects->remove( object ); |
81 | } | 77 | } |
82 | delete cleanupObjects; | 78 | delete cleanupObjects; |
83 | cleanupObjects = 0; | 79 | cleanupObjects = 0; |
84 | } | 80 | } |
85 | 81 | ||
86 | private: | 82 | private: |
87 | QPtrList<Type*> *cleanupObjects; | 83 | QPtrList<Type*> *cleanupObjects; |
88 | }; | 84 | }; |
89 | 85 | ||
90 | template<class Type> | 86 | template<class Type> |
91 | #ifdef Q_NO_TEMPLATE_EXPORT | ||
92 | class QSingleCleanupHandler | 87 | class QSingleCleanupHandler |
93 | #else | ||
94 | class Q_EXPORT QSingleCleanupHandler | ||
95 | #endif | ||
96 | { | 88 | { |
97 | public: | 89 | public: |
98 | QSingleCleanupHandler() : object( 0 ) {} | 90 | QSingleCleanupHandler() : object( 0 ) {} |
99 | ~QSingleCleanupHandler() { | 91 | ~QSingleCleanupHandler() { |
100 | if ( object ) { | 92 | if ( object ) { |
101 | delete *object; | 93 | delete *object; |
102 | *object = 0; | 94 | *object = 0; |
103 | } | 95 | } |
104 | } | 96 | } |
105 | Type* set( Type **o ) { | 97 | Type* set( Type **o ) { |
106 | object = o; | 98 | object = o; |
107 | return *object; | 99 | return *object; |
108 | } | 100 | } |
109 | void reset() { object = 0; } | 101 | void reset() { object = 0; } |
110 | private: | 102 | private: |
111 | Type **object; | 103 | Type **object; |
112 | }; | 104 | }; |
113 | 105 | ||
114 | template<class Type> | 106 | template<class Type> |
115 | #ifdef Q_NO_TEMPLATE_EXPORT | ||
116 | class QSharedCleanupHandler | 107 | class QSharedCleanupHandler |
117 | #else | ||
118 | class Q_EXPORT QSharedCleanupHandler | ||
119 | #endif | ||
120 | { | 108 | { |
121 | public: | 109 | public: |
122 | QSharedCleanupHandler() : object( 0 ) {} | 110 | QSharedCleanupHandler() : object( 0 ) {} |
123 | ~QSharedCleanupHandler() { | 111 | ~QSharedCleanupHandler() { |
124 | if ( object ) { | 112 | if ( object ) { |
125 | if ( (*object)->deref() ) | 113 | if ( (*object)->deref() ) |
126 | delete *object; | 114 | delete *object; |
127 | *object = 0; | 115 | *object = 0; |
128 | } | 116 | } |
129 | } | 117 | } |
130 | Type* set( Type **o ) { | 118 | Type* set( Type **o ) { |
131 | object = o; | 119 | object = o; |
132 | return *object; | 120 | return *object; |
133 | } | 121 | } |
134 | void reset() { object = 0; } | 122 | void reset() { object = 0; } |
135 | private: | 123 | private: |
136 | Type **object; | 124 | Type **object; |
137 | }; | 125 | }; |
138 | 126 | ||
139 | #endif //QCLEANUPHANDLER_H | 127 | #endif //QCLEANUPHANDLER_H |