QLinkedList< T > Class Template Reference

QLinkedList< T > Class Template Reference

#include <qcontainerfwd.h>

Class Description

template<class T>
class QLinkedList< T >

Definition at line 55 of file qcontainerfwd.h.

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_typepointer
 
typedef const value_typeconst_pointer
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef qptrdiff difference_type
 

Public Member Functions

 QLinkedList ()
 
 QLinkedList (const QLinkedList< T > &l)
 
 ~QLinkedList ()
 
QLinkedList< T > & operator= (const QLinkedList< T > &)
 
void swap (QLinkedList< T > &other)
 
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 &)
 
takeFirst ()
 
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

Definition at line 193 of file qlinkedlist.h.

Definition at line 194 of file qlinkedlist.h.

typedef int size_type

Definition at line 215 of file qlinkedlist.h.

typedef T value_type

Definition at line 216 of file qlinkedlist.h.

typedef value_type* pointer

Definition at line 217 of file qlinkedlist.h.

typedef const value_type* const_pointer

Definition at line 218 of file qlinkedlist.h.

Definition at line 219 of file qlinkedlist.h.

typedef const value_type& const_reference

Definition at line 220 of file qlinkedlist.h.

typedef qptrdiff difference_type

Definition at line 221 of file qlinkedlist.h.

Constructor & Destructor Documentation

QLinkedList ( )
inline

Definition at line 84 of file qlinkedlist.h.

QLinkedListData * d
Definition: qlinkedlist.h:81
QBasicAtomicInt ref
Definition: qlinkedlist.h:62
static QLinkedListData shared_null
Definition: qlinkedlist.h:66
QLinkedList ( const QLinkedList< T > &  l)
inline

Definition at line 85 of file qlinkedlist.h.

85 : d(l.d) { d->ref.ref(); if (!d->sharable) detach(); }
void detach()
Definition: qlinkedlist.h:97
QLinkedListData * d
Definition: qlinkedlist.h:81
QBasicAtomicInt ref
Definition: qlinkedlist.h:62
~QLinkedList ( )
inline

Definition at line 258 of file qlinkedlist.h.

259 {
260  if (!d)
261  return;
262  if (!d->ref.deref())
263  free(d);
264 }
QLinkedListData * d
Definition: qlinkedlist.h:81
QBasicAtomicInt ref
Definition: qlinkedlist.h:62

Member Function Documentation

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

Definition at line 317 of file qlinkedlist.h.

318 {
319  if (d != l.d) {
320  QLinkedListData *o = l.d;
321  o->ref.ref();
322  if (!d->ref.deref())
323  free(d);
324  d = o;
325  if (!d->sharable)
326  detach_helper();
327  }
328  return *this;
329 }
QLinkedListData * d
Definition: qlinkedlist.h:81
QBasicAtomicInt ref
Definition: qlinkedlist.h:62
void swap ( QLinkedList< T > &  other)
inline

Definition at line 92 of file qlinkedlist.h.

92 { qSwap(d, other.d); }
QLinkedListData * d
Definition: qlinkedlist.h:81
Q_INLINE_TEMPLATE void qSwap(QScopedPointer< T, Cleanup > &p1, QScopedPointer< T, Cleanup > &p2)
bool operator== ( const QLinkedList< T > &  l) const

Definition at line 332 of file qlinkedlist.h.

333 {
334  if (d->size != l.d->size)
335  return false;
336  if (e == l.e)
337  return true;
338  Node *i = e->n;
339  Node *il = l.e->n;
340  while (i != e) {
341  if (! (i->t == il->t))
342  return false;
343  i = i->n;
344  il = il->n;
345  }
346  return true;
347 }
QLinkedListData * d
Definition: qlinkedlist.h:81
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
bool operator!= ( const QLinkedList< T > &  l) const
inline

Definition at line 94 of file qlinkedlist.h.

94 { return !(*this == l); }
int size ( ) const
inline

Definition at line 96 of file qlinkedlist.h.

96 { return d->size; }
QLinkedListData * d
Definition: qlinkedlist.h:81
void detach ( )
inline

Definition at line 97 of file qlinkedlist.h.

98  { if (d->ref != 1) detach_helper(); }
QLinkedListData * d
Definition: qlinkedlist.h:81
QBasicAtomicInt ref
Definition: qlinkedlist.h:62
bool isDetached ( ) const
inline

Definition at line 99 of file qlinkedlist.h.

