CopperSpice API
1.9.2
|
The QList class is a template class which stores a list of values. More...
Classes | |
class | const_iterator |
The QList::const_iterator class provides an STL style const iterator for QList and QQueue More... | |
class | iterator |
The QList::iterator class provides an STL style iterator for QList and QQueue More... | |
Public Typedefs | |
using | allocator_type = typename std::deque< T >::allocator_type |
using | const_iterator = typename std::deque< T >::const_iterator |
using | const_pointer = typename std::deque< T >::const_pointer |
using | const_reference = typename std::deque< T >::const_reference |
using | const_reverse_iterator = typename std::deque< T >::const_reverse_iterator |
using | difference_type = typename std::deque< T >::difference_type |
using | iterator = typename std::deque< T >::iterator |
using | Java_Iterator = QListIterator< T > |
using | Java_MutableIterator = QMutableListIterator< T > |
using | pointer = typename std::deque< T >::pointer |
using | reference = typename std::deque< T >::reference |
using | reverse_iterator = typename std::deque< T >::reverse_iterator |
using | size_type = typename std::deque< T >::difference_type |
using | value_type = typename std::deque< T >::value_type |
Public Methods | |
QList () = default | |
QList (const QList< T > &other) = default | |
template<class Input_Iterator > | |
QList (Input_Iterator first, Input_Iterator last) | |
QList (QList< T > &&other) = default | |
QList (std::initializer_list< T > args) | |
~QList () = default | |
void | append (const QList< T > &other) |
void | append (const T &value) |
void | append (QList< T > &&other) |
void | append (T &&value) |
const T & | at (size_type i) const |
T & | back () |
const T & | back () const |
iterator | begin () |
const_iterator | begin () const |
const_iterator | cbegin () const |
const_iterator | cend () const |
void | clear () |
const_iterator | constBegin () const |
const_iterator | constEnd () const |
const_reference | constFirst () const |
const_reference | constLast () const |
bool | contains (const T &value) const |
size_type | count () const |
size_type | count (const T &value) const |
const_reverse_iterator | crbegin () const |
const_reverse_iterator | crend () const |
bool | empty () const |
iterator | end () |
const_iterator | end () const |
bool | endsWith (const T &value) const |
iterator | erase (const_iterator begin, const_iterator end) |
iterator | erase (const_iterator pos) |
T & | first () |
const T & | first () const |
T & | front () |
const T & | front () const |
size_type | indexOf (const T &value, size_type from=0) const |
iterator | insert (iterator before, const T &value) |
void | insert (size_type i, const T &value) |
bool | isEmpty () const |
T & | last () |
const T & | last () const |
size_type | lastIndexOf (const T &value, size_type from=-1) const |
size_type | length () const |
QList< T > | mid (size_type pos, size_type length=-1) const |
void | move (size_type from, size_type to) |
bool | operator!= (const QList< T > &other) const |
QList< T > | operator+ (const QList< T > &other) const |
QList< T > & | operator+= (const QList< T > &other) |
QList< T > & | operator+= (const T &value) |
QList< T > & | operator<< (const QList< T > &other) |
QList< T > & | operator<< (const T &value) |
QList< T > & | operator= (const QList< T > &other) = default |
QList< T > & | operator= (QList< T > &&other) = default |
bool | operator== (const QList< T > &other) const |
T & | operator[] (size_type i) |
const T & | operator[] (size_type i) const |
void | pop_back () |
void | pop_front () |
void | prepend (const T &value) |
void | push_back (const T &value) |
void | push_front (const T &value) |
reverse_iterator | rbegin () |
const_reverse_iterator | rbegin () const |
size_type | removeAll (const T &value) |
void | removeAt (size_type i) |
void | removeFirst () |
void | removeLast () |
bool | removeOne (const T &value) |
reverse_iterator | rend () |
const_reverse_iterator | rend () const |
void | replace (size_type i, const T &value) |
void | resize (size_type size) |
size_type | size () const |
bool | startsWith (const T &value) const |
void | swap (QList< T > &other) |
void | swap (size_type i, size_type j) |
T | takeAt (size_type i) |
T | takeFirst () |
T | takeLast () |
QSet< T > | toSet () const |
std::list< T > | toStdList () const |
QVector< T > | toVector () const |
T | value (size_type i) const |
T | value (size_type i, const T &defaultValue) const |
Static Public Methods | |
static QList< T > | fromSet (const QSet< T > &set) |
static QList< T > | fromStdList (const std::list< T > &other) |
static QList< T > | fromVector (const QVector< T > &vector) |
Related Functions | |
These are not member functions | |
bool | operator< (const QList< T > &lhs, const QList< T > &rhs) |
QDataStream & | operator<< (QDataStream &stream, const QList< T > &list) |
bool | operator<= (const QList< T > &lhs, const QList< T > &rhs) |
bool | operator> (const QList< T > &lhs, const QList< T > &rhs) |
bool | operator>= (const QList< T > &lhs, const QList< T > &rhs) |
QDataStream & | operator>> (QDataStream &stream, QList< T > &list) |
The QList class is a template class which stores a list of values. This container stores elements in large blocks of memory which provides fast index access. Insert and erase at the beginning or end of the container will be fast, whereas in the middle may be slow.
The QStringList class which inherits from QList<QString> adds several methods which pertain specifically to working with a list of strings.
For an overview and comparison of all containers, refer to the documentation for Container Classes. Refer to the section on Time Complexity for a discussion about which operations will be relatively faster or slower for a given container with a size of n.
A QVector can be created with an initial size. The following code constructs a QList with 200 elements and each element will be default initialized. Refer to default constructed elements for additional information.
QList, like all other containers in C++, uses 0 based indexes. To access the item at a particular index position you can use operator[]. For a non-const list operator[] returns an lvalue reference to the item and can be used on the left side of an assignment.
For read only access an alternative syntax is to use the at() method.
QList provides basic methods to add, move, and remove items: insert(), replace(), removeAt(), move(), and swap(). This class also has methods to append(), prepend(), removeFirst(), and removeLast().
To insert items into a QList the operator<<() method can be used.
A common requirement is to remove an item from a list and do something with it. QList provides takeAt(), takeFirst(), and takeLast(). The following is a loop which removes the items from a list one at a time and calls delete
.
Inserting and removing items at either ends of the list is fast because QList preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.
If you want to find all occurrences of a particular value in a list, use indexOf() or lastIndexOf(). The former searches forward starting from a given index position, the latter searches backward. Both return the index of a matching item if they find it, otherwise they return -1.
If you simply want to check whether a list contains a particular value, use contains(). If you want to find out how many times a particular value occurs in the list, use count(). If you want to replace all occurrences of a particular value with another, use replace().
The QVector value type T should be Default Constructible and Copy Constructible to work with all methods of this class. Data types like QObject are not copy constructible and therefore should never be stored in a container. You can however use a pointer to a QObject or any subclass as the type T.
A few methods have additional requirements. For example, indexOf() and lastIndexOf() need the value type T to support operator==()
. If any other constraints exist, they will appear in the documentation for the given method.
QList provides Java style iterators (QListIterator and QMutableListIterator) and STL style iterators (QList::const_iterator and QList::iterator). As an alternative you can use indexes into a QList however they are slightly slower than using an iterator.
QList does not support inserting, prepending, appending, or replacing with references to its own values. Doing so may cause your application to abort with an error message. All methods except isEmpty() assume the current QList is not empty. Methods with a parameter of an index value always assume the index is in the valid range of elements.
If you define CS_DISABLE_ASSERT failures will not be detected or reported. Errors may produce undefined behavior.
QList< T >::allocator_type |
Typedef for allocator used by the container.
QList< T >::const_iterator |
Typedef for std::deque<T>::const_iterator.
QList< T >::const_pointer |
Typedef for const T *.
QList< T >::const_reference |
Typedef for const T &.
QList< T >::const_reverse_iterator |
Typedef for an STL style const reverse iterator.
QList< T >::difference_type |
Typedef for ptrdiff_t.
QList< T >::iterator |
Typedef for std::deque<T>::iterator.
QList< T >::Java_Iterator |
Typedef for the java style const iterator.
QList< T >::Java_MutableIterator |
Typedef for the java style mutable iterator.
QList< T >::pointer |
Typedef for T *.
QList< T >::reference |
Typedef for T &.
QList< T >::reverse_iterator |
Typedef for an STL style reverse iterator.
QList< T >::size_type |
Typedef for a signed integer of the appropriate size for your platform.
QList< T >::value_type |
Typedef for T.
|
default |
Constructs an empty list.
|
default |
Copy constructs a new QList from other.
|
default |
Move constructs a new QList from other.
|
inline |
Construct a list from the std::initializer_list specified by args.
|
inline |
Construct a list containing the elements fromfirst to last.
|
default |
Destroys this QList.
|
inline |
Copy appends the items of other to this QList.
|
inline |
Appends value at the end of the list.
This is the same as list.insert(size(), value).
This operation is typically very fast (constant time) because QList preallocates extra space on both sides of the internal buffer to allow for fast growth at both ends.
|
inline |
Move appends the items of other to this QList.
|
inline |
Move appends from value to this QList.
|
inline |
Returns the item at index position i in the list. The value for i must be a valid index position in the list, i >= 0 and i < size().
This method is very fast. Refer to constant time for more information.
|
inline |
Equivalent to calling last(). Verify the list is not empty before calling this method.
|
inline |
Equivalent to calling last(). Verify the list is not empty before calling this method.
|
inline |
Returns an STL style iterator pointing to the first item in the list.
|
inline |
Returns an STL style iterator pointing to the first item in the list.
|
inline |
Returns a const STL style iterator positioned at the first item in the set.
|
inline |
Returns a const STL style iterator pointing to the imaginary item after the last item in the set.
|
inline |
Removes all items from the list.
|
inline |
Returns a const STL style iterator pointing to the first item in the list.
|
inline |
Returns a const STL style iterator pointing to the imaginary item after the last item in the list.
|
inline |
Returns a const reference to the first item in the list. The list must not be empty. If the list can be empty, call isEmpty() before calling this method.
|
inline |
Returns a reference to the last item in the list. The list must not be empty. If the list can be empty, call isEmpty() before calling this method.
bool QList< T >::contains | ( | const T & | value | ) | const |
Returns true if the list contains an occurrence of value, otherwise returns false. This method requires the value type to have an implementation of operator==()
.
|
inline |
Returns the number of items in the list. This is effectively the same as size().
QList< T >::size_type QList< T >::count | ( | const T & | value | ) | const |
Returns the number of occurrences of value in the list. This method requires the type T to support operator==()
.
|
inline |
Returns a const STL style reverse iterator pointing to the first item in the list, in reverse order.
|
inline |
Returns a const STL style reverse iterator pointing to one past the last item in the list, in reverse order.
|
inline |
Equivalent to calling isEmpty().
|
inline |
Returns an STL style iterator pointing to the imaginary item after the last item in the list.
|
inline |
Returns an STL style iterator pointing to the imaginary item after the last item in the list.
|
inline |
Returns true if this list is not empty and its last item is equal to value, otherwise returns false.
|
inline |
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.
|
inline |
Removes the item associated with the iterator pos from the list, and returns an iterator to the next item in the list (which may be end()).
|
inline |
|
inline |
Returns a reference to the first item in the list. The list must not be empty. If the list can be empty, call isEmpty() before calling this method.
|
static |
Returns a QList object with the data contained in set. The order of the elements in the QList is undefined.
|
inlinestatic |
Returns a QList containing copies of the items in the given other.
|
static |
Returns a QList object with the data contained in vector.
|
inline |
Equivalent to calling first(). Verify the list is not empty before calling this method.
|
inline |
Equivalent to calling first(). Verify the list is not empty before calling this method.
|
inline |
Returns the index position of the first occurrence of value in the list, searching forward from index position from. Returns -1 if no item matched.
This method requires the type T to support operator==()
.
Inserts value in front of the item pointed to by the iterator before. Returns an iterator pointing at the inserted item. The iterator passed to the method will be invalid after the call; the returned iterator should be used instead.
|
inline |
Inserts value at index position i in the list. If i is 0, the value is prepended to the list. If i is size(), the value is appended to the list.
|
inline |
Returns true if the list contains no items, otherwise returns false.
|
inline |
|
inline |
Returns a reference to the last item in the list. The list must not be empty. If the list can be empty, call isEmpty() before calling this method.
|
inline |
Returns the index position of the last occurrence of value in the list, searching backward from index position from. If from is -1 the search starts at the last item. Returns -1 if no item matched.
This method requires the type T to support operator==()
.
|
inline |
Returns a list whose elements are copied from this list, starting at position pos. If length is -1 then all elements after pos are returned, otherwise the given length of elements is returned. If the length is greater than number of elements the value for length is ignored.
Moves the item at index position from to index position to.
Equivalent to calling insert(to, takeAt(from)). This method assumes both "from" and "to" are valid indexes.
|
inline |
Returns true if other is not equal to this list, otherwise returns false. Two lists are considered equal if they contain the same values in the same order.
This method requires the type T to support operator==()
.
|
inline |
Returns a list that contains all the items in this list followed by all the items in the other list.
|
inline |
Appends the items of the other list to this list and returns a reference to this list.
|
inline |
Appends value to the list.
|
inline |
Appends the items of the other list to this list and returns a reference to this list.
|
inline |
Appends value to the list.
|
default |
Copy assigns from other and returns a reference to this object.
|
default |
Move assigns from other and returns a reference to this object.
This version takes an rvalue. Refer to references for a detailed description of rvalues and move semantics.
|
inline |
Returns true if other is equal to this list, otherwise returns false. Two lists are considered equal if they contain the same values in the same order.
This method requires the type T to support operator==()
.
|
inline |
|
inline |
Equivalent to calling at().
|
inline |
Equivalent to calling removeLast(). Verify the list is not empty before calling this method.
|
inline |
Equivalent to calling removeFirst(). Verify the list is not empty before calling this method.
|
inline |
Inserts value at the beginning of the list. Equivalent to calling list.insert(0, value).
This operation is usually very fast (constant time) because QList preallocates extra space on both sides of the internal buffer to allow for fast growth at both ends.
|
inline |
Equivalent to calling append(value).
|
inline |
Equivalent to calling prepend(value).
|
inline |
Returns a const STL style reverse iterator pointing to the first item in the list, in reverse order.
|
inline |
Returns a const STL style reverse iterator pointing to the first item in the list, in reverse order.
QList< T >::size_type QList< T >::removeAll | ( | const T & | value | ) |
Removes all occurrences of value in the list and returns the number of entries removed.
This method requires the type T to support operator==()
.
|
inline |
Removes the item at index position i. The value i must be a valid index position in the list.
|
inline |
Equivalent to calling removeAt(0). Verify the list is not empty before calling this method.
|
inline |
Equivalent to calling removeAt(size() - 1). Verify the list is not empty before calling this method.
bool QList< T >::removeOne | ( | const T & | value | ) |
Removes the first occurrence of value in the list and returns true on success, otherwise returns false.
This method requires the type T to support operator==()
.
|
inline |
Returns a const STL style reverse iterator pointing to one past the last item in the list, in reverse order.
|
inline |
This is an overloaded method.
|
inline |
Replaces the item at index position i with value. The value for i must be a valid index position in the list, i >= 0 and i < size().
|
inline |
Resize this list to contain size number of elements.
|
inline |
|
inline |
Returns true if this list is not empty and its first item is equal to value, otherwise returns false.
|
inline |
Swaps list other with this list. This operation is very fast and never fails.
Exchange the item at index position i with the item at index position j. This method assumes that both i and j are at least 0 but less than size(). To avoid failure, test that both i and j are at least 0 and less than size().
|
inline |
Removes the item at index position i and returns it. The value for i must be a valid index position in the list, i >= 0 and i < size(). If the return value is not used then calling removeAt() is more efficient.
|
inline |
Removes the first item in the list and returns it. This is the same as takeAt(0). This function assumes the list is not empty. To avoid failure, call isEmpty() before calling this function.
If you do not use the return value removeFirst() is more efficient.
|
inline |
Removes the last item in the list and returns it. This is the same as takeAt(size() - 1). This function assumes the list is not empty. To avoid failure, call isEmpty() before calling this function.
If you do not use the return value removeLast() is more efficient.
QSet< T > QList< T >::toSet | ( | ) | const |
Returns a QSet object with the data contained in this QList. Since QSet does not allow duplicates, the resulting QSet might be smaller than the original list.
|
inline |
Returns a std::list object with the data contained in this QList.
QVector< T > QList< T >::toVector | ( | ) | const |
Returns a QVector object with the data contained in this QList.
T QList< T >::value | ( | size_type | i | ) | const |
Returns the value at index position i in the list. If you are certain the index is going to be within bounds, use the method at() which is slightly faster. If the index is out of bounds, a value initialized object is returned. Refer to default constructed elements for additional information.
T QList< T >::value | ( | size_type | i, |
const T & | defaultValue | ||
) | const |
Returns the value at index position i in the list. If the index i is out of bounds defaultValue is returned.
|
related |
Returns true if list lhs is lexicographically less than rhs, otherwise returns false. This method requires the type T to support operator<()
.
|
related |
Writes the given list to the stream. Returns a reference to the stream. This function requires the type T to support operator<<()
.
Refer to Serializing Data Types for additional information.
|
related |
Returns true if list lhs is lexicographically less than or equal to rhs, otherwise returns false. This method requires the type T to support operator<()
.
|
related |
Returns true if list lhs is lexicographically greater than rhs, otherwise returns false. This method requires the type T to support operator<()
.
|
related |
Returns true if list lhs is lexicographically greater than or equal to rhs, otherwise returns false. This method requires the type T to support operator<()
.
|
related |
Reads from the stream into the given list. Returns a reference to the stream. This function requires the type T to support operator>>()
.
Refer to Serializing Data Types for additional information.