diff -r 000000000000 -r 1918ee327afb src/qt3support/tools/q3valuelist.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/qt3support/tools/q3valuelist.h Mon Jan 11 14:00:40 2010 +0000 @@ -0,0 +1,238 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt3Support module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef Q3VALUELIST_H +#define Q3VALUELIST_H + +#include +#include +#include +#include + +#ifndef QT_NO_STL +#include +#include +#endif + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Qt3SupportLight) + +template +class Q3ValueListIterator : public QLinkedList::iterator +{ +public: + inline Q3ValueListIterator() : + QLinkedList::iterator() {} + inline Q3ValueListIterator(const Q3ValueListIterator &o) : + QLinkedList::iterator(o) {} + inline Q3ValueListIterator(const typename QLinkedList::iterator &o) : + QLinkedList::iterator(o) {} +}; + +template +class Q3ValueListConstIterator : public QLinkedList::const_iterator +{ +public: + inline Q3ValueListConstIterator() {} + inline Q3ValueListConstIterator(const Q3ValueListConstIterator &o) : + QLinkedList::const_iterator(o) {} + inline Q3ValueListConstIterator(const typename QLinkedList::const_iterator &o) : + QLinkedList::const_iterator(o) {} + inline Q3ValueListConstIterator(const typename QLinkedList::iterator &o) : + QLinkedList::const_iterator(o) {} +}; + +template +class Q3ValueList : public QLinkedList +{ +public: + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; +#ifndef QT_NO_STL + typedef ptrdiff_t difference_type; +#else + typedef int difference_type; +#endif + + typedef Q3ValueListIterator Iterator; + typedef Q3ValueListConstIterator ConstIterator; + typedef Q3ValueListIterator iterator; + typedef Q3ValueListConstIterator const_iterator; + typedef typename QLinkedList::size_type size_type; + + /** + * API + */ + Q3ValueList() {} + Q3ValueList(const Q3ValueList& l) : QLinkedList(l) {} + Q3ValueList(const QLinkedList& l) : QLinkedList(l) {} + Q3ValueList(const QList& l) + { + for (int i = 0; i < l.size(); ++i) append(l.at(i)); + } +#ifndef QT_NO_STL + Q3ValueList(const std::list& l) + { + qCopy(l.begin(), l.end(), std::back_inserter(*this)); + } +#endif + ~Q3ValueList() {} + + Q3ValueList& operator= (const Q3ValueList& l) + { + QLinkedList::operator=(l); + return *this; + } + Q3ValueList& operator= (const QList& l) + { + this->clear(); + for (int i = 0; i < l.size(); ++i) append(l.at(i)); + return *this; + } +#ifndef QT_NO_STL + Q3ValueList& operator= (const std::list& l) + { + this->detach(); + qCopy(l.begin(), l.end(), std::back_inserter(*this)); + return *this; + } + bool operator== (const std::list& l) const + { + if (this->size() != l.size()) + return false; + typename Q3ValueList::const_iterator it2 = this->begin(); +#if !defined(Q_CC_MIPS) + typename +#endif + std::list::const_iterator it = l.begin(); + for (; it2 != this->end(); ++it2, ++it) + if (!((*it2) == (*it))) + return false; + return true; + } +#endif + bool operator== (const Q3ValueList& l) const { return QLinkedList::operator==(l); } + bool operator!= (const Q3ValueList& l) const { return QLinkedList::operator!=(l); } + + operator QList() const { + QList list; + for (typename Q3ValueList::const_iterator it = QLinkedList::constBegin(); + it != QLinkedList::constEnd(); ++it) + list.append(*it); + return list; + } + + inline Q3ValueList& operator<< (const T& x) { append(x); return *this; } + + void insert(typename Q3ValueList::Iterator pos, + typename Q3ValueList::size_type n, + const T& x); + + typename Q3ValueList::Iterator insert(typename Q3ValueList::Iterator pos, + const T& x) + { return QLinkedList::insert(pos, x); } + typename Q3ValueList::Iterator remove(typename Q3ValueList::Iterator pos) + { return QLinkedList::erase(pos); } + int remove(const T &value) + { return QLinkedList::removeAll(value); } + + inline Q3ValueList operator+ (const Q3ValueList& l) const + { return static_cast >(QLinkedList::operator+(l)); } + inline Q3ValueList& operator+= (const Q3ValueList& l) + { QLinkedList::operator+=(l); return *this; } + + typename Q3ValueList::Iterator fromLast() + { return (this->isEmpty() ? this->end() : --this->end()); } + typename Q3ValueList::ConstIterator fromLast() const + { return (this->isEmpty() ? this->end() : --this->end()); } + + typename Q3ValueList::Iterator append(const T& x) + { QLinkedList::append(x); return --this->end(); } + typename Q3ValueList::Iterator prepend(const T& x) + { QLinkedList::prepend(x); return this->begin(); } + + typename Q3ValueList::Iterator at(typename Q3ValueList::size_type i) + { Q_ASSERT(i < this->size()); this->detach(); return this->begin()+i; } + typename Q3ValueList::ConstIterator at(typename Q3ValueList::size_type i) const + { Q_ASSERT(i < this->size()); return this->begin()+i; } + typename Q3ValueList::size_type contains(const T& x) const + { return QLinkedList::count(x); } + + Q3ValueList& operator+= (const T& x) { append(x); return *this; } + + T& operator[] (typename Q3ValueList::size_type i) { return *at(i); } + const T& operator[] (typename Q3ValueList::size_type i) const { return *at(i); } + +}; + +template +Q_OUTOFLINE_TEMPLATE void Q3ValueList::insert(typename Q3ValueList::Iterator pos, + typename Q3ValueList::size_type n, const T& x) +{ + for (; n > 0; --n) + this->insert(pos, x); +} + +#ifndef QT_NO_DATASTREAM +template +Q_OUTOFLINE_TEMPLATE QDataStream& operator>>(QDataStream& s, Q3ValueList& l) +{ + return operator>>(s, static_cast &>(l)); +} + +template +Q_OUTOFLINE_TEMPLATE QDataStream& operator<<(QDataStream& s, const Q3ValueList& l) +{ + return operator<<(s, static_cast &>(l)); +} +#endif + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // Q3VALUELIST_H