99 { return d->ref == 1; }
QLinkedListData * d
Definition: qlinkedlist.h:81
QBasicAtomicInt ref
Definition: qlinkedlist.h:62
void setSharable ( bool  sharable)
inline

Definition at line 100 of file qlinkedlist.h.

100 { if (!sharable) detach(); d->sharable = sharable; }
void detach()
Definition: qlinkedlist.h:97
QLinkedListData * d
Definition: qlinkedlist.h:81
bool isSharedWith ( const QLinkedList< T > &  other) const
inline

Definition at line 101 of file qlinkedlist.h.

101 { return d == other.d; }
QLinkedListData * d
Definition: qlinkedlist.h:81
bool isEmpty ( ) const
inline

Definition at line 103 of file qlinkedlist.h.

103 { return d->size == 0; }
QLinkedListData * d
Definition: qlinkedlist.h:81
void clear ( )

Definition at line 311 of file qlinkedlist.h.

312 {
313  *this = QLinkedList<T>();
314 }
void append ( const T &  t)

Definition at line 350 of file qlinkedlist.h.

351 {
352  detach();
353  Node *i = new Node(t);
354  i->n = e;
355  i->p = e->p;
356  i->p->n = i;
357  e->p = i;
358  d->size++;
359 }
void detach()
Definition: qlinkedlist.h:97
QLinkedListData * d
Definition: qlinkedlist.h:81
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
GLdouble GLdouble t
Definition: GLee.h:1181
void prepend ( const T &  t)

Definition at line 362 of file qlinkedlist.h.

363 {
364  detach();
365  Node *i = new Node(t);
366  i->n = e->n;
367  i->p = e;
368  i->n->p = i;
369  e->n = i;
370  d->size++;
371 }
void detach()
Definition: qlinkedlist.h:97
QLinkedListData * d
Definition: qlinkedlist.h:81
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
GLdouble GLdouble t
Definition: GLee.h:1181
T takeFirst ( )
inline

Definition at line 409 of file qlinkedlist.h.

410 {
411  T t = first();
412  removeFirst();
413  return t;
414 }
void removeFirst()
Definition: qlinkedlist.h:200
GLdouble GLdouble t
Definition: GLee.h:1181
T takeLast ( )
inline

Definition at line 417 of file qlinkedlist.h.

418 {
419  T t = last();
420  removeLast();
421  return t;
422 }
void removeLast()
Definition: qlinkedlist.h:201
GLdouble GLdouble t
Definition: GLee.h:1181
int removeAll ( const T &  t)

Definition at line 374 of file qlinkedlist.h.

375 {
376  detach();
377  const T t = _t;
378  Node *i = e->n;
379  int c = 0;
380  while (i != e) {
381  if (i->t == t) {
382  Node *n = i;
383  i->n->p = i->p;
384  i->p->n = i->n;
385  i = i->n;
386  delete n;
387  c++;
388  } else {
389  i = i->n;
390  }
391  }
392  d->size-=c;
393  return c;
394 }
void detach()
Definition: qlinkedlist.h:97
QLinkedListData * d
Definition: qlinkedlist.h:81
GLenum GLsizei n
Definition: GLee.h:3432
const GLubyte * c
Definition: GLee.h:5419
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
GLdouble GLdouble t
Definition: GLee.h:1181
bool removeOne ( const T &  t)

Definition at line 397 of file qlinkedlist.h.

398 {
399  detach();
400  iterator it = qFind(begin(), end(), _t);
401  if (it != end()) {
402  erase(it);
403  return true;
404  }
405  return false;
406 }
void detach()
Definition: qlinkedlist.h:97
InputIterator qFind(InputIterator first, InputIterator last, const T &val)
Definition: qalgorithms.h:117
iterator begin()
Definition: qlinkedlist.h:182
iterator erase(iterator pos)
Definition: qlinkedlist.h:470
friend class iterator
Definition: qlinkedlist.h:149
iterator end()
Definition: qlinkedlist.h:185
bool contains ( const T &  t) const

Definition at line 425 of file qlinkedlist.h.

426 {
427  Node *i = e;
428  while ((i = i->n) != e)
429  if (i->t == t)
430  return true;
431  return false;
432 }
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
GLdouble GLdouble t
Definition: GLee.h:1181
int count ( const T &  t) const

Definition at line 435 of file qlinkedlist.h.

436 {
437  Node *i = e;
438  int c = 0;
439  while ((i = i->n) != e)
440  if (i->t == t)
441  c++;
442  return c;
443 }
const GLubyte * c
Definition: GLee.h:5419
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
GLdouble GLdouble t
Definition: GLee.h:1181
iterator begin ( )
inline

