Public Types | Public Member Functions | Friends

QVarLengthArray< T, Prealloc > Class Template Reference

Search for all occurrences

Detailed Description

template<class T, int Prealloc>
class QVarLengthArray< T, Prealloc >

Definition at line 60 of file qvarlengtharray.h.

#include <qvarlengtharray.h>

List of all members.

Public Types

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

  QVarLengthArray (int size=0)
  QVarLengthArray (const QVarLengthArray< T, Prealloc > &other)
  ~QVarLengthArray ()
QVarLengthArray< T, Prealloc > &  operator= (const QVarLengthArray< T, Prealloc > &other)
void  removeLast ()
int  size () const
int  count () const
bool  isEmpty () const
void  resize (int size)
void  clear ()
int  capacity () const
void  reserve (int size)
T &  operator[] (int idx)
const T &  operator[] (int idx) const
const T &  at (int idx) const
value (int i) const
value (int i, const T &defaultValue) const
void  append (const T &t)
void  append (const T *buf, int size)
T *  data ()
const T *  data () const
const T *  constData () const

Friends

class  QPodList< T, Prealloc >

Member Typedef Documentation

typedef int size_type

Definition at line 130 of file qvarlengtharray.h.

typedef T value_type

Definition at line 131 of file qvarlengtharray.h.

typedef value_type* pointer

Definition at line 132 of file qvarlengtharray.h.

typedef const value_type* const_pointer

Definition at line 133 of file qvarlengtharray.h.

Definition at line 134 of file qvarlengtharray.h.

typedef const value_type& const_reference

Definition at line 135 of file qvarlengtharray.h.

typedef qptrdiff difference_type

Definition at line 136 of file qvarlengtharray.h.


Constructor & Destructor Documentation

Q_INLINE_TEMPLATE QVarLengthArray ( int  size = 0 ) [inline, explicit]

Definition at line 154 of file qvarlengtharray.h.

    : s(asize) {
    if (s > Prealloc) {
        ptr = reinterpret_cast<T *>(qMalloc(s * sizeof(T)));
        Q_CHECK_PTR(ptr);
        a = s;
    } else {
        ptr = reinterpret_cast<T *>(array);
        a = Prealloc;
    }
    if (QTypeInfo<T>::isComplex) {
        T *i = ptr + s;
        while (i != ptr)
            new (--i) T;
    }
}
QVarLengthArray ( const QVarLengthArray< T, Prealloc > &  other ) [inline]

Definition at line 65 of file qvarlengtharray.h.

        : a(Prealloc), s(0), ptr(reinterpret_cast<T *>(array))
    {
        append(other.constData(), other.size());
    }
~QVarLengthArray ( ) [inline]

Definition at line 71 of file qvarlengtharray.h.

                              {
        if (QTypeInfo<T>::isComplex) {
            T *i = ptr + s;
            while (i-- != ptr)
                i->~T();
        }
        if (ptr != reinterpret_cast<T *>(array))
            qFree(ptr);
    }

Member Function Documentation

QVarLengthArray<T, Prealloc>& operator= ( const QVarLengthArray< T, Prealloc > &  other ) [inline]

Definition at line 80 of file qvarlengtharray.h.

    {
        if (this != &other) {
            clear();
            append(other.constData(), other.size());
        }
        return *this;
    }
void removeLast ( ) [inline]

Definition at line 89 of file qvarlengtharray.h.

                             {
        Q_ASSERT(s > 0);
        realloc(s - 1, a);
    }
int size ( ) const [inline]

Definition at line 93 of file qvarlengtharray.h.

{ return s; }
int count ( ) const [inline]

Definition at line 94 of file qvarlengtharray.h.

{ return s; }
bool isEmpty ( ) const [inline]

Definition at line 95 of file qvarlengtharray.h.

{ return (s == 0); }
Q_INLINE_TEMPLATE void resize ( int  size ) [inline]

Definition at line 172 of file qvarlengtharray.h.

{ realloc(asize, qMax(asize, a)); }
void clear ( ) [inline]

Definition at line 97 of file qvarlengtharray.h.

{ resize(0); }
int capacity ( ) const [inline]

Definition at line 99 of file qvarlengtharray.h.

{ return a; }
Q_INLINE_TEMPLATE void reserve ( int  size ) [inline]

Definition at line 176 of file qvarlengtharray.h.

{ if (asize > a) realloc(s, asize); }
T& operator[] ( int  idx ) [inline]

Definition at line 102 of file qvarlengtharray.h.

                                  {
        Q_ASSERT(idx >= 0 && idx < s);
        return ptr[idx];
    }
const T& operator[] ( int  idx ) const [inline]

Definition at line 106 of file qvarlengtharray.h.

                                              {
        Q_ASSERT(idx >= 0 && idx < s);
        return ptr[idx];
    }
const T& at ( int  idx ) const [inline]

Definition at line 110 of file qvarlengtharray.h.

{ return operator[](idx); }
Q_OUTOFLINE_TEMPLATE T value ( int  i ) const

Definition at line 262 of file qvarlengtharray.h.

{
    if (i < 0 || i >= size()) {
        return T();
    }
    return at(i);
}
Q_OUTOFLINE_TEMPLATE T value ( int  i,
const T &  defaultValue 
) const

Definition at line 270 of file qvarlengtharray.h.

{
    return (i < 0 || i >= size()) ? defaultValue : at(i);
}
void append ( const T &  t ) [inline]

Definition at line 115 of file qvarlengtharray.h.

                                   {
        if (s == a)   // i.e. s != 0
            realloc(s, s<<1);
        const int idx = s++;
        if (QTypeInfo<T>::isComplex) {
            new (ptr + idx) T(t);
        } else {
            ptr[idx] = t;
        }
    }
Q_OUTOFLINE_TEMPLATE void append ( const T *  buf,
int  size 
)

Definition at line 180 of file qvarlengtharray.h.

{
    Q_ASSERT(abuf);
    if (increment <= 0)
        return;

    const int asize = s + increment;

    if (asize >= a)
        realloc(s, qMax(s*2, asize));

    if (QTypeInfo<T>::isComplex) {
        // call constructor for new objects (which can throw)
        while (s < asize)
            new (ptr+(s++)) T(*abuf++);
    } else {
        qMemCopy(&ptr[s], abuf, increment * sizeof(T));
        s = asize;
    }
}
T* data ( ) [inline]

Definition at line 127 of file qvarlengtharray.h.

{ return ptr; }
const T* data ( ) const [inline]

Definition at line 128 of file qvarlengtharray.h.

{ return ptr; }
const T* constData ( ) const [inline]

Definition at line 129 of file qvarlengtharray.h.

{ return ptr; }

Friends And Related Function Documentation

friend class QPodList< T, Prealloc > [friend]

Definition at line 139 of file qvarlengtharray.h.


Member Data Documentation

char array[sizeof(qint64)*(((Prealloc *sizeof(T))/sizeof(qint64))+1)]

Definition at line 147 of file qvarlengtharray.h.

Definition at line 148 of file qvarlengtharray.h.

Definition at line 149 of file qvarlengtharray.h.


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