⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlinkedlist.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtCore module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qlinkedlist.h"QLinkedListData QLinkedListData::shared_null = {    &QLinkedListData::shared_null, &QLinkedListData::shared_null, Q_ATOMIC_INIT(1), 0, true};/*! \class QLinkedList    \brief The QLinkedList class is a template class that provides linked lists.    \ingroup tools    \ingroup shared    \mainclass    \reentrant    QLinkedList\<T\> is one of Qt's generic \l{container classes}. It    stores a list of values and provides iterator-based access as    well as \l{constant time} insertions and removals.    QList\<T\>, QLinkedList\<T\>, and QVector\<T\> provide similar    functionality. Here's an overview:    \list    \i For most purposes, QList is the right class to use. Its       index-based API is more convenient than QLinkedList's       iterator-based API, and it is usually faster than       QVector because of the way it stores its items in       memory (see \l{Algorithmic Complexity} for details).       It also expands to less code in your executable.    \i If you need a real linked list, with guarantees of \l{constant       time} insertions in the middle of the list and iterators to       items rather than indexes, use QLinkedList.    \i If you want the items to occupy adjacent memory positions,       use QVector.    \endlist    Here's an example of a QLinkedList that stores integers and a    QLinkedList that stores QTime values:    \code        QLinkedList<int> integerList;        QLinkedList<QTime> timeList;    \endcode    QLinkedList stores a list of items. The default constructor    creates an empty list. To insert items into the list, you can use    operator<<():    \code        QLinkedList<QString> list;        list << "one" << "two" << "three";        // list: ["one", "two", "three"]    \endcode    If you want to get the first or last item in a linked list, use    first() or last(). If you want to remove an item from either end    of the list, use removeFirst() or removeLast(). If you want to    remove all occurrences of a given value in the list, use    removeAll().    A common requirement is to remove the first or last item in the    list and do something with it. For this, QLinkedList provides    takeFirst() and takeLast(). Here's a loop that removes the items    from a list one at a time and calls \c delete on them:    \code        QLinkedList<QWidget *> list;        ...        while (!list.isEmpty())            delete list.takeFirst();    \endcode    QLinkedList's value type must be an \l{assignable data type}.    This covers most data types that are commonly used, but the    compiler won't let you, for example, store a QWidget as a value;    instead, store a QWidget *. A few functions have additional    requirements; for example, contains() and removeAll() expect the    value type to support \c operator==(). These requirements are    documented on a per-function basis.    If you want to insert, modify, or remove items in the middle of    the list, you must use an iterator. QLinkedList provides both    \l{Java-style iterators} (QLinkedListIterator and    QMutableLinkedListIterator) and \l{STL-style iterators}    (QLinkedList::const_iterator and QLinkedList::iterator). See the    documentation for these classes for details.    \sa QListIterator, QMutableListIterator, QList, QVector*//*! \fn QLinkedList::QLinkedList()    Constructs an empty list.*//*! \fn QLinkedList::QLinkedList(const QLinkedList<T> &other)    Constructs a copy of \a other.    This operation occurs in \l{constant time}, because QLinkedList    is \l{implicitly shared}. This makes returning a QLinkedList from    a function very fast. If a shared instance is modified, it will    be copied (copy-on-write), and this takes \l{linear time}.    \sa operator=()*//*! \fn QLinkedList::~QLinkedList()    Destroys the list. References to the values in the list, and all    iterators over this list, become invalid.*//*! \fn QLinkedList<T> &QLinkedList::operator=(const QLinkedList<T> &other)    Assigns \a other to this list and returns a reference to this    list.*//*! \fn bool QLinkedList::operator==(const QLinkedList<T> &other) const    Returns true if \a other is equal to this list; otherwise returns    false.    Two lists are considered equal if they contain the same values in    the same order.    This function requires the value type to implement \c    operator==().    \sa operator!=()*//*! \fn bool QLinkedList::operator!=(const QLinkedList<T> &other) const    Returns true if \a other is not equal to this list; otherwise    returns false.    Two lists are considered equal if they contain the same values in    the same order.    This function requires the value type to implement \c    operator==().    \sa operator==()*//*! \fn int QLinkedList::size() const    Returns the number of items in the list.    \sa isEmpty(), count()*//*! \fn void QLinkedList::detach()    \internal*//*! \fn bool QLinkedList::isDetached() const    \internal*//*! \fn void QLinkedList::setSharable(bool sharable)    \internal*//*! \fn bool QLinkedList::isEmpty() const    Returns true if the list contains no items; otherwise returns    false.    \sa size()*//*! \fn void QLinkedList::clear()    Removes all the items in the list.    \sa removeAll()*//*! \fn void QLinkedList::append(const T &value)    Inserts \a value at the end of the list.    Example:    \code        QLinkedList<QString> list;        list.append("one");        list.append("two");        list.append("three");        // list: ["one", "two", "three"]    \endcode    This is the same as list.insert(end(), \a value).    \sa operator<<(), prepend(), insert()*//*! \fn void QLinkedList::prepend(const T &value)    Inserts \a value at the beginning of the list.    Example:    \code        QLinkedList<QString> list;        list.prepend("one");        list.prepend("two");        list.prepend("three");        // list: ["three", "two", "one"]    \endcode    This is the same as list.insert(begin(), \a value).    \sa append(), insert()*//*! \fn int QLinkedList::removeAll(const T &value)    Removes all occurrences of \a value in the list.    Example:    \code        QList<QString> list;        list << "sun" << "cloud" << "sun" << "rain";        list.removeAll("sun");        // list: ["cloud", "rain"]    \endcode    This function requires the value type to have an implementation of    \c operator==().    \sa insert()*//*! \fn bool QLinkedList::contains(const T &value) const    Returns true if the list contains an occurrence of \a value;    otherwise returns false.    This function requires the value type to have an implementation of    \c operator==().    \sa QListIterator::findNext(), QListIterator::findPrevious()*//*! \fn int QLinkedList::count(const T &value) const    Returns the number of occurrences of \a value in the list.    This function requires the value type to have an implementation of    \c operator==().    \sa contains()*//*! \fn QLinkedList::iterator QLinkedList::begin()    Returns an \l{STL-style iterator} pointing to the first item in    the list.    \sa constBegin(), end()*//*! \fn QLinkedList::const_iterator QLinkedList::begin() const    \overload*//*! \fn QLinkedList::const_iterator QLinkedList::constBegin() const    Returns a const \l{STL-style iterator} pointing to the first item    in the list.    \sa begin(), constEnd()*//*! \fn QLinkedList::iterator QLinkedList::end()    Returns an \l{STL-style iterator} pointing to the imaginary item    after the last item in the list.    \sa begin(), constEnd()*//*! \fn QLinkedList::const_iterator QLinkedList::end() const    \overload*//*! \fn QLinkedList::const_iterator QLinkedList::constEnd() const    Returns a const \l{STL-style iterator} pointing to the imaginary    item after the last item in the list.    \sa constBegin(), end()*//*! \fn QLinkedList::iterator QLinkedList::insert(iterator before, const T &value)    Inserts \a value in front of the item pointed to by the iterator    \a before. Returns an iterator pointing at the inserted item.    \sa erase()*//*! \fn QLinkedList::iterator QLinkedList::erase(iterator pos)    Removes the item pointed to by the iterator \a pos from the list,    and returns an iterator to the next item in the list (which may be    end()).    \sa insert()*//*! \fn QLinkedList::iterator QLinkedList::erase(iterator begin, iterator end)    \overload    Removes all the items from \a begin up to (but not including) \a    end.*//*! \typedef QLinkedList::Iterator    Qt-style synonym for QList::iterator.*//*! \typedef QLinkedList::ConstIterator    Qt-style synonym for QList::const_iterator.*//*!    \typedef QLinkedList::size_type    Typedef for int. Provided for STL compatibility.*//*!    \typedef QLinkedList::value_type    Typedef for T. Provided for STL compatibility.*//*!    \typedef QLinkedList::pointer    Typedef for T *. Provided for STL compatibility.*//*!    \typedef QLinkedList::const_pointer    Typedef for const T *. Provided for STL compatibility.*//*!    \typedef QLinkedList::reference    Typedef for T &. Provided for STL compatibility.*//*!    \typedef QLinkedList::const_reference    Typedef for const T &. Provided for STL compatibility.*//*!

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -