- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- Class List
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends

# QLinkedList< T > Class Template Reference

Search for all occurrences

## Detailed Description

### template<class T>
class QLinkedList< T >

Definition at line 78 of file qlinkedlist.h.

`#include <qlinkedlist.h>`

List of all members.

## Classes
class | const_iterator
class | iterator
## Public Types
typedef iterator | Iterator
typedef const_iterator | ConstIterator
typedef int | size_type
typedef T | value_type
typedef value_type * | pointer
typedef const value_type * | const_pointer
typedef value_type & | reference
typedef const value_type & | const_reference
typedef qptrdiff | difference_type
## Public Member Functions
| QLinkedList ()
| QLinkedList (const QLinkedList< T > &l)
| ~QLinkedList ()
QLinkedList< T > & | operator= (const QLinkedList< T > &)
bool | operator== (const QLinkedList< T > &l) const
bool | operator!= (const QLinkedList< T > &l) const
int | size () const
void | detach ()
bool | isDetached () const
void | setSharable (bool sharable)
bool | isSharedWith (const QLinkedList< T > &other) const
bool | isEmpty () const
void | clear ()
void | append (const T &)
void | prepend (const T &)
T | takeFirst ()
T | takeLast ()
int | removeAll (const T &t)
bool | removeOne (const T &t)
bool | contains (const T &t) const
int | count (const T &t) const
iterator | begin ()
const_iterator | begin () const
const_iterator | constBegin () const
iterator | end ()
const_iterator | end () const
const_iterator | constEnd () const
iterator | insert (iterator before, const T &t)
iterator | erase (iterator pos)
iterator | erase (iterator first, iterator last)
int | count () const
T & | first ()
const T & | first () const
T & | last ()
const T & | last () const
void | removeFirst ()
void | removeLast ()
bool | startsWith (const T &t) const
bool | endsWith (const T &t) const
void | push_back (const T &t)
void | push_front (const T &t)
T & | front ()
const T & | front () const
T & | back ()
const T & | back () const
void | pop_front ()
void | pop_back ()
bool | empty () const
std::list< T > | toStdList () const
QLinkedList< T > & | operator+= (const QLinkedList< T > &l)
QLinkedList< T > | operator+ (const QLinkedList< T > &l) const
QLinkedList< T > & | operator+= (const T &t)
QLinkedList< T > & | operator<< (const T &t)
QLinkedList< T > & | operator<< (const QLinkedList< T > &l)
## Static Public Member Functions
static QLinkedList< T > | fromStdList (const std::list< T > &list)
## Friends
class | iterator
class | const_iterator

## Member Typedef Documentation

typedef iterator Iterator

Search for all occurrences

Definition at line 188 of file qlinkedlist.h.

typedef const_iterator ConstIterator

Search for all occurrences

Definition at line 189 of file qlinkedlist.h.

typedef int size_type

Search for all occurrences

Definition at line 210 of file qlinkedlist.h.

typedef T value_type

Search for all occurrences

Definition at line 211 of file qlinkedlist.h.

typedef value_type* pointer

Search for all occurrences

Definition at line 212 of file qlinkedlist.h.

typedef const value_type* const_pointer

Search for all occurrences

Definition at line 213 of file qlinkedlist.h.

typedef value_type& reference

Search for all occurrences

Definition at line 214 of file qlinkedlist.h.

typedef const value_type& const_reference

Search for all occurrences

Definition at line 215 of file qlinkedlist.h.

typedef qptrdiff difference_type

Search for all occurrences

Definition at line 216 of file qlinkedlist.h.

## Constructor & Destructor Documentation

QLinkedList | ( |  | ) | `[inline]`

Definition at line 84 of file qlinkedlist.h.

    : d(&QLinkedListData::shared_null) { d->ref.ref(); }

QLinkedList | ( | const QLinkedList< T > & | l | ) | `[inline]`

Definition at line 85 of file qlinkedlist.h.

    : d(l.d) { d->ref.ref(); if (!d->sharable) detach(); }

~QLinkedList | ( |  | ) | `[inline]`

Definition at line 253 of file qlinkedlist.h.

    {
        if (!d)
            return;
        if (!d->ref.deref())
            free(d);
    }

## Member Function Documentation

QLinkedList< T > & operator= | ( | const QLinkedList< T > & | l | ) |

Definition at line 312 of file qlinkedlist.h.

    {
        if (d != l.d) {
            QLinkedListData *o = l.d;
            o->ref.ref();
            if (!d->ref.deref())
                free(d);
            d = o;
            if (!d->sharable)
                detach_helper();
        }
        return *this;
    }

bool operator== | ( | const QLinkedList< T > & | l | ) | const

