Member Function Documentation
QArray::QArray()
Constructs an empty array.
See also reserve().
QArray::QArray(int size)
Constructs an array of size elements, all initialized to their default-constructed values.
QArray::QArray(int size, const T & value)
Constructs an array of size elements, all initialized to value.
See also fill().
QArray::QArray(const T * values, int size)
Constructs an array of size elements, initialized from values.
QArray::QArray(const QArray<T, PreallocSize> & other)
Constructs a copy of other.
See also operator=().
QArray::~QArray()
Destroys the array.
void QArray::append(const T & value)
Appends value to this array.
See also prepend() and insert().
void QArray::append(const T * values, int count)
Appends the count elements of values to this array.
void QArray::append(const QArray<T, PreallocSize> & other)
Appends the elements of other to this array.
void QArray::append(const T & value1, const T & value2)
This is an overloaded function.
Appends value1 and value2 to this array.
void QArray::append(const T & value1, const T & value2, const T & value3)
This is an overloaded function.
Appends value1, value2, and value3 to this array.
void QArray::append(const T & value1, const T & value2, const T & value3, const T & value4)
This is an overloaded function.
Appends value1, value2, value3, and value4 to this array.
const T & QArray::at(int index) const
Returns the item at position index in the array.
index must be a valid index position in the array (i.e., 0 <= index < size()).
See also operator[](), constData(), and value().
This function is provided for STL compatibility. It is equivalent to last().
This is an overloaded function.
Returns an STL-style iterator pointing to the first item in the array.
See also end(), constBegin(), and QArray::iterator.
This is an overloaded function.
int QArray::capacity() const
Returns the number of elements that can be stored in this array before reallocation.
See also reserve() and size().
void QArray::clear()
Clears all elements from this array and sets the size to zero.
This function will deallocate any memory that is used on the heap to store the array's elements. To reuse the same memory as before, call resize() with an argument of zero.
See also resize() and isEmpty().
Returns a const STL-style iterator pointing to the first item in the array.
See also constEnd(), begin(), and QArray::const_iterator.
const T * QArray::constData() const
Returns a const pointer to the data stored in the array. The pointer can be used to access the items in the array. The pointer remains valid as long as the array isn't reallocated.
This function is mostly useful to pass an array to a function that accepts a plain C++ array.
See also data() and operator[]().
Returns a const STL-style iterator pointing to the imaginary item after the last item in the array.
See also constBegin(), end(), and QArray::const_iterator.
bool QArray::contains(const T & value) const
Returns true if the array contains an occurrence of value; false otherwise.
This function requires the value type T to have an implementation of operator==().
See also indexOf() and count().
int QArray::count(const T & value) const
Returns the number of occurrences of value in the array.
This function requires the value type T to have an implementation of operator==().
See also contains() and indexOf().
int QArray::count() const
This is an overloaded function.
Same as size(), provided for convenience.
T * QArray::data()
Returns a pointer to the data stored in the array. The pointer can be used to access and modify the items in the array.
The pointer remains valid as long as the array isn't reallocated.
This function is mostly useful to pass an array to a function that accepts a plain C++ array. It may make a deep copy of the array's elements if the array is implicitly shared.
See also constData() and operator[]().
const T * QArray::data() const
This is an overloaded function.
bool QArray::empty() const
This function is provided for STL compatibility. It is equivalent to isEmpty(), returning true if the array is empty; otherwise returns false.
Returns an STL-style iterator pointing to the imaginary item after the last item in the array.
See also begin(), constEnd(), and QArray::iterator.
This is an overloaded function.
bool QArray::endsWith(const T & value) const
Returns true if this array is not empty and its last item is equal to value; otherwise returns false.
See also isEmpty() and last().
Removes the item pointed to by the iterator pos from the vector, and returns an iterator to the next item in the vector (which may be end()).
See also insert() and remove().
This is an overloaded function.
Removes all the items from begin up to (but not including) end. Returns an iterator to the same item that end referred to before the call.
T * QArray::extend(int size)
Extends this array by size elements and returns a pointer to the storage, which is not initialized. The pointer is only valid until the array is reallocated or destroyed.
The append() or resize() functions are recommended if T is a complex type, with extend() only used for simple types. Because the storage is not initialized, the caller should use the in-place new operator to set elements:
QArray<QRegExp> array;
QRegExp *space = array.extend(1);
new (space) QRegExp(QLatin1String("exp"));
See also append() and resize().
QArray<T, PreallocSize> & QArray::fill(const T & value, int size = -1)
Assigns value to all items in the array. If size is different from -1 (the default), the array is resized to size beforehand. Returns a reference to the array.
See also resize().
T & QArray::first()
Returns a reference to the first item in the array. This function assumes that the array isn't empty.
See also last() and isEmpty().
const T & QArray::first() const
This is an overloaded function.
QArray<T, PreallocSize> QArray::fromRawData(const T * data, int size) [static]
Returns an array consisting of the size elements from data.
This function takes a reference to data, but does not copy the elements until the array is modified. The memory at data must remain valid until the returned array is destroyed or modified.
Use append() instead of fromRawData() to force a copy to be made of the elements at data when the array is created:
QArray<float> array;
array.append(data, size);
QArray<float> array;
array = QArray<float>::fromRawData(data, size);
See also fromWritableRawData() and append().
QArray<T, PreallocSize> QArray::fromWritableRawData(T * data, int size) [static]
Returns an array consisting of the size elements from data.
This function takes a reference to data, but does not copy the elements until the array is reallocated to a larger size. The memory at data must remain valid until the returned array is destroyed or reallocated.
The elements of data will be modified in-place. This differs from fromRawData() which will make a copy of the elements of data when the array is modified.
If the returned array is resized to less than size, then a copy will not be made, and append() can be used to append new items up to size. Further calls to append() after size will force the array to be reallocated.
If the returned array is resized to more than size, then a copy of the data will be made and further modifications will not affect the elements at data.
See also fromRawData().
This function is provided for STL compatibility. It is equivalent to first().
This is an overloaded function.
int QArray::indexOf(const T & value, int from = 0) const
Returns the index position of the first occurrence of value in the array, searching forward from index position from. Returns -1 if no item matched.
If from is negative, then it indicates an index position relative to the end of the array, -1 being the last index position.
This function requires the value type T to have an implementation of operator==().
See also lastIndexOf() and contains().
void QArray::insert(int index, const T & value)
Inserts value at position index in this array. If index is 0, then value is prepended to the array. If index is size(), then value is appended to the array.
See also append() and prepend().
iterator QArray::insert(iterator before, int count, const T & value)
Inserts count copies of value in front of the item pointed to by the iterator before. Returns an iterator pointing at the first of the inserted items.
void QArray::insert(int index, int count, const T & value)
This is an overloaded function.
Inserts count copies of value at position index in this array.
iterator QArray::insert(iterator before, const T & value)
This is an overloaded function.
Inserts value in front of the item pointed to by the iterator before. Returns an iterator pointing at the inserted item.
bool QArray::isEmpty() const
Returns true if this array is empty; false otherwise.
See also size() and clear().
T & QArray::last()
Returns a reference to the last item in the array. This function assumes that the array isn't empty.
See also first() and isEmpty().
const T & QArray::last() const
This is an overloaded function.
int QArray::lastIndexOf(const T & value, int from = -1) const
Returns the index position of the last occurrence of value in the array, searching backward from index position from. Returns -1 if no item matched.
If from is negative, then it indicates an index position relative to the end of the array, -1 being the last index position. The default for from is -1.
This function requires the value type T to have an implementation of operator==().
See also indexOf() and contains().
QArray<T, PreallocSize> QArray::left(int length) const
Returns an array containing the first length elements of this array. If length is less than zero, or greater than size(), then all elements in this array will be included in the return value.
See also mid() and right().
QArray<T, PreallocSize> QArray::mid(int index, int length = -1) const
Returns an array containing the length elements of this array, starting at index. If length is less than zero, or extends further than the end of the array, then all elements extending from index to the end of the array will be included in the return value.
See also left() and right().
void QArray::pop_back()
This function is provided for STL compatibility. It is equivalent to removeLast().
void QArray::pop_front()
This function is provided for STL compatibility. It is equivalent to removeFirst().
void QArray::prepend(const T & value)
Prepends value to this array.
See also append() and insert().
void QArray::push_back(const T & value)
This function is provided for STL compatibility. It is equivalent to append(value).
void QArray::push_front(const T & value)
This function is provided for STL compatibility. It is equivalent to prepend(value).
void QArray::remove(int index, int count)
Removes the count elements starting at position index in this array. If index or count is out of range, the set of removed elements will be truncated to those that are in range.
void QArray::remove(int index)
This is an overloaded function.
Removes the element at position index in this array.
void QArray::removeFirst()
Removes the first element from this array. Does nothing if the array is empty.
See also remove() and removeLast().
void QArray::removeLast()
Removes the last element from this array. Does nothing if the array is empty.
See also remove() and removeFirst().
void QArray::replace(int index, const T & value)
Replaces the element at index with value.
See also operator[]() and remove().
void QArray::replace(int index, const T * values, int count)
This is an overloaded function.
Replaces the count elements of this array with the contents of values, starting at index.
If (index + count) is larger than the current size of this array, the array will be extended to that size.
See also append().
void QArray::reserve(int size)
Increases the capacity of this array to reserve space for at least size elements. If the capacity is already larger than size, this function does nothing; in particular, it does not remove elements from the array like resize() does.
This function can be useful when you know how roughly many elements will be appended ahead of time. Reserving the space once can avoid unnecessary realloc operations later.
See also capacity(), resize(), and squeeze().
void QArray::resize(int size)
Sets the size of the array to size. If size is greater than the current size, elements are added to the end and are initialized to a default-constructed value. If size is less than the current size, elements are removed from the end.
See also size(), reserve(), and squeeze().
void QArray::reverse()
Reverses the order of this array in place.
See also reversed().
QArray<T, PreallocSize> QArray::reversed() const
Returns a copy of this array with elements in the reverse order.
See also reverse().
QArray<T, PreallocSize> QArray::right(int length) const
Returns an array containing the last length elements of this array. If length is less than zero, or greater than size(), then all elements in this array will be included in the return value.
See also mid() and left().
int QArray::size() const
Returns the number of elements in this array.
See also resize(), capacity(), and isEmpty().
void QArray::squeeze()
Releases any memory not required to store the array's elements by reducing its capacity() to size().
This function is intended for reclaiming memory in an array that is being used over and over with different contents. As elements are added to an array, it will be constantly expanded in size. This function can realloc the array to a smaller size to reclaim unused memory.
See also reserve() and capacity().
bool QArray::startsWith(const T & value) const
Returns true if this array is not empty and its first item is equal to value; otherwise returns false.
See also isEmpty() and first().
T QArray::value(int index) const
Returns the value at position index in the vector.
If the index is out of bounds, the function returns a default-constructed value. If you are certain that index is within bounds, you can use at() instead, which is slightly faster.
See also at() and operator[]().
T QArray::value(int index, const T & defaultValue) const
This is an overloaded function.
If the index is out of bounds, the function returns defaultValue.
bool QArray::operator!=(const QArray<T, PreallocSize> & other) const
Returns true if other is not equal to this array; otherwise returns false.
Two arrays are considered equal if they contain the same values in the same order.
This function requires the value type to have an implementation of operator==().
See also operator==().
QArray<T, PreallocSize> & QArray::operator+=(const QArray<T, PreallocSize> & other)
Appends the elements of the other array to this array and returns a reference to this array.
See also operator<<() and append().
QArray<T, PreallocSize> & QArray::operator+=(const T & value)
This is an overloaded function.
Appends value to this array and returns a reference to this array.
See also operator<<() and append().
QArray<T, PreallocSize> & QArray::operator<<(const QArray<T, PreallocSize> & other)
Appends the elements of the other array to this array and returns a reference to this array.
See also operator+=() and append().
QArray<T, PreallocSize> & QArray::operator<<(const T & value)
This is an overloaded function.
Appends value to this array and returns a reference to this array.
See also operator+=() and append().
QArray<T, PreallocSize> & QArray::operator=(const QArray<T, PreallocSize> & other)
Assigns other to this array and returns a reference to this array.
bool QArray::operator==(const QArray<T, PreallocSize> & other) const
Returns true if other is equal to this array; otherwise returns false.
Two arrays are considered equal if they contain the same values in the same order.
This function requires the value type to have an implementation of operator==().
See also operator!=().
T & QArray::operator[](int index)
Returns the item at position index as a modifiable reference.
index must be a valid index position in the vector (i.e., 0 <= index < size()).
Note that using non-const operators can cause QArray to do a deep copy.
See also at() and value().
const T & QArray::operator[](int index) const
This is an overloaded function.
Same as at(index).