Definition at line 182 of file qlinkedlist.h.

182 { detach(); return e->n; }
void detach()
Definition: qlinkedlist.h:97
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
const_iterator begin ( ) const
inline

Definition at line 183 of file qlinkedlist.h.

183 { return e->n; }
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
const_iterator constBegin ( ) const
inline

Definition at line 184 of file qlinkedlist.h.

184 { return e->n; }
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
iterator end ( )
inline

Definition at line 185 of file qlinkedlist.h.

185 { detach(); return e; }
void detach()
Definition: qlinkedlist.h:97
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
const_iterator end ( ) const
inline

Definition at line 186 of file qlinkedlist.h.

186 { return e; }
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
const_iterator constEnd ( ) const
inline

Definition at line 187 of file qlinkedlist.h.

187 { return e; }
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
QLinkedList< T >::iterator insert ( iterator  before,
const T &  t 
)

Definition at line 447 of file qlinkedlist.h.

448 {
449  Node *i = before.i;
450  Node *m = new Node(t);
451  m->n = i;
452  m->p = i->p;
453  m->p->n = m;
454  i->p = m;
455  d->size++;
456  return m;
457 }
QLinkedListData * d
Definition: qlinkedlist.h:81
GLdouble GLdouble t
Definition: GLee.h:1181
QLinkedList< T >::iterator erase ( iterator  pos)

Definition at line 470 of file qlinkedlist.h.

471 {
472  detach();
473  Node *i = pos.i;
474  if (i != e) {
475  Node *n = i;
476  i->n->p = i->p;
477  i->p->n = i->n;
478  i = i->n;
479  delete n;
480  d->size--;
481  }
482  return i;
483 }
void detach()
Definition: qlinkedlist.h:97
QLinkedListData * d
Definition: qlinkedlist.h:81
GLenum GLsizei n
Definition: GLee.h:3432
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
iterator erase ( iterator  first,
iterator  last 
)
int count ( ) const
inline

Definition at line 195 of file qlinkedlist.h.

195 { return d->size; }
QLinkedListData * d
Definition: qlinkedlist.h:81
T& first ( )
inline

Definition at line 196 of file qlinkedlist.h.

196 { Q_ASSERT(!isEmpty()); return *begin(); }
iterator begin()
Definition: qlinkedlist.h:182
bool isEmpty() const
Definition: qlinkedlist.h:103
const T& first ( ) const
inline

Definition at line 197 of file qlinkedlist.h.

197 { Q_ASSERT(!isEmpty()); return *begin(); }
iterator begin()
Definition: qlinkedlist.h:182
bool isEmpty() const
Definition: qlinkedlist.h:103
T& last ( )
inline

Definition at line 198 of file qlinkedlist.h.

198 { Q_ASSERT(!isEmpty()); return *(--end()); }
iterator end()
Definition: qlinkedlist.h:185
bool isEmpty() const
Definition: qlinkedlist.h:103
const T& last ( ) const
inline

Definition at line 199 of file qlinkedlist.h.

199 { Q_ASSERT(!isEmpty()); return *(--end()); }
iterator end()
Definition: qlinkedlist.h:185
bool isEmpty() const
Definition: qlinkedlist.h:103
void removeFirst ( )
inline

Definition at line 200 of file qlinkedlist.h.

200 { Q_ASSERT(!isEmpty()); erase(begin()); }
iterator begin()
Definition: qlinkedlist.h:182
iterator erase(iterator pos)
Definition: qlinkedlist.h:470
bool isEmpty() const
Definition: qlinkedlist.h:103
void removeLast ( )
inline

Definition at line 201 of file qlinkedlist.h.

201 { Q_ASSERT(!isEmpty()); erase(--end()); }
iterator erase(iterator pos)
Definition: qlinkedlist.h:470
iterator end()
Definition: qlinkedlist.h:185
bool isEmpty() const
Definition: qlinkedlist.h:103
bool startsWith ( const T &  t) const
inline

Definition at line 202 of file qlinkedlist.h.

202 { return !isEmpty() && first() == t; }
bool isEmpty() const
Definition: qlinkedlist.h:103
GLdouble GLdouble t
Definition: GLee.h:1181
bool endsWith ( const T &  t) const
inline

Definition at line 203 of file qlinkedlist.h.

203 { return !isEmpty() && last() == t; }
bool isEmpty() const
Definition: qlinkedlist.h:103
GLdouble GLdouble t
Definition: GLee.h:1181
void push_back ( const T &  t)
inline