Definition at line 327 of file qlinkedlist.h.

    {
        if (d->size != l.d->size)
            return false;
        if (e == l.e)
            return true;
        Node *i = e->n;
        Node *il = l.e->n;
        while (i != e) {
            if (! (i->t == il->t))
                return false;
            i = i->n;
            il = il->n;
        }
        return true;
    }

bool operator!= | ( | const QLinkedList< T > & | l | ) | const `[inline]`

Definition at line 89 of file qlinkedlist.h.

    { return !(*this == l); }

int size | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 91 of file qlinkedlist.h.

    { return d->size; }

void detach | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 92 of file qlinkedlist.h.

        { if (d->ref != 1) detach_helper(); }

bool isDetached | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 94 of file qlinkedlist.h.

    { return d->ref == 1; }

void setSharable | ( | bool | sharable | ) | `[inline]`

Search for all occurrences

Definition at line 95 of file qlinkedlist.h.

    { if (!sharable) detach(); d->sharable = sharable; }

bool isSharedWith | ( | const QLinkedList< T > & | other | ) | const `[inline]`

Search for all occurrences

Definition at line 96 of file qlinkedlist.h.

    { return d == other.d; }

bool isEmpty | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 98 of file qlinkedlist.h.

    { return d->size == 0; }

void clear | ( |  | ) |

Search for all occurrences

Definition at line 306 of file qlinkedlist.h.

    {
        *this = QLinkedList<T>();
    }

void append | ( | const T & | t | ) |

Search for all occurrences

Definition at line 345 of file qlinkedlist.h.

    {
        detach();
        Node *i = new Node(t);
        i->n = e;
        i->p = e->p;
        i->p->n = i;
        e->p = i;
        d->size++;
    }

void prepend | ( | const T & | t | ) |

Search for all occurrences

Definition at line 357 of file qlinkedlist.h.

    {
        detach();
        Node *i = new Node(t);
        i->n = e->n;
        i->p = e;
        i->n->p = i;
        e->n = i;
        d->size++;
    }

T takeFirst | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 404 of file qlinkedlist.h.

    {
        T t = first();
        removeFirst();
        return t;
    }

T takeLast | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 412 of file qlinkedlist.h.

    {
        T t = last();
        removeLast();
        return t;
    }

int removeAll | ( | const T & | t | ) |

Search for all occurrences

Definition at line 369 of file qlinkedlist.h.

    {
        detach();
        const T t = _t;
        Node *i = e->n;
        int c = 0;
        while (i != e) {
            if (i->t == t) {
                Node *n = i;
                i->n->p = i->p;
                i->p->n = i->n;
                i = i->n;
                delete n;
                c++;
            } else {
                i = i->n;
            }
        }
        d->size-=c;
        return c;
    }

bool removeOne | ( | const T & | t | ) |

Search for all occurrences

Definition at line 392 of file qlinkedlist.h.

    {
        detach();
        iterator it = qFind(begin(), end(), _t);
        if (it != end()) {
            erase(it);
            return true;
        }
        return false;
    }

bool contains | ( | const T & | t | ) | const

Search for all occurrences

Definition at line 420 of file qlinkedlist.h.

    {
        Node *i = e;
        while ((i = i->n) != e)
            if (i->t == t)
                return true;
        return false;
    }

int count | ( | const T & | t | ) | const

Search for all occurrences

Definition at line 430 of file qlinkedlist.h.

    {
        Node *i = e;
        int c = 0;
        while ((i = i->n) != e)
            if (i->t == t)
                c++;
        return c;
    }

iterator begin | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 177 of file qlinkedlist.h.

    { detach(); return e->n; }

const_iterator begin | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 178 of file qlinkedlist.h.

    { return e->n; }

const_iterator constBegin | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 179 of file qlinkedlist.h.

    { return e->n; }

iterator end | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 180 of file qlinkedlist.h.

    { detach(); return e; }

const_iterator end | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 181 of file qlinkedlist.h.

    { return e; }

const_iterator constEnd | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 182 of file qlinkedlist.h.

    { return e; }

QLinkedList< T >::iterator insert | ( | iterator | before,
|  | const T & | t
| ) |  |

Search for all occurrences

Definition at line 442 of file qlinkedlist.h.

    {
        Node *i = before.i;
        Node *m = new Node(t);
        m->n = i;
        m->p = i->p;
        m->p->n = m;
        i->p = m;
        d->size++;
        return m;
    }

QLinkedList< T >::iterator erase | ( | iterator | pos | ) |

Search for all occurrences

Definition at line 465 of file qlinkedlist.h.

    {
        detach();
        Node *i = pos.i;
        if (i != e) {
            Node *n = i;
            i->n->p = i->p;
            i->p->n = i->n;
            i = i->n;
            delete n;
            d->size--;
        }
        return i;
    }

