QListData Struct Reference

#include <qlist.h>

Collaboration diagram for QListData:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 45 of file qlist.h.

Public Types

enum  

Public Member Functions

Datadetach ()
void realloc (int alloc)
void ** erase (void **xi)
void ** append ()
void ** append (const QListData &l)
void ** prepend ()
void ** insert (int i)
void remove (int i)
void remove (int i, int n)
void move (int from, int to)
int size () const
bool isEmpty () const
void ** at (int i) const
void ** begin () const
void ** end () const

Public Attributes

Datad

Static Public Attributes

static Data shared_null

Classes

struct  Data


Member Enumeration Documentation

anonymous enum

Definition at line 52 of file qlist.h.

00052 { DataHeaderSize = sizeof(Data) - sizeof(void *) };


Member Function Documentation

QListData::Data * QListData::detach (  ) 

Definition at line 48 of file qlistdata.cpp.

References QListData::Data::alloc, d, DataHeaderSize, qAtomicSetPtr(), qMalloc(), QListData::Data::ref, and x.

Referenced by QList< T >::detach_helper().

00049 {
00050     Q_ASSERT(d->ref != 1);
00051     Data *x = static_cast<Data *>(qMalloc(DataHeaderSize + d->alloc * sizeof(void *)));
00052     ::memcpy(x, d, DataHeaderSize + d->alloc * sizeof(void *));
00053     x->alloc = d->alloc;
00054     x->ref.init(1);
00055     x->sharable = true;
00056     if (!x->alloc)
00057         x->begin = x->end = 0;
00058 
00059     x = qAtomicSetPtr(&d, x);
00060     if (!x->ref.deref())
00061         return x;
00062     return 0;
00063 }

Here is the call graph for this function:

void QListData::realloc ( int  alloc  ) 

Definition at line 65 of file qlistdata.cpp.

References QListData::Data::alloc, QListData::Data::begin, d, DataHeaderSize, QListData::Data::end, qRealloc(), and QListData::Data::ref.

Referenced by append(), insert(), and prepend().

00066 {
00067     Q_ASSERT(d->ref == 1);
00068     d = static_cast<Data *>(qRealloc(d, DataHeaderSize + alloc * sizeof(void *)));
00069     d->alloc = alloc;
00070     if (!alloc)
00071         d->begin = d->end = 0;
00072 }

Here is the call graph for this function:

void ** QListData::erase ( void **  xi  ) 

Definition at line 233 of file qlistdata.cpp.

References QListData::Data::array, QListData::Data::begin, d, i, QListData::Data::ref, and remove().

Referenced by QList< T >::erase().

00234 {
00235     Q_ASSERT(d->ref == 1);
00236     int i = xi - (d->array + d->begin);
00237     remove(i);
00238     return d->array + d->begin + i;
00239 }

Here is the call graph for this function:

void ** QListData::append (  ) 

Definition at line 75 of file qlistdata.cpp.

References QListData::Data::alloc, QListData::Data::array, QListData::Data::begin, d, QListData::Data::end, grow(), n, realloc(), and QListData::Data::ref.

Referenced by QList< T >::append(), insert(), and QList< T >::operator+=().

00076 {
00077     Q_ASSERT(d->ref == 1);
00078     if (d->end == d->alloc) {
00079         int n = d->end - d->begin;
00080         if (d->begin > 2 * d->alloc / 3) {
00081             ::memcpy(d->array + n, d->array + d->begin, n * sizeof(void *));
00082             d->begin = n;
00083             d->end = n * 2;
00084         } else {
00085             realloc(grow(d->alloc + 1));
00086         }
00087     }
00088     return d->array + d->end++;
00089 }

Here is the call graph for this function:

void ** QListData::append ( const QListData l  ) 

Definition at line 91 of file qlistdata.cpp.

References QListData::Data::alloc, QListData::Data::array, d, QListData::Data::end, grow(), l, n, realloc(), and QListData::Data::ref.

00092 {
00093     Q_ASSERT(d->ref == 1);
00094     int e = d->end;
00095     int n = l.d->end - l.d->begin;
00096     if (n) {
00097         if (e + n > d->alloc)
00098             realloc(grow(e + l.d->end - l.d->begin));
00099         ::memcpy(d->array + d->end, l.d->array + l.d->begin, n * sizeof(void*));
00100         d->end += n;
00101     }
00102     return d->array + e;
00103 }