Definition at line 206 of file qlinkedlist.h.

206 { append(t); }
GLdouble GLdouble t
Definition: GLee.h:1181
void append(const T &)
Definition: qlinkedlist.h:350
void push_front ( const T &  t)
inline

Definition at line 207 of file qlinkedlist.h.

207 { prepend(t); }
void prepend(const T &)
Definition: qlinkedlist.h:362
GLdouble GLdouble t
Definition: GLee.h:1181
T& front ( )
inline

Definition at line 208 of file qlinkedlist.h.

208 { return first(); }
const T& front ( ) const
inline

Definition at line 209 of file qlinkedlist.h.

209 { return first(); }
T& back ( )
inline

Definition at line 210 of file qlinkedlist.h.

210 { return last(); }
const T& back ( ) const
inline

Definition at line 211 of file qlinkedlist.h.

211 { return last(); }
void pop_front ( )
inline

Definition at line 212 of file qlinkedlist.h.

212 { removeFirst(); }
void removeFirst()
Definition: qlinkedlist.h:200
void pop_back ( )
inline

Definition at line 213 of file qlinkedlist.h.

213 { removeLast(); }
void removeLast()
Definition: qlinkedlist.h:201
bool empty ( ) const
inline

Definition at line 214 of file qlinkedlist.h.

214 { return isEmpty(); }
bool isEmpty() const
Definition: qlinkedlist.h:103
static QLinkedList<T> fromStdList ( const std::list< T > &  list)
inlinestatic

Definition at line 224 of file qlinkedlist.h.

225  { QLinkedList<T> tmp; qCopy(list.begin(), list.end(), std::back_inserter(tmp)); return tmp; }
OutputIterator qCopy(InputIterator begin, InputIterator end, OutputIterator dest)
Definition: qalgorithms.h:79
std::list<T> toStdList ( ) const
inline

Definition at line 226 of file qlinkedlist.h.

227  { std::list<T> tmp; qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }
const_iterator constBegin() const
Definition: qlinkedlist.h:184
const_iterator constEnd() const
Definition: qlinkedlist.h:187
OutputIterator qCopy(InputIterator begin, InputIterator end, OutputIterator dest)
Definition: qalgorithms.h:79
QLinkedList< T > & operator+= ( const QLinkedList< T > &  l)

Definition at line 486 of file qlinkedlist.h.

487 {
488  detach();
489  int n = l.d->size;
490  d->size += n;
491  Node *original = l.e->n;
492  while (n--) {
493  QT_TRY {
494  Node *copy = new Node(original->t);
495  original = original->n;
496  copy->n = e;
497  copy->p = e->p;
498  copy->p->n = copy;
499  e->p = copy;
500  } QT_CATCH(...) {
501  // restore the original list
502  while (n++<d->size)
503  removeLast();
504  QT_RETHROW;
505  }
506  }
507  return *this;
508 }
void detach()
Definition: qlinkedlist.h:97
QLinkedListData * d
Definition: qlinkedlist.h:81
void removeLast()
Definition: qlinkedlist.h:201
GLenum GLsizei n
Definition: GLee.h:3432
QLinkedListNode< T > * e
Definition: qlinkedlist.h:81
QLinkedList< T > operator+ ( const QLinkedList< T > &  l) const

Definition at line 511 of file qlinkedlist.h.

512 {
513  QLinkedList<T> n = *this;
514  n += l;
515  return n;
516 }
GLenum GLsizei n
Definition: GLee.h:3432
QLinkedList<T>& operator+= ( const T &  t)
inline

Definition at line 248 of file qlinkedlist.h.

248 { append(t); return *this; }
GLdouble GLdouble t
Definition: GLee.h:1181
void append(const T &)
Definition: qlinkedlist.h:350
QLinkedList<T>& operator<< ( const T &  t)
inline

Definition at line 249 of file qlinkedlist.h.

249 { append(t); return *this; }
GLdouble GLdouble t
Definition: GLee.h:1181
void append(const T &)
Definition: qlinkedlist.h:350
QLinkedList<T>& operator<< ( const QLinkedList< T > &  l)
inline

Definition at line 250 of file qlinkedlist.h.

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

Friends And Related Function Documentation

friend class iterator
friend

Definition at line 149 of file qlinkedlist.h.

friend class const_iterator
friend

Definition at line 179 of file qlinkedlist.h.

Member Data Documentation

Definition at line 81 of file qlinkedlist.h.

Definition at line 81 of file qlinkedlist.h.


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