1 | /****************************************************************************
|
---|
2 | ** $Id: qptrlist.h 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Definition of QPtrList template/macro class
|
---|
5 | **
|
---|
6 | ** Copyright (C) 1992-2000 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 QPTRLIST_H
|
---|
37 | #define QPTRLIST_H
|
---|
38 |
|
---|
39 | #ifndef QT_H
|
---|
40 | #include "qglist.h"
|
---|
41 | #endif // QT_H
|
---|
42 |
|
---|
43 | template<class type>
|
---|
44 | class QPtrListStdIterator : public QGListStdIterator
|
---|
45 | {
|
---|
46 | public:
|
---|
47 | inline QPtrListStdIterator( QLNode* n ): QGListStdIterator(n) {}
|
---|
48 | type *operator*() { return node ? (type *)node->getData() : 0; }
|
---|
49 | inline QPtrListStdIterator<type> operator++()
|
---|
50 | { node = next(); return *this; }
|
---|
51 | inline QPtrListStdIterator<type> operator++(int)
|
---|
52 | { QLNode* n = node; node = next(); return QPtrListStdIterator<type>( n ); }
|
---|
53 | inline bool operator==( const QPtrListStdIterator<type>& it ) const { return node == it.node; }
|
---|
54 | inline bool operator!=( const QPtrListStdIterator<type>& it ) const { return node != it.node; }
|
---|
55 | };
|
---|
56 |
|
---|
57 |
|
---|
58 | template<class type>
|
---|
59 | class QPtrList
|
---|
60 | #ifdef Q_QDOC
|
---|
61 | : public QPtrCollection
|
---|
62 | #else
|
---|
63 | : public QGList
|
---|
64 | #endif
|
---|
65 | {
|
---|
66 | public:
|
---|
67 |
|
---|
68 | QPtrList() {}
|
---|
69 | QPtrList( const QPtrList<type> &l ) : QGList(l) {}
|
---|
70 | ~QPtrList() { clear(); }
|
---|
71 | QPtrList<type> &operator=(const QPtrList<type> &l)
|
---|
72 | { return (QPtrList<type>&)QGList::operator=(l); }
|
---|
73 | bool operator==( const QPtrList<type> &list ) const
|
---|
74 | { return QGList::operator==( list ); }
|
---|
75 | bool operator!=( const QPtrList<type> &list ) const
|
---|
76 | { return !QGList::operator==( list ); }
|
---|
77 | uint count() const { return QGList::count(); }
|
---|
78 | bool isEmpty() const { return QGList::count() == 0; }
|
---|
79 | bool insert( uint i, const type *d){ return QGList::insertAt(i,(QPtrCollection::Item)d); }
|
---|
80 | void inSort( const type *d ) { QGList::inSort((QPtrCollection::Item)d); }
|
---|
81 | void prepend( const type *d ) { QGList::insertAt(0,(QPtrCollection::Item)d); }
|
---|
82 | void append( const type *d ) { QGList::append((QPtrCollection::Item)d); }
|
---|
83 | bool remove( uint i ) { return QGList::removeAt(i); }
|
---|
84 | bool remove() { return QGList::remove((QPtrCollection::Item)0); }
|
---|
85 | bool remove( const type *d ) { return QGList::remove((QPtrCollection::Item)d); }
|
---|
86 | bool removeRef( const type *d ) { return QGList::removeRef((QPtrCollection::Item)d); }
|
---|
87 | void removeNode( QLNode *n ) { QGList::removeNode(n); }
|
---|
88 | bool removeFirst() { return QGList::removeFirst(); }
|
---|
89 | bool removeLast() { return QGList::removeLast(); }
|
---|
90 | type *take( uint i ) { return (type *)QGList::takeAt(i); }
|
---|
91 | type *take() { return (type *)QGList::take(); }
|
---|
92 | type *takeNode( QLNode *n ) { return (type *)QGList::takeNode(n); }
|
---|
93 | void clear() { QGList::clear(); }
|
---|
94 | void sort() { QGList::sort(); }
|
---|
95 | int find( const type *d ) { return QGList::find((QPtrCollection::Item)d); }
|
---|
96 | int findNext( const type *d ) { return QGList::find((QPtrCollection::Item)d,FALSE); }
|
---|
97 | int findRef( const type *d ) { return QGList::findRef((QPtrCollection::Item)d); }
|
---|
98 | int findNextRef( const type *d ){ return QGList::findRef((QPtrCollection::Item)d,FALSE);}
|
---|
99 | uint contains( const type *d ) const { return QGList::contains((QPtrCollection::Item)d); }
|
---|
100 | uint containsRef( const type *d ) const
|
---|
101 | { return QGList::containsRef((QPtrCollection::Item)d); }
|
---|
102 | bool replace( uint i, const type *d ) { return QGList::replaceAt( i, (QPtrCollection::Item)d ); }
|
---|
103 | type *at( uint i ) { return (type *)QGList::at(i); }
|
---|
104 | int at() const { return QGList::at(); }
|
---|
105 | type *current() const { return (type *)QGList::get(); }
|
---|
106 | QLNode *currentNode() const { return QGList::currentNode(); }
|
---|
107 | type *getFirst() const { return (type *)QGList::cfirst(); }
|
---|
108 | type *getLast() const { return (type *)QGList::clast(); }
|
---|
109 | type *first() { return (type *)QGList::first(); }
|
---|
110 | type *last() { return (type *)QGList::last(); }
|
---|
111 | type *next() { return (type *)QGList::next(); }
|
---|
112 | type *prev() { return (type *)QGList::prev(); }
|
---|
113 | void toVector( QGVector *vec )const{ QGList::toVector(vec); }
|
---|
114 |
|
---|
115 |
|
---|
116 | // standard iterators
|
---|
117 | typedef QPtrListStdIterator<type> Iterator;
|
---|
118 | typedef QPtrListStdIterator<type> ConstIterator;
|
---|
119 | inline Iterator begin() { return QGList::begin(); }
|
---|
120 | inline ConstIterator begin() const { return QGList::begin(); }
|
---|
121 | inline ConstIterator constBegin() const { return QGList::begin(); }
|
---|
122 | inline Iterator end() { return QGList::end(); }
|
---|
123 | inline ConstIterator end() const { return QGList::end(); }
|
---|
124 | inline ConstIterator constEnd() const { return QGList::end(); }
|
---|
125 | inline Iterator erase( Iterator it ) { return QGList::erase( it ); }
|
---|
126 | // stl syntax compatibility
|
---|
127 | typedef Iterator iterator;
|
---|
128 | typedef ConstIterator const_iterator;
|
---|
129 |
|
---|
130 |
|
---|
131 | #ifdef Q_QDOC
|
---|
132 | protected:
|
---|
133 | virtual int compareItems( QPtrCollection::Item, QPtrCollection::Item );
|
---|
134 | virtual QDataStream& read( QDataStream&, QPtrCollection::Item& );
|
---|
135 | virtual QDataStream& write( QDataStream&, QPtrCollection::Item ) const;
|
---|
136 | #endif
|
---|
137 |
|
---|
138 | private:
|
---|
139 | void deleteItem( Item d );
|
---|
140 | };
|
---|
141 |
|
---|
142 | #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION)
|
---|
143 | template<> inline void QPtrList<void>::deleteItem( QPtrCollection::Item )
|
---|
144 | {
|
---|
145 | }
|
---|
146 | #endif
|
---|
147 |
|
---|
148 | template<class type> inline void QPtrList<type>::deleteItem( QPtrCollection::Item d )
|
---|
149 | {
|
---|
150 | if ( del_item ) delete (type *)d;
|
---|
151 | }
|
---|
152 |
|
---|
153 | template<class type>
|
---|
154 | class QPtrListIterator : public QGListIterator
|
---|
155 | {
|
---|
156 | public:
|
---|
157 | QPtrListIterator(const QPtrList<type> &l) :QGListIterator((QGList &)l) {}
|
---|
158 | ~QPtrListIterator() {}
|
---|
159 | uint count() const { return list->count(); }
|
---|
160 | bool isEmpty() const { return list->count() == 0; }
|
---|
161 | bool atFirst() const { return QGListIterator::atFirst(); }
|
---|
162 | bool atLast() const { return QGListIterator::atLast(); }
|
---|
163 | type *toFirst() { return (type *)QGListIterator::toFirst(); }
|
---|
164 | type *toLast() { return (type *)QGListIterator::toLast(); }
|
---|
165 | operator type *() const { return (type *)QGListIterator::get(); }
|
---|
166 | type *operator*() { return (type *)QGListIterator::get(); }
|
---|
167 |
|
---|
168 | // No good, since QPtrList<char> (ie. QStrList fails...
|
---|
169 | //
|
---|
170 | // MSVC++ gives warning
|
---|
171 | // Sunpro C++ 4.1 gives error
|
---|
172 | // type *operator->() { return (type *)QGListIterator::get(); }
|
---|
173 |
|
---|
174 | type *current() const { return (type *)QGListIterator::get(); }
|
---|
175 | type *operator()() { return (type *)QGListIterator::operator()();}
|
---|
176 | type *operator++() { return (type *)QGListIterator::operator++(); }
|
---|
177 | type *operator+=(uint j) { return (type *)QGListIterator::operator+=(j);}
|
---|
178 | type *operator--() { return (type *)QGListIterator::operator--(); }
|
---|
179 | type *operator-=(uint j) { return (type *)QGListIterator::operator-=(j);}
|
---|
180 | QPtrListIterator<type>& operator=(const QPtrListIterator<type>&it)
|
---|
181 | { QGListIterator::operator=(it); return *this; }
|
---|
182 | };
|
---|
183 |
|
---|
184 | #ifndef QT_NO_COMPAT
|
---|
185 | #define QList QPtrList
|
---|
186 | #define QListIterator QPtrListIterator
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | #define Q_DEFINED_QPTRLIST
|
---|
190 | #include "qwinexport.h"
|
---|
191 |
|
---|
192 | #endif // QPTRLIST_H
|
---|