Here is the call graph for this function:

void ** QListData::prepend (  ) 

Definition at line 105 of file qlistdata.cpp.

References QListData::Data::alloc, QListData::Data::array, QListData::Data::begin, d, QListData::Data::end, grow(), realloc(), and QListData::Data::ref.

Referenced by insert(), and QList< T >::prepend().

00106 {
00107     Q_ASSERT(d->ref == 1);
00108     if (d->begin == 0) {
00109         if (d->end >= d->alloc / 3)
00110             realloc(grow(d->alloc + 1));
00111 
00112         if (d->end < d->alloc / 3)
00113             d->begin = d->alloc - 2 * d->end;
00114         else
00115             d->begin = d->alloc - d->end;
00116 
00117         ::memmove(d->array + d->begin, d->array, d->end * sizeof(void *));
00118         d->end += d->begin;
00119     }
00120     return d->array + --d->begin;
00121 }

Here is the call graph for this function:

void ** QListData::insert ( int  i  ) 

Definition at line 123 of file qlistdata.cpp.

References QListData::Data::alloc, append(), QListData::Data::array, QListData::Data::begin, d, QListData::Data::end, grow(), prepend(), realloc(), QListData::Data::ref, and size().

Referenced by QList< T >::insert().

00124 {
00125     Q_ASSERT(d->ref == 1);
00126     if (i <= 0)
00127         return prepend();
00128     if (i >= d->end - d->begin)
00129         return append();
00130 
00131     bool leftward = false;
00132     int size = d->end - d->begin;
00133 
00134     if (d->begin == 0) {
00135         if (d->end == d->alloc) {
00136             // If the array is full, we expand it and move some items rightward
00137             realloc(grow(d->alloc + 1));
00138         } else {
00139             // If there is free space at the end of the array, we move some items rightward
00140         }
00141     } else {
00142         if (d->end == d->alloc) {
00143             // If there is free space at the beginning of the array, we move some items leftward
00144             leftward = true;
00145         } else {
00146             // If there is free space at both ends, we move as few items as possible
00147             leftward = (i < size - i);
00148         }
00149     }
00150 
00151     if (leftward) {
00152         --d->begin;
00153         ::memmove(d->array + d->begin, d->array + d->begin + 1, i * sizeof(void *));
00154     } else {
00155         ::memmove(d->array + d->begin + i + 1, d->array + d->begin + i,
00156                   (size - i) * sizeof(void *));
00157         ++d->end;
00158     }
00159     return d->array + d->begin + i;
00160 }

Here is the call graph for this function:

void QListData::remove ( int  i  ) 

Definition at line 162 of file qlistdata.cpp.

References QListData::Data::array, QListData::Data::begin, d, QListData::Data::end, and QListData::Data::ref.

Referenced by erase(), QList< T >::removeAll(), QList< T >::removeAt(), and QList< T >::takeAt().

00163 {
00164     Q_ASSERT(d->ref == 1);
00165     i += d->begin;
00166     if (i - d->begin < d->end - i) {
00167         if (int offset = i - d->begin)
00168             ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *));
00169         d->begin++;
00170     } else {
00171         if (int offset = d->end - i - 1)
00172             ::memmove(d->array + i, d->array + i + 1, offset * sizeof(void *));
00173         d->end--;
00174     }
00175 }

void QListData::remove ( int  i,
int  n 
)

Definition at line 177 of file qlistdata.cpp.

References QListData::Data::array, QListData::Data::begin, d, QListData::Data::end, and QListData::Data::ref.

00178 {
00179     Q_ASSERT(d->ref == 1);
00180     i += d->begin;
00181     int middle = i + n/2;
00182     if (middle - d->begin < d->end - middle) {
00183         ::memmove(d->array + d->begin + n, d->array + d->begin,
00184                    (i - d->begin) * sizeof(void*));
00185         d->begin += n;
00186     } else {
00187         ::memmove(d->array + i, d->array + i + n,
00188                    (d->end - i - n) * sizeof(void*));
00189         d->end -= n;
00190     }
00191 }

