|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt3Support module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef Q3PTRLIST_H |
|
43 #define Q3PTRLIST_H |
|
44 |
|
45 #include <Qt3Support/q3glist.h> |
|
46 |
|
47 QT_BEGIN_HEADER |
|
48 |
|
49 QT_BEGIN_NAMESPACE |
|
50 |
|
51 QT_MODULE(Qt3SupportLight) |
|
52 |
|
53 template<class type> |
|
54 class Q3PtrListStdIterator : public Q3GListStdIterator |
|
55 { |
|
56 public: |
|
57 inline Q3PtrListStdIterator( Q3LNode* n ): Q3GListStdIterator(n) {} |
|
58 type *operator*() { return node ? (type *)node->getData() : 0; } |
|
59 inline Q3PtrListStdIterator<type> operator++() |
|
60 { node = next(); return *this; } |
|
61 inline Q3PtrListStdIterator<type> operator++(int) |
|
62 { Q3LNode* n = node; node = next(); return Q3PtrListStdIterator<type>( n ); } |
|
63 inline bool operator==( const Q3PtrListStdIterator<type>& it ) const { return node == it.node; } |
|
64 inline bool operator!=( const Q3PtrListStdIterator<type>& it ) const { return node != it.node; } |
|
65 }; |
|
66 |
|
67 |
|
68 template<class type> |
|
69 class Q3PtrList |
|
70 #ifdef qdoc |
|
71 : public Q3PtrCollection |
|
72 #else |
|
73 : public Q3GList |
|
74 #endif |
|
75 { |
|
76 public: |
|
77 |
|
78 Q3PtrList() {} |
|
79 Q3PtrList( const Q3PtrList<type> &l ) : Q3GList(l) {} |
|
80 ~Q3PtrList() { clear(); } |
|
81 Q3PtrList<type> &operator=(const Q3PtrList<type> &l) |
|
82 { return (Q3PtrList<type>&)Q3GList::operator=(l); } |
|
83 bool operator==( const Q3PtrList<type> &list ) const |
|
84 { return Q3GList::operator==( list ); } |
|
85 bool operator!=( const Q3PtrList<type> &list ) const |
|
86 { return !Q3GList::operator==( list ); } |
|
87 uint count() const { return Q3GList::count(); } |
|
88 bool isEmpty() const { return Q3GList::count() == 0; } |
|
89 bool insert( uint i, const type *d){ return Q3GList::insertAt(i,(Q3PtrCollection::Item)d); } |
|
90 void inSort( const type *d ) { Q3GList::inSort((Q3PtrCollection::Item)d); } |
|
91 void prepend( const type *d ) { Q3GList::insertAt(0,(Q3PtrCollection::Item)d); } |
|
92 void append( const type *d ) { Q3GList::append((Q3PtrCollection::Item)d); } |
|
93 bool remove( uint i ) { return Q3GList::removeAt(i); } |
|
94 bool remove() { return Q3GList::remove((Q3PtrCollection::Item)0); } |
|
95 bool remove( const type *d ) { return Q3GList::remove((Q3PtrCollection::Item)d); } |
|
96 bool removeRef( const type *d ) { return Q3GList::removeRef((Q3PtrCollection::Item)d); } |
|
97 void removeNode( Q3LNode *n ) { Q3GList::removeNode(n); } |
|
98 bool removeFirst() { return Q3GList::removeFirst(); } |
|
99 bool removeLast() { return Q3GList::removeLast(); } |
|
100 type *take( uint i ) { return (type *)Q3GList::takeAt(i); } |
|
101 type *take() { return (type *)Q3GList::take(); } |
|
102 type *takeNode( Q3LNode *n ) { return (type *)Q3GList::takeNode(n); } |
|
103 void clear() { Q3GList::clear(); } |
|
104 void sort() { Q3GList::sort(); } |
|
105 int find( const type *d ) { return Q3GList::find((Q3PtrCollection::Item)d); } |
|
106 int findNext( const type *d ) { return Q3GList::find((Q3PtrCollection::Item)d,false); } |
|
107 int findRef( const type *d ) { return Q3GList::findRef((Q3PtrCollection::Item)d); } |
|
108 int findNextRef( const type *d ){ return Q3GList::findRef((Q3PtrCollection::Item)d,false);} |
|
109 uint contains( const type *d ) const { return Q3GList::contains((Q3PtrCollection::Item)d); } |
|
110 uint containsRef( const type *d ) const |
|
111 { return Q3GList::containsRef((Q3PtrCollection::Item)d); } |
|
112 bool replace( uint i, const type *d ) { return Q3GList::replaceAt( i, (Q3PtrCollection::Item)d ); } |
|
113 type *at( uint i ) { return (type *)Q3GList::at(i); } |
|
114 int at() const { return Q3GList::at(); } |
|
115 type *current() const { return (type *)Q3GList::get(); } |
|
116 Q3LNode *currentNode() const { return Q3GList::currentNode(); } |
|
117 type *getFirst() const { return (type *)Q3GList::cfirst(); } |
|
118 type *getLast() const { return (type *)Q3GList::clast(); } |
|
119 type *first() { return (type *)Q3GList::first(); } |
|
120 type *last() { return (type *)Q3GList::last(); } |
|
121 type *next() { return (type *)Q3GList::next(); } |
|
122 type *prev() { return (type *)Q3GList::prev(); } |
|
123 void toVector( Q3GVector *vec )const{ Q3GList::toVector(vec); } |
|
124 |
|
125 |
|
126 // standard iterators |
|
127 typedef Q3PtrListStdIterator<type> Iterator; |
|
128 typedef Q3PtrListStdIterator<type> ConstIterator; |
|
129 inline Iterator begin() { return Q3GList::begin(); } |
|
130 inline ConstIterator begin() const { return Q3GList::begin(); } |
|
131 inline ConstIterator constBegin() const { return Q3GList::begin(); } |
|
132 inline Iterator end() { return Q3GList::end(); } |
|
133 inline ConstIterator end() const { return Q3GList::end(); } |
|
134 inline ConstIterator constEnd() const { return Q3GList::end(); } |
|
135 inline Iterator erase( Iterator it ) { return Q3GList::erase( it ); } |
|
136 // stl syntax compatibility |
|
137 typedef Iterator iterator; |
|
138 typedef ConstIterator const_iterator; |
|
139 |
|
140 |
|
141 #ifdef qdoc |
|
142 protected: |
|
143 virtual int compareItems( Q3PtrCollection::Item, Q3PtrCollection::Item ); |
|
144 virtual QDataStream& read( QDataStream&, Q3PtrCollection::Item& ); |
|
145 virtual QDataStream& write( QDataStream&, Q3PtrCollection::Item ) const; |
|
146 #endif |
|
147 |
|
148 private: |
|
149 void deleteItem( Item d ); |
|
150 }; |
|
151 |
|
152 #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION) |
|
153 template<> inline void Q3PtrList<void>::deleteItem( Q3PtrCollection::Item ) |
|
154 { |
|
155 } |
|
156 #endif |
|
157 |
|
158 template<class type> inline void Q3PtrList<type>::deleteItem( Q3PtrCollection::Item d ) |
|
159 { |
|
160 if ( del_item ) delete (type *)d; |
|
161 } |
|
162 |
|
163 template<class type> |
|
164 class Q3PtrListIterator : public Q3GListIterator |
|
165 { |
|
166 public: |
|
167 Q3PtrListIterator(const Q3PtrList<type> &l) :Q3GListIterator((Q3GList &)l) {} |
|
168 ~Q3PtrListIterator() {} |
|
169 uint count() const { return list->count(); } |
|
170 bool isEmpty() const { return list->count() == 0; } |
|
171 bool atFirst() const { return Q3GListIterator::atFirst(); } |
|
172 bool atLast() const { return Q3GListIterator::atLast(); } |
|
173 type *toFirst() { return (type *)Q3GListIterator::toFirst(); } |
|
174 type *toLast() { return (type *)Q3GListIterator::toLast(); } |
|
175 operator type *() const { return (type *)Q3GListIterator::get(); } |
|
176 type *operator*() { return (type *)Q3GListIterator::get(); } |
|
177 |
|
178 // No good, since Q3PtrList<char> (ie. QStrList fails... |
|
179 // |
|
180 // MSVC++ gives warning |
|
181 // Sunpro C++ 4.1 gives error |
|
182 // type *operator->() { return (type *)Q3GListIterator::get(); } |
|
183 |
|
184 type *current() const { return (type *)Q3GListIterator::get(); } |
|
185 type *operator()() { return (type *)Q3GListIterator::operator()();} |
|
186 type *operator++() { return (type *)Q3GListIterator::operator++(); } |
|
187 type *operator+=(uint j) { return (type *)Q3GListIterator::operator+=(j);} |
|
188 type *operator--() { return (type *)Q3GListIterator::operator--(); } |
|
189 type *operator-=(uint j) { return (type *)Q3GListIterator::operator-=(j);} |
|
190 Q3PtrListIterator<type>& operator=(const Q3PtrListIterator<type>&it) |
|
191 { Q3GListIterator::operator=(it); return *this; } |
|
192 }; |
|
193 |
|
194 QT_END_NAMESPACE |
|
195 |
|
196 QT_END_HEADER |
|
197 |
|
198 #endif // Q3PTRLIST_H |