iterator erase | ( | iterator | first,
|  | iterator | last
| ) |  |

Search for all occurrences

int count | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 190 of file qlinkedlist.h.

    { return d->size; }

T& first | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 191 of file qlinkedlist.h.

    { Q_ASSERT(!isEmpty()); return *begin(); }

const T& first | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 192 of file qlinkedlist.h.

    { Q_ASSERT(!isEmpty()); return *begin(); }

T& last | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 193 of file qlinkedlist.h.

    { Q_ASSERT(!isEmpty()); return *(--end()); }

const T& last | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 194 of file qlinkedlist.h.

    { Q_ASSERT(!isEmpty()); return *(--end()); }

void removeFirst | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 195 of file qlinkedlist.h.

    { Q_ASSERT(!isEmpty()); erase(begin()); }

void removeLast | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 196 of file qlinkedlist.h.

    { Q_ASSERT(!isEmpty()); erase(--end()); }

bool startsWith | ( | const T & | t | ) | const `[inline]`

Search for all occurrences

Definition at line 197 of file qlinkedlist.h.

    { return !isEmpty() && first() == t; }

bool endsWith | ( | const T & | t | ) | const `[inline]`

Search for all occurrences

Definition at line 198 of file qlinkedlist.h.

    { return !isEmpty() && last() == t; }

void push_back | ( | const T & | t | ) | `[inline]`

Search for all occurrences

Definition at line 201 of file qlinkedlist.h.

    { append(t); }

void push_front | ( | const T & | t | ) | `[inline]`

Search for all occurrences

Definition at line 202 of file qlinkedlist.h.

    { prepend(t); }

T& front | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 203 of file qlinkedlist.h.

    { return first(); }

const T& front | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 204 of file qlinkedlist.h.

    { return first(); }

T& back | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 205 of file qlinkedlist.h.

    { return last(); }

const T& back | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 206 of file qlinkedlist.h.

    { return last(); }

void pop_front | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 207 of file qlinkedlist.h.

    { removeFirst(); }

void pop_back | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 208 of file qlinkedlist.h.

    { removeLast(); }

bool empty | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 209 of file qlinkedlist.h.

    { return isEmpty(); }

static QLinkedList<T> fromStdList | ( | const std::list< T > & | list | ) | `[inline, static]`

Search for all occurrences

Definition at line 219 of file qlinkedlist.h.

        { QLinkedList<T> tmp; qCopy(list.begin(), list.end(), std::back_inserter(tmp)); return tmp; }

std::list<T> toStdList | ( |  | ) | const `[inline]`

Search for all occurrences

Definition at line 221 of file qlinkedlist.h.

        { std::list<T> tmp; qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }

QLinkedList< T > & operator+= | ( | const QLinkedList< T > & | l | ) |

Definition at line 481 of file qlinkedlist.h.

    {
        detach();
        int n = l.d->size;
        d->size += n;
        Node *original = l.e->n;
        while (n--) {
            QT_TRY {
                Node *copy = new Node(original->t);
                original = original->n;
                copy->n = e;
                copy->p = e->p;
                copy->p->n = copy;
                e->p = copy;
            } QT_CATCH(...) {
                // restore the original list
                while (n++<d->size)
                    removeLast();
                QT_RETHROW;
            }
        }
        return *this;
    }

QLinkedList< T > operator+ | ( | const QLinkedList< T > & | l | ) | const

Definition at line 506 of file qlinkedlist.h.

    {
        QLinkedList<T> n = *this;
        n += l;
        return n;
    }

QLinkedList<T>& operator+= | ( | const T & | t | ) | `[inline]`

Definition at line 243 of file qlinkedlist.h.

    { append(t); return *this; }

QLinkedList<T>& operator<< | ( | const T & | t | ) | `[inline]`

Definition at line 244 of file qlinkedlist.h.

    { append(t); return *this; }

QLinkedList<T>& operator<< | ( | const QLinkedList< T > & | l | ) | `[inline]`

Definition at line 245 of file qlinkedlist.h.

    { *this += l; return *this; }

## Friends And Related Function Documentation

friend class iterator `[friend]`

Search for all occurrences

Definition at line 144 of file qlinkedlist.h.

friend class const_iterator `[friend]`

Search for all occurrences

Definition at line 174 of file qlinkedlist.h.

## Member Data Documentation

QLinkedListData* d

Search for all occurrences

Definition at line 81 of file qlinkedlist.h.

QLinkedListNode<T>* e

Search for all occurrences

Definition at line 81 of file qlinkedlist.h.

The documentation for this class was generated from the following file:

- QtCore/qlinkedlist.h