void QListData::move ( int  from,
int  to 
)

Definition at line 193 of file qlistdata.cpp.

References QListData::Data::alloc, QListData::Data::array, QListData::Data::begin, d, QListData::Data::end, QListData::Data::ref, and t.

Referenced by QList< T >::move().

00194 {
00195     Q_ASSERT(d->ref == 1);
00196     if (from == to)
00197         return;
00198 
00199     from += d->begin;
00200     to += d->begin;
00201     void *t = d->array[from];
00202 
00203     if (from < to) {
00204         if (d->end == d->alloc || 3 * (to - from) < 2 * (d->end - d->begin)) {
00205             ::memmove(d->array + from, d->array + from + 1, (to - from) * sizeof(void *));
00206         } else {
00207             // optimization
00208             if (int offset = from - d->begin)
00209                 ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *));
00210             if (int offset = d->end - (to + 1))
00211                 ::memmove(d->array + to + 2, d->array + to + 1, offset * sizeof(void *));
00212             ++d->begin;
00213             ++d->end;
00214             ++to;
00215         }
00216     } else {
00217         if (d->begin == 0 || 3 * (from - to) < 2 * (d->end - d->begin)) {
00218             ::memmove(d->array + to + 1, d->array + to, (from - to) * sizeof(void *));
00219         } else {
00220             // optimization
00221             if (int offset = to - d->begin)
00222                 ::memmove(d->array + d->begin - 1, d->array + d->begin, offset * sizeof(void *));
00223             if (int offset = d->end - (from + 1))
00224                 ::memmove(d->array + from, d->array + from + 1, offset * sizeof(void *));
00225             --d->begin;
00226             --d->end;
00227             --to;
00228         }
00229     }
00230     d->array[to] = t;
00231 }

int QListData::size (  )  const [inline]

Definition at line 66 of file qlist.h.

References d.

Referenced by QList< T >::at(), QList< QPostEvent >::count(), QList< T >::indexOf(), insert(), QList< T >::lastIndexOf(), QList< T >::move(), QList< T >::operator==(), QList< T >::operator[](), QList< T >::removeAll(), QList< T >::removeAt(), QList< T >::replace(), QList< QPostEvent >::size(), QList< T >::swap(), QList< T >::takeAt(), and QList< T >::value().

00066 { return d->end - d->begin; }

bool QListData::isEmpty (  )  const [inline]

Definition at line 67 of file qlist.h.

References d.

Referenced by QList< QPostEvent >::isEmpty().

00067 { return d->end  == d->begin; }

void** QListData::at ( int  i  )  const [inline]

Definition at line 68 of file qlist.h.

References d.

Referenced by QList< T >::at(), QList< T >::indexOf(), QList< T >::lastIndexOf(), QList< T >::operator[](), QList< T >::removeAll(), QList< T >::removeAt(), QList< T >::replace(), QList< T >::takeAt(), and QList< T >::value().

00068 { return d->array + d->begin + i; }

void** QListData::begin (  )  const [inline]

Definition at line 69 of file qlist.h.

References d.

Referenced by QList< QPostEvent >::begin(), QList< QPostEvent >::constBegin(), QList< T >::contains(), QList< T >::count(), QList< T >::detach_helper(), QList< T >::indexOf(), QList< T >::insert(), QList< T >::lastIndexOf(), and QList< T >::operator==().

00069 { return d->array + d->begin; }

void** QListData::end (  )  const [inline]

Definition at line 70 of file qlist.h.

References d.

Referenced by QList< QPostEvent >::constEnd(), QList< T >::contains(), QList< T >::count(), QList< T >::detach_helper(), QList< QPostEvent >::end(), QList< T >::indexOf(), QList< T >::operator+=(), and QList< T >::operator==().

00070 { return d->array + d->end; }


Member Data Documentation

QListData::Data QListData::shared_null [static]

Definition at line 56 of file qlist.h.

Referenced by Q3CleanupHandler< T >::add(), and QList< T >::~QList().

Data* QListData::d

Definition at line 57 of file qlist.h.

Referenced by append(), detach(), erase(), insert(), move(), prepend(), realloc(), and remove().


The documentation for this struct was generated from the following files:
Generated on Thu Mar 15 18:17:03 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1