~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/qt3support/tools/q3glist.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef Q3GLIST_H
 
30
#define Q3GLIST_H
 
31
 
 
32
#include "Qt3Support/q3ptrcollection.h"
 
33
 
 
34
class Q_COMPAT_EXPORT Q3LNode
 
35
{
 
36
friend class Q3GList;
 
37
friend class Q3GListIterator;
 
38
friend class Q3GListStdIterator;
 
39
public:
 
40
    Q3PtrCollection::Item getData()     { return data; }
 
41
private:
 
42
    Q3PtrCollection::Item data;
 
43
    Q3LNode *prev;
 
44
    Q3LNode *next;
 
45
    Q3LNode( Q3PtrCollection::Item d ) { data = d; }
 
46
};
 
47
 
 
48
class Q3GListIteratorList; // internal helper class
 
49
 
 
50
class Q_COMPAT_EXPORT Q3GList : public Q3PtrCollection  // doubly linked generic list
 
51
{
 
52
friend class Q3GListIterator;
 
53
friend class Q3GListIteratorList;
 
54
friend class Q3GVector;                         // needed by Q3GVector::toList
 
55
public:
 
56
    uint  count() const;                        // return number of nodes
 
57
 
 
58
#ifndef QT_NO_DATASTREAM
 
59
    QDataStream &read( QDataStream & );         // read list from stream
 
60
    QDataStream &write( QDataStream & ) const;  // write list to stream
 
61
#endif
 
62
protected:
 
63
    Q3GList();                                  // create empty list
 
64
    Q3GList( const Q3GList & );                 // make copy of other list
 
65
    virtual ~Q3GList();
 
66
 
 
67
    Q3GList &operator=( const Q3GList & );      // assign from other list
 
68
    bool operator==( const Q3GList& ) const;
 
69
 
 
70
    void inSort( Q3PtrCollection::Item );               // add item sorted in list
 
71
    void append( Q3PtrCollection::Item );               // add item at end of list
 
72
    bool insertAt( uint index, Q3PtrCollection::Item ); // add item at i'th position
 
73
    void relinkNode( Q3LNode * );               // relink as first item
 
74
    bool removeNode( Q3LNode * );               // remove node
 
75
    bool remove( Q3PtrCollection::Item = 0 );   // remove item (0=current)
 
76
    bool removeRef( Q3PtrCollection::Item = 0 );        // remove item (0=current)
 
77
    bool removeFirst();                         // remove first item
 
78
    bool removeLast();                          // remove last item
 
79
    bool removeAt( uint );                      // remove item at i'th position
 
80
    bool replaceAt( uint, Q3PtrCollection::Item ); // replace item at position i with item
 
81
    Q3PtrCollection::Item takeNode( Q3LNode * );        // take out node
 
82
    Q3PtrCollection::Item take();               // take out current item
 
83
    Q3PtrCollection::Item takeAt( uint index ); // take out item at i'th pos
 
84
    Q3PtrCollection::Item takeFirst();          // take out first item
 
85
    Q3PtrCollection::Item takeLast();           // take out last item
 
86
 
 
87
    void sort();                                // sort all items;
 
88
    void clear();                               // remove all items
 
89
 
 
90
    int  findRef( Q3PtrCollection::Item, bool = true ); // find exact item in list
 
91
    int  find( Q3PtrCollection::Item, bool = true ); // find equal item in list
 
92
 
 
93
    uint containsRef( Q3PtrCollection::Item ) const;    // get number of exact matches
 
94
    uint contains( Q3PtrCollection::Item ) const;       // get number of equal matches
 
95
 
 
96
    Q3PtrCollection::Item at( uint index );     // access item at i'th pos
 
97
    int   at() const;                           // get current index
 
98
    Q3LNode *currentNode() const;               // get current node
 
99
 
 
100
    Q3PtrCollection::Item get() const;          // get current item
 
101
 
 
102
    Q3PtrCollection::Item cfirst() const;       // get ptr to first list item
 
103
    Q3PtrCollection::Item clast()  const;       // get ptr to last list item
 
104
    Q3PtrCollection::Item first();              // set first item in list curr
 
105
    Q3PtrCollection::Item last();               // set last item in list curr
 
106
    Q3PtrCollection::Item next();               // set next item in list curr
 
107
    Q3PtrCollection::Item prev();               // set prev item in list curr
 
108
 
 
109
    void  toVector( Q3GVector * ) const;                // put items in vector
 
110
 
 
111
    virtual int compareItems( Q3PtrCollection::Item, Q3PtrCollection::Item );
 
112
 
 
113
#ifndef QT_NO_DATASTREAM
 
114
    virtual QDataStream &read( QDataStream &, Q3PtrCollection::Item & );
 
115
    virtual QDataStream &write( QDataStream &, Q3PtrCollection::Item ) const;
 
116
#endif
 
117
 
 
118
    Q3LNode* begin() const { return firstNode; }
 
119
    Q3LNode* end() const { return 0; }
 
120
    Q3LNode* erase( Q3LNode* it );
 
121
 
 
122
private:
 
123
    void  prepend( Q3PtrCollection::Item );     // add item at start of list
 
124
 
 
125
    void heapSortPushDown( Q3PtrCollection::Item* heap, int first, int last );
 
126
 
 
127
    Q3LNode *firstNode;                         // first node
 
128
    Q3LNode *lastNode;                          // last node
 
129
    Q3LNode *curNode;                           // current node
 
130
    int curIndex;                               // current index
 
131
    uint numNodes;                              // number of nodes
 
132
    Q3GListIteratorList *iterators;             // list of iterators
 
133
 
 
134
    Q3LNode *locate( uint );                    // get node at i'th pos
 
135
    Q3LNode *unlink();                          // unlink node
 
136
};
 
137
 
 
138
 
 
139
inline uint Q3GList::count() const
 
140
{
 
141
    return numNodes;
 
142
}
 
143
 
 
144
inline bool Q3GList::removeFirst()
 
145
{
 
146
    first();
 
147
    return remove();
 
148
}
 
149
 
 
150
inline bool Q3GList::removeLast()
 
151
{
 
152
    last();
 
153
    return remove();
 
154
}
 
155
 
 
156
inline int Q3GList::at() const
 
157
{
 
158
    return curIndex;
 
159
}
 
160
 
 
161
inline Q3PtrCollection::Item Q3GList::at( uint index )
 
162
{
 
163
    Q3LNode *n = locate( index );
 
164
    return n ? n->data : 0;
 
165
}
 
166
 
 
167
inline Q3LNode *Q3GList::currentNode() const
 
168
{
 
169
    return curNode;
 
170
}
 
171
 
 
172
inline Q3PtrCollection::Item Q3GList::get() const
 
173
{
 
174
    return curNode ? curNode->data : 0;
 
175
}
 
176
 
 
177
inline Q3PtrCollection::Item Q3GList::cfirst() const
 
178
{
 
179
    return firstNode ? firstNode->data : 0;
 
180
}
 
181
 
 
182
inline Q3PtrCollection::Item Q3GList::clast() const
 
183
{
 
184
    return lastNode ? lastNode->data : 0;
 
185
}
 
186
 
 
187
 
 
188
/*****************************************************************************
 
189
  Q3GList stream functions
 
190
 *****************************************************************************/
 
191
 
 
192
#ifndef QT_NO_DATASTREAM
 
193
Q_COMPAT_EXPORT QDataStream &operator>>( QDataStream &, Q3GList & );
 
194
Q_COMPAT_EXPORT QDataStream &operator<<( QDataStream &, const Q3GList & );
 
195
#endif
 
196
 
 
197
/*****************************************************************************
 
198
  Q3GListIterator class
 
199
 *****************************************************************************/
 
200
 
 
201
class Q_COMPAT_EXPORT Q3GListIterator                   // Q3GList iterator
 
202
{
 
203
friend class Q3GList;
 
204
friend class Q3GListIteratorList;
 
205
protected:
 
206
    Q3GListIterator( const Q3GList & );
 
207
    Q3GListIterator( const Q3GListIterator & );
 
208
    Q3GListIterator &operator=( const Q3GListIterator & );
 
209
   ~Q3GListIterator();
 
210
 
 
211
    bool  atFirst() const;                      // test if at first item
 
212
    bool  atLast()  const;                      // test if at last item
 
213
    Q3PtrCollection::Item         toFirst();                            // move to first item
 
214
    Q3PtrCollection::Item         toLast();                             // move to last item
 
215
 
 
216
    Q3PtrCollection::Item         get() const;                          // get current item
 
217
    Q3PtrCollection::Item         operator()();                         // get current and move to next
 
218
    Q3PtrCollection::Item         operator++();                         // move to next item (prefix)
 
219
    Q3PtrCollection::Item         operator+=(uint);                     // move n positions forward
 
220
    Q3PtrCollection::Item         operator--();                         // move to prev item (prefix)
 
221
    Q3PtrCollection::Item         operator-=(uint);                     // move n positions backward
 
222
 
 
223
protected:
 
224
    Q3GList *list;                              // reference to list
 
225
 
 
226
private:
 
227
    Q3LNode  *curNode;                          // current node in list
 
228
};
 
229
 
 
230
 
 
231
inline bool Q3GListIterator::atFirst() const
 
232
{
 
233
    return curNode == list->firstNode;
 
234
}
 
235
 
 
236
inline bool Q3GListIterator::atLast() const
 
237
{
 
238
    return curNode == list->lastNode;
 
239
}
 
240
 
 
241
inline Q3PtrCollection::Item Q3GListIterator::get() const
 
242
{
 
243
    return curNode ? curNode->data : 0;
 
244
}
 
245
 
 
246
class Q_COMPAT_EXPORT Q3GListStdIterator
 
247
{
 
248
public:
 
249
    inline Q3GListStdIterator( Q3LNode* n ) : node( n ){}
 
250
    inline operator Q3LNode* () { return node; }
 
251
protected:
 
252
    inline Q3LNode *next() { return node->next; }
 
253
    Q3LNode *node;
 
254
};
 
255
 
 
256
#endif  // Q3GLIST_H