45 #include <QtCore/qiterator.h> 46 #include <QtCore/qatomic.h> 61 QLinkedListData *n, *
p;
88 #ifdef Q_COMPILER_RVALUE_REFS 90 {
qSwap(
d, other.d);
return *
this; }
96 inline int size()
const {
return d->size; }
98 {
if (
d->ref != 1) detach_helper(); }
100 inline void setSharable(
bool sharable) {
if (!sharable) detach();
d->sharable = sharable; }
103 inline bool isEmpty()
const {
return d->size == 0; }
107 void append(
const T &);
108 void prepend(
const T &);
111 int removeAll(
const T &
t);
112 bool removeOne(
const T &t);
113 bool contains(
const T &t)
const;
114 int count(
const T &t)
const;
116 class const_iterator;
144 { Node *
n = i;
if (j > 0)
while (j--) n = n->
n;
else while (j++) n = n->
p;
return n; }
149 friend class iterator;
174 { Node *
n = i;
if (j > 0)
while (j--) n = n->
n;
else while (j++) n = n->
p;
return n; }
179 friend class const_iterator;
182 inline iterator
begin() { detach();
return e->n; }
183 inline const_iterator
begin()
const {
return e->n; }
185 inline iterator
end() { detach();
return e; }
186 inline const_iterator
end()
const {
return e; }
187 inline const_iterator
constEnd()
const {
return e; }
188 iterator insert(iterator before,
const T &t);
189 iterator erase(iterator pos);
190 iterator erase(iterator first, iterator last);
195 inline int count()
const {
return d->size; }
208 inline T&
front() {
return first(); }
209 inline const T&
front()
const {
return first(); }
210 inline T&
back() {
return last(); }
211 inline const T&
back()
const {
return last(); }
225 {
QLinkedList<T> tmp;
qCopy(list.begin(), list.end(), std::back_inserter(tmp));
return tmp; }
227 { std::list<T> tmp;
qCopy(constBegin(), constEnd(), std::back_inserter(tmp));
return tmp; }
232 inline QT3_SUPPORT iterator
remove(iterator pos) {
return erase(pos); }
233 inline QT3_SUPPORT
int findIndex(
const T& t)
const 234 {
int i=0;
for (const_iterator
it = begin();
it !=
end(); ++
it, ++i)
if(*
it == t)
return i;
return -1;}
235 inline QT3_SUPPORT iterator find(iterator from,
const T& t)
236 {
while (from !=
end() && !(*from == t)) ++from;
return from; }
237 inline QT3_SUPPORT iterator find(
const T& t)
238 {
return find(begin(), t); }
239 inline QT3_SUPPORT const_iterator find(const_iterator from,
const T& t)
const 240 {
while (from !=
end() && !(*from == t)) ++from;
return from; }
241 inline QT3_SUPPORT const_iterator find(
const T& t)
const 242 {
return find(begin(), t); }
253 void detach_helper();
257 template <
typename T>
266 template <
typename T>
273 x.d->sharable =
true;
274 Node *original = e->
n;
276 while (original != e) {
278 copy->
n =
new Node(original->
t);
280 original = original->
n;
295 template <
typename T>
298 Node *y =
reinterpret_cast<Node*
>(x);
310 template <
typename T>
316 template <
typename T>
331 template <
typename T>
341 if (! (i->
t == il->
t))
349 template <
typename T>
361 template <
typename T>
373 template <
typename T>
396 template <
typename T>
408 template <
typename T>
416 template <
typename T>
424 template <
typename T>
428 while ((i = i->
n) != e)
434 template <
typename T>
439 while ((i = i->
n) != e)
446 template <
typename T>
459 template <
typename T>
463 while (afirst != alast)
469 template <
typename T>
485 template <
typename T>
491 Node *original = l.
e->n;
495 original = original->
n;
510 template <
typename T>
525 #endif // QLINKEDLIST_H T takeFirst()
Removes the first item in the list and returns it.
void clear()
Removes all the items in the list.
bool operator!=(const const_iterator &o) const
Returns true if other points to a different item than this iterator; otherwise returns false...
const_iterator(const const_iterator &o)
Constructs a copy of other.
const value_type & const_reference
Typedef for const T &.
const_iterator operator+(int j) const
Returns an iterator to the item at j positions forward from this iterator.
iterator erase(iterator pos)
Removes the item pointed to by the iterator pos from the list, and returns an iterator to the next it...
const_iterator & operator++()
The prefix ++ operator (++it) advances the iterator to the next item in the list and returns an itera...
const_iterator & operator+=(int j)
Advances the iterator by j items.
const T * operator->() const
Returns a pointer to the current item.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
const_iterator & operator-=(int j)
Makes the iterator go back by j items.
#define QT_END_NAMESPACE
This macro expands to.
T & last()
Returns a reference to the last item in the list.
std::bidirectional_iterator_tag iterator_category
QLinkedList< T > & operator+=(const QLinkedList< T > &l)
Appends the items of the other list to this list and returns a reference to this list.
QLinkedListNode(const T &arg)
iterator & operator--()
The prefix – operator (–it) makes the preceding item current and returns an iterator to the new cur...
void push_front(const T &t)
This function is provided for STL compatibility.
#define it(className, varName)
iterator(const iterator &o)
Constructs a copy of other.
InputIterator qFind(InputIterator first, InputIterator last, const T &val)
iterator operator+(int j) const
Returns an iterator to the item at j positions forward from this iterator.
T & back()
This function is provided for STL compatibility.
const value_type * const_pointer
Typedef for const T *.
const T & back() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
const_iterator & operator--()
The prefix – operator (–it) makes the preceding item current and returns an iterator to the new cur...
const_iterator()
Constructs an uninitialized iterator.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
const_iterator operator++(int)
The postfix ++ operator (it++) advances the iterator to the next item in the list and returns an iter...
const T & first() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
static void clear(QVariant::Private *d)
int count() const
Same as size().
const T & front() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
iterator & operator-=(int j)
Makes the iterator go back by j items.
bool removeOne(const T &t)
Removes the first occurrences of value in the list.
qptrdiff difference_type
Typedef for ptrdiff_t.
int removeAll(const T &t)
Removes all occurrences of value in the list.
void append(const T &)
Inserts value at the end of the list.
bool operator==(const iterator &o) const
Returns true if other points to the same item as this iterator; otherwise returns false...
#define Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(C)
value_type & reference
Typedef for T &.
bool operator!=(const iterator &o) const
Returns true if other points to a different item than this iterator; otherwise returns false...
bool operator!=(const QLinkedList< T > &l) const
Returns true if other is not equal to this list; otherwise returns false.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
T & first()
Returns a reference to the first item in the list.
bool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
iterator & operator+=(int j)
Advances the iterator by j items.
QLinkedList< T > & operator=(const QLinkedList< T > &)
Assigns other to this list and returns a reference to this list.
const T & last() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
~QLinkedList()
Destroys the list.
T & operator*() const
Returns a modifiable reference to the current item.
The QLinkedList class is a template class that provides linked lists.
#define QT_BEGIN_NAMESPACE
This macro expands to.
#define Q_DECLARE_SEQUENTIAL_ITERATOR(C)
static bool isEmpty(const char *str)
The QLinkedList::const_iterator class provides an STL-style const iterator for QLinkedList.
iterator operator--(int)
The postfix – operator (it–) makes the preceding item current and returns an iterator to the previo...
QIntegerForSizeof< void * >::Signed qptrdiff
const_iterator ConstIterator
Qt-style synonym for QLinkedList::const_iterator.
void removeFirst()
Removes the first item in the list.
bool operator==(const QLinkedList< T > &l) const
Returns true if other is equal to this list; otherwise returns false.
iterator operator-(int j) const
Returns an iterator to the item at j positions backward from this iterator.
QLinkedList()
Constructs an empty list.
static QLinkedList< T > fromStdList(const std::list< T > &list)
Returns a QLinkedList object with the data contained in list.
The QLinkedList::iterator class provides an STL-style non-const iterator for QLinkedList.
bool isSharedWith(const QLinkedList< T > &other) const
void qSwap(T &value1, T &value2)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
iterator & operator=(const iterator &o)
Assigns other to this iterator.
void pop_back()
This function is provided for STL compatibility.
const_iterator operator-(int j) const
This function returns an iterator to the item at j positions backward from this iterator.
const_iterator end() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void prepend(const T &)
Inserts value at the beginning of the list.
T * operator->() const
Returns a pointer to the current item.
const_iterator & operator=(const const_iterator &o)
Assigns other to this iterator.
const_iterator operator--(int)
The postfix – operator (it–) makes the preceding item current and returns an iterator to the previo...
bool operator!=(const const_iterator &o) const
void setSharable(bool sharable)
value_type * pointer
Typedef for T *.
QLinkedList< T > & operator+=(const T &t)
Appends value to the list.
const T & operator*() const
Returns a reference to the current item.
std::bidirectional_iterator_tag iterator_category
std::list< T > toStdList() const
Returns a std::list object with the data contained in this QLinkedList.
T takeLast()
Removes the last item in the list and returns it.
void push_back(const T &t)
This function is provided for STL compatibility.
bool startsWith(const T &t) const
Returns true if the list is not empty and its first item is equal to value; otherwise returns false...
const_iterator(iterator ci)
Constructs a copy of other.
QLinkedListNode< T > Node
QLinkedList< T > operator+(const QLinkedList< T > &l) const
Returns a list that contains all the items in this list followed by all the items in the other list...
void removeLast()
Removes the last item in the list.
iterator operator++(int)
The postfix ++ operator (it++) advances the iterator to the next item in the list and returns an iter...
iterator()
Constructs an uninitialized iterator.
const_iterator begin() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int size_type
Typedef for int.
QDataStream & operator<<(QDataStream &s, const QAxBase &c)
T value_type
Typedef for T.
OutputIterator qCopy(InputIterator begin, InputIterator end, OutputIterator dest)
static QLinkedListData shared_null
bool operator==(const const_iterator &o) const
iterator & operator++()
The prefix ++ operator (++it) advances the iterator to the next item in the list and returns an itera...
iterator insert(iterator before, const T &t)
Inserts value in front of the item pointed to by the iterator before.
int size() const
Returns the number of items in the list.
void free(QLinkedListData *)
timeval & operator+=(timeval &t1, const timeval &t2)
iterator Iterator
Qt-style synonym for QLinkedList::iterator.
static const KeyPair *const end
bool empty() const
This function is provided for STL compatibility.
bool operator==(QBool b1, bool b2)
bool endsWith(const T &t) const
Returns true if the list is not empty and its last item is equal to value; otherwise returns false...
bool operator==(const const_iterator &o) const
Returns true if other points to the same item as this iterator; otherwise returns false...
T & front()
This function is provided for STL compatibility.
void pop_front()
This function is provided for STL compatibility.
void swap(QLinkedList< T > &other)
Swaps list other with this list.
QLinkedList(const QLinkedList< T > &l)
Constructs a copy of other.
timeval operator+(const timeval &t1, const timeval &t2)