qlist.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 **
4 ** Definition of QList template/macro class
5 **
6 ** Created : 920701
7 **
8 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9 **
10 ** This file is part of the tools module of the Qt GUI Toolkit.
11 **
12 ** This file may be distributed under the terms of the Q Public License
13 ** as defined by Trolltech AS of Norway and appearing in the file
14 ** LICENSE.QPL included in the packaging of this file.
15 **
16 ** This file may be distributed and/or modified under the terms of the
17 ** GNU General Public License version 2 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.GPL included in the
19 ** packaging of this file.
20 **
21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22 ** licenses may use this file in accordance with the Qt Commercial License
23 ** Agreement provided with the Software.
24 **
25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 **
28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29 ** information about Qt Commercial License Agreements.
30 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
31 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
32 **
33 ** Contact info@trolltech.com if any conditions of this licensing are
34 ** not clear to you.
35 **
36 **********************************************************************/
37 
38 /* This is a stripped version of the original QList, which has been renamed to
39  QInternalList. This implementation doesn't expose the current node and index,
40  nor direct access to the list nodes.
41  This makes it possible to have more constant methods. It also provides
42  a typesafe method to compare elements called compareValues() and a typesafe
43  methods to create and delete elements called newValue() and deleteValue().
44  */
45 
46 #ifndef QLIST_H
47 #define QLIST_H
48 
49 #ifndef QT_H
50 #include "qglist.h"
51 #endif // QT_H
52 
53 
54 template<class type> class Q_EXPORT QList : private QGList
55 {
56 public:
57  QList() {}
58  QList( const QList<type> &l ) : QGList(l) {}
59  ~QList() { clear(); }
61  { return (QList<type>&)QGList::operator=(l); }
62  bool operator==( const QList<type> &list ) const
63  { return QGList::operator==( list ); }
64 
65  // capacity
66  uint count() const { return QGList::count(); }
67  bool isEmpty() const { return QGList::count() == 0; }
68 
69  // modifiers add
70  bool insert( uint i, const type *d){ return QGList::insertAt(i,(QCollection::Item)d); }
71  void inSort( const type *d ) { QGList::inSort((QCollection::Item)d); }
72  void prepend( const type *d ) { QGList::insertAt(0,(QCollection::Item)d); }
73  void append( const type *d ) { QGList::append((QCollection::Item)d); }
74 
75  // modifiers remove
76  bool remove( uint i ) { return QGList::removeAt(i); }
77  bool remove( const type *d ) { return QGList::remove((QCollection::Item)d); }
78  bool removeRef( const type *d ) { return QGList::removeRef((QCollection::Item)d); }
79  bool removeFirst() { return QGList::removeFirst(); }
80  bool removeLast() { return QGList::removeLast(); }
81  type *take( uint i ) { return (type *)QGList::takeAt(i); }
82  void clear() { QGList::clear(); }
83 
84  // operations
85  void sort() { QGList::sort(); }
86 
87  // search
88  int find( const type *d ) const { return const_cast<QList<type>*>(this)->QGList::find((QCollection::Item)d); }
89  int findRef( const type *d ) const { return const_cast<QList<type>*>(this)->QGList::findRef((QCollection::Item)d); }
90  uint contains( const type *d ) const { return QGList::contains((QCollection::Item)d); }
91  uint containsRef( const type *d ) const { return QGList::containsRef((QCollection::Item)d); }
92 
93  // element access
94  type *at( uint i ) const { return (type *)const_cast<QList<type>*>(this)->QGList::at(i); }
95  type *getFirst() const { return (type *)QGList::cfirst(); }
96  type *getLast() const { return (type *)QGList::clast(); }
97 
98  // ownership
99  void setAutoDelete( bool enable ) { QGList::setAutoDelete(enable); }
100 
101 private:
102  // new to be reimplemented methods
103  virtual int compareValues(const type *t1,const type *t2) const
104  { return const_cast<QList<type>*>(this)->QGList::compareItems((QCollection::Item)t1,(QCollection::Item)t2); }
105  virtual type *newValue(type *item) const
106  { return item; }
107  virtual void deleteValue(type *item) const
108  { if (del_item) delete item; }
109 
110  // reimplemented methods
111  virtual Item newItem( Item item)
112  { return (Item)newValue((type*)item); }
113  virtual void deleteItem( QCollection::Item item )
114  { deleteValue((type *)item); }
116  { return compareValues((const type*)i1,(const type*)i2); }
117 };
118 
119 #if defined(Q_DELETING_VOID_UNDEFINED)
120 template<> inline void QList<void>::deleteValue(void *) const
121 {
122 }
123 #endif
124 
125 
126 template<class type> class Q_EXPORT QListIterator : public QGListIterator
127 {
128 public:
131  uint count() const { return list->count(); }
132  bool isEmpty() const { return list->count() == 0; }
133  bool atFirst() const { return QGListIterator::atFirst(); }
134  bool atLast() const { return QGListIterator::atLast(); }
137  operator type *() const { return (type *)QGListIterator::get(); }
139 
140  // No good, since QList<char> (ie. QStrList fails...
141  //
142  // MSVC++ gives warning
143  // Sunpro C++ 4.1 gives error
144  // type *operator->() { return (type *)QGListIterator::get(); }
145 
146  type *current() const { return (type *)QGListIterator::get(); }
153  { QGListIterator::operator=(it); return *this; }
154 };
155 
156 
157 #endif // QLIST_H
~QListIterator()
Definition: qlist.h:130
virtual int compareValues(const type *t1, const type *t2) const
Definition: qlist.h:103
uint contains(QCollection::Item) const
Definition: qglist.cpp:751
QCollection::Item operator++()
Definition: qglist.cpp:1180
bool removeFirst()
Definition: qlist.h:79
void append(QCollection::Item)
Definition: qglist.cpp:364
bool removeAt(uint index)
Definition: qglist.cpp:554
QListIterator< type > & operator=(const QListIterator< type > &it)
Definition: qlist.h:152
QList(const QList< type > &l)
Definition: qlist.h:58
void append(const type *d)
Definition: qlist.h:73
int findRef(const type *d) const
Definition: qlist.h:89
QCollection::Item operator-=(uint)
Definition: qglist.cpp:1218
QCollection::Item get() const
Definition: qglist.h:251
virtual int compareItems(QCollection::Item, QCollection::Item)
Definition: qglist.cpp:125
type * at(uint i) const
Definition: qlist.h:94
type * operator++()
Definition: qlist.h:148
int find(const type *d) const
Definition: qlist.h:88
static QStrList * l
Definition: config.cpp:1044
uint containsRef(QCollection::Item) const
Definition: qglist.cpp:734
virtual Item newItem(Item item)
Definition: qlist.h:111
bool removeRef(QCollection::Item=0)
Definition: qglist.cpp:523
bool insert(uint i, const type *d)
Definition: qlist.h:70
uint count() const
Definition: qglist.h:150
uint count() const
Definition: qlist.h:66
type * getLast() const
Definition: qlist.h:96
bool removeLast()
Definition: qglist.h:161
QCollection::Item operator()()
Definition: qglist.cpp:1166
void inSort(const type *d)
Definition: qlist.h:71
uint count() const
Definition: qlist.h:131
int at() const
Definition: qglist.h:167
QGListIterator & operator=(const QGListIterator &)
Definition: qglist.cpp:1085
virtual void deleteItem(QCollection::Item item)
Definition: qlist.h:113
bool isEmpty() const
Definition: qlist.h:67
void sort()
Definition: qlist.h:85
The QGList class is an internal class for implementing Qt collection classes.
Definition: qglist.h:68
~QList()
Definition: qlist.h:59
type * operator*()
Definition: qlist.h:138
QCollection::Item clast() const
Definition: qglist.h:193
void clear()
Definition: qlist.h:82
type * current() const
Definition: qlist.h:146
virtual type * newValue(type *item) const
Definition: qlist.h:105
QListIterator(const QList< type > &l)
Definition: qlist.h:129
type * getFirst() const
Definition: qlist.h:95
bool atFirst() const
Definition: qglist.h:241
bool operator==(const QList< type > &list) const
Definition: qlist.h:62
QCollection::Item toLast()
Definition: qglist.cpp:1142
uint containsRef(const type *d) const
Definition: qlist.h:91
virtual void deleteValue(type *item) const
Definition: qlist.h:107
QList< type > & operator=(const QList< type > &l)
Definition: qlist.h:60
QList()
Definition: qlist.h:57
void sort()
Definition: qglist.cpp:934
int findRef(QCollection::Item, bool=TRUE)
Definition: qglist.cpp:683
void setAutoDelete(bool enable)
Definition: qcollection.h:55
virtual int compareItems(QCollection::Item i1, QCollection::Item i2)
Definition: qlist.h:115
bool remove(QCollection::Item=0)
Definition: qglist.cpp:504
type * operator()()
Definition: qlist.h:147
bool atLast() const
Definition: qglist.h:246
QCollection::Item operator--()
Definition: qglist.cpp:1205
bool isEmpty() const
Definition: qlist.h:132
QCollection::Item operator+=(uint)
Definition: qglist.cpp:1193
type * operator--()
Definition: qlist.h:150
type * operator+=(uint j)
Definition: qlist.h:149
bool atFirst() const
Definition: qlist.h:133
bool removeFirst()
Definition: qglist.h:155
QCollection::Item cfirst() const
Definition: qglist.h:188
bool atLast() const
Definition: qlist.h:134
type * operator-=(uint j)
Definition: qlist.h:151
bool removeRef(const type *d)
Definition: qlist.h:78
bool removeLast()
Definition: qlist.h:80
void prepend(const type *d)
Definition: qlist.h:72
type * take(uint i)
Definition: qlist.h:81
void clear()
Definition: qglist.cpp:652
uint contains(const type *d) const
Definition: qlist.h:90
bool operator==(const QGList &) const
Definition: qglist.cpp:242
void inSort(QCollection::Item)
Definition: qglist.cpp:327
unsigned uint
Definition: qglobal.h:351
void setAutoDelete(bool enable)
Definition: qlist.h:99
The QGListIterator class is an internal class for implementing QListIterator.
Definition: qglist.h:212
QGList & operator=(const QGList &)
Definition: qglist.cpp:222
type * toLast()
Definition: qlist.h:136
#define Q_EXPORT
Definition: qglobal.h:468
QCollection::Item toFirst()
Definition: qglist.cpp:1126
QCollection::Item takeAt(uint index)
Definition: qglist.cpp:608
Definition: qlist.h:54
bool insertAt(uint index, QCollection::Item)
Definition: qglist.cpp:384
type * toFirst()
Definition: qlist.h:135
void * Item
Definition: qcollection.h:60
int find(QCollection::Item, bool=TRUE)
Definition: qglist.cpp:708