ISLEman
qlist.h
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(); }
60  QList<type> &operator=(const QList<type> &l)
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); }
115  virtual int compareItems(QCollection::Item i1,QCollection::Item i2)
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:
129  QListIterator(const QList<type> &l) :QGListIterator((QGList &)l) {}
130  ~QListIterator() {}
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(); }
135  type *toFirst() { return (type *)QGListIterator::toFirst(); }
136  type *toLast() { return (type *)QGListIterator::toLast(); }
137  operator type *() const { return (type *)QGListIterator::get(); }
138  type *operator*() { 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(); }
147  type *operator()() { return (type *)QGListIterator::operator()();}
148  type *operator++() { return (type *)QGListIterator::operator++(); }
149  type *operator+=(uint j) { return (type *)QGListIterator::operator+=(j);}
150  type *operator--() { return (type *)QGListIterator::operator--(); }
151  type *operator-=(uint j) { return (type *)QGListIterator::operator-=(j);}
152  QListIterator<type>& operator=(const QListIterator<type>&it)
153  { QGListIterator::operator=(it); return *this; }
154 };
155 
156 
157 #endif // QLIST_H
virtual Item newItem(Item)
Definition: qcollection.cpp:148
virtual int compareItems(QCollection::Item, QCollection::Item)
Definition: qglist.cpp:125
bool operator==(const QGList &) const
Definition: qglist.cpp:242
The QGList class is an internal class for implementing Qt collection classes.
Definition: qglist.h:68
void clear()
Definition: qlist.h:82
uint count() const
Definition: qglist.h:150
uint count() const
Definition: qlist.h:66
Definition: qlist.h:126
void sort()
Definition: qglist.cpp:934
void setAutoDelete(bool enable)
Definition: qcollection.h:55
virtual void deleteItem(Item)
Definition: qcollection.cpp:174
void clear()
Definition: qglist.cpp:652
The QGListIterator class is an internal class for implementing QListIterator.
Definition: qglist.h:212
Definition: qlist.h:54