W3cubDocs

/Qt

QMetaSequence Class

The QMetaSequence class allows type erased access to sequential containers. More...

Header: #include <QMetaSequence>
CMake: find_package(Qt6 COMPONENTS Core REQUIRED) target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Since: Qt 6.0
Inherits: QMetaContainer

Public Functions

void addValue(void *container, const void *value) const
void addValueAtBegin(void *container, const void *value) const
void addValueAtEnd(void *container, const void *value) const
bool canAddValue() const
bool canAddValueAtBegin() const
bool canAddValueAtEnd() const
bool canEraseRangeAtIterator() const
bool canEraseValueAtIterator() const
bool canGetValueAtConstIterator() const
bool canGetValueAtIndex() const
bool canGetValueAtIterator() const
bool canInsertValueAtIterator() const
bool canRemoveValue() const
bool canRemoveValueAtBegin() const
bool canRemoveValueAtEnd() const
bool canSetValueAtIndex() const
bool canSetValueAtIterator() const
void eraseRangeAtIterator(void *container, const void *iterator1, const void *iterator2) const
void eraseValueAtIterator(void *container, const void *iterator) const
void insertValueAtIterator(void *container, const void *iterator, const void *value) const
bool isSortable() const
void removeValue(void *container) const
void removeValueAtBegin(void *container) const
void removeValueAtEnd(void *container) const
void setValueAtIndex(void *container, qsizetype index, const void *value) const
void setValueAtIterator(const void *iterator, const void *value) const
void valueAtConstIterator(const void *iterator, void *result) const
void valueAtIndex(const void *container, qsizetype index, void *result) const
void valueAtIterator(const void *iterator, void *result) const
QMetaType valueMetaType() const

Static Public Members

QMetaSequence fromContainer()

Detailed Description

The class provides a number of primitive container operations, using void* as operands. This way, you can manipulate a generic container retrieved from a Variant without knowing its type.

The void* arguments to the various methods are typically created by using a QVariant of the respective container or value type, and calling its QVariant::data() or QVariant::constData() methods. However, you can also pass plain pointers to objects of the container or value type.

Iterator invalidation follows the rules given by the underlying containers and is not expressed in the API. Therefore, for a truly generic container, any iterators should be considered invalid after any write operation.

Member Function Documentation

void QMetaSequence::addValue(void *container, const void *value) const

Adds value to the container if possible. If canAddValue() returns false, the value is not added. Else, if canAddValueAtEnd() returns true, the value is added to the end of the container. Else, if canAddValueAtBegin() returns true, the value is added to the beginning of the container. Else, the value is added in an unspecified place or not at all. The latter is the case for adding values to an unordered container, for example QSet.

See also canAddValue(), canAddValueAtBegin(), canAddValueAtEnd(), isSortable(), and removeValue().

void QMetaSequence::addValueAtBegin(void *container, const void *value) const

Adds value to the beginning of container if possible. If canAddValueAtBegin() returns false, the value is not added.

See also canAddValueAtBegin(), isSortable(), and removeValueAtBegin().

void QMetaSequence::addValueAtEnd(void *container, const void *value) const

Adds value to the end of container if possible. If canAddValueAtEnd() returns false, the value is not added.

See also canAddValueAtEnd(), isSortable(), and removeValueAtEnd().

bool QMetaSequence::canAddValue() const

Returns true if values can be added to the container, false otherwise.

See also addValue() and isSortable().

bool QMetaSequence::canAddValueAtBegin() const

Returns true if values added using addValue() can be placed at the beginning of the container, otherwise returns false.

See also addValueAtBegin() and canAddValueAtEnd().

bool QMetaSequence::canAddValueAtEnd() const

Returns true if values added using addValue() can be placed at the end of the container, otherwise returns false.

See also addValueAtEnd() and canAddValueAtBegin().

bool QMetaSequence::canEraseRangeAtIterator() const

Returns true if a range between two iterators can be erased from the container, false otherwise.

bool QMetaSequence::canEraseValueAtIterator() const

Returns true if the value pointed to by a non-const iterator can be erased, false otherwise.

See also hasIterator() and eraseValueAtIterator().

bool QMetaSequence::canGetValueAtConstIterator() const

Returns true if the underlying container can retrieve the value pointed to by a const iterator, false otherwise.

See also hasConstIterator() and valueAtConstIterator().

bool QMetaSequence::canGetValueAtIndex() const

Returns true if values can be retrieved from the container by index, otherwise false.

See also valueAtIndex().

bool QMetaSequence::canGetValueAtIterator() const

Returns true if the underlying container can retrieve the value pointed to by a non-const iterator, false otherwise.

See also hasIterator() and valueAtIterator().

bool QMetaSequence::canInsertValueAtIterator() const

Returns true if the underlying container can insert a new value, taking the location pointed to by a non-const iterator into account.

See also hasIterator() and insertValueAtIterator().

bool QMetaSequence::canRemoveValue() const

Returns true if values can be removed from the container, false otherwise.

See also removeValue() and isSortable().

bool QMetaSequence::canRemoveValueAtBegin() const

Returns true if values can be removed from the beginning of the container using removeValue() can be placed at the, otherwise returns false.

See also removeValueAtBegin() and canRemoveValueAtEnd().

bool QMetaSequence::canRemoveValueAtEnd() const

Returns true if values can be removed from the end of the container using removeValue() can be placed at the, otherwise returns false.

See also removeValueAtEnd() and canRemoveValueAtBegin().

bool QMetaSequence::canSetValueAtIndex() const

Returns true if an value can be written to the container by index, otherwise false.

See also setValueAtIndex().

bool QMetaSequence::canSetValueAtIterator() const

Returns true if the underlying container can write to the value pointed to by a non-const iterator, false otherwise.

See also hasIterator() and setValueAtIterator().

void QMetaSequence::eraseRangeAtIterator(void *container, const void *iterator1, const void *iterator2) const

Erases the range of values between the iterators iterator1 and iterator2 from the container, if possible.

See also canEraseValueAtIterator(), begin(), and end().

void QMetaSequence::eraseValueAtIterator(void *container, const void *iterator) const

Erases the value pointed to by the non-const iterator from the container, if possible.

See also canEraseValueAtIterator(), begin(), and end().

[static, since 6.0] template <typename T> QMetaSequence QMetaSequence::fromContainer()

Returns the QMetaSequence corresponding to the type given as template parameter.

This function was introduced in Qt 6.0.

void QMetaSequence::insertValueAtIterator(void *container, const void *iterator, const void *value) const

Inserts value into the container, if possible, taking the non-const iterator into account. If canInsertValueAtIterator() returns false, the value is not inserted. Else if isSortable() returns true, the value is inserted before the value pointed to by iterator. Else, the value is inserted at an unspecified place or not at all. In the latter case, the iterator is taken as a hint. If it points to the correct place for the value, the operation may be faster than a addValue() without iterator.

See also canInsertValueAtIterator(), isSortable(), begin(), and end().

bool QMetaSequence::isSortable() const

Returns true if the underlying container is sortable, otherwise returns false. A container is considered sortable if values added to it are placed in a defined location. Inserting into or adding to a sortable container will always succeed. Inserting into or adding to an unsortable container may not succeed, for example if the container is a QSet that already contains the value being inserted.

See also addValue(), insertValueAtIterator(), canAddValueAtBegin(), canAddValueAtEnd(), canRemoveValueAtBegin(), and canRemoveValueAtEnd().

void QMetaSequence::removeValue(void *container) const

Removes an value from the container if possible. If canRemoveValue() returns false, no value is removed. Else, if canRemoveValueAtEnd() returns true, the last value in the container is removed. Else, if canRemoveValueAtBegin() returns true, the first value in the container is removed. Else, an unspecified value or nothing is removed.

See also canRemoveValue(), canRemoveValueAtBegin(), canRemoveValueAtEnd(), isSortable(), and addValue().

void QMetaSequence::removeValueAtBegin(void *container) const

Removes a value from the beginning of container if possible. If canRemoveValueAtBegin() returns false, the value is not removed.

See also canRemoveValueAtBegin(), isSortable(), and addValueAtBegin().

void QMetaSequence::removeValueAtEnd(void *container) const

Removes a value from the end of container if possible. If canRemoveValueAtEnd() returns false, the value is not removed.

See also canRemoveValueAtEnd(), isSortable(), and addValueAtEnd().

void QMetaSequence::setValueAtIndex(void *container, qsizetype index, const void *value) const

Overwrites the value at index in the container using the value passed as parameter if that is possible.

See also valueAtIndex() and canSetValueAtIndex().

void QMetaSequence::setValueAtIterator(const void *iterator, const void *value) const

Writes value to the value pointed to by the non-const iterator, if possible.

See also valueAtIterator(), canSetValueAtIterator(), begin(), and end().

void QMetaSequence::valueAtConstIterator(const void *iterator, void *result) const

Retrieves the value pointed to by the const iterator and stores it in the memory location pointed to by result, if possible.

See also canGetValueAtConstIterator(), constBegin(), and constEnd().

void QMetaSequence::valueAtIndex(const void *container, qsizetype index, void *result) const

Retrieves the value at index in the container and places it in the memory location pointed to by result, if that is possible.

See also setValueAtIndex() and canGetValueAtIndex().

void QMetaSequence::valueAtIterator(const void *iterator, void *result) const

Retrieves the value pointed to by the non-const iterator and stores it in the memory location pointed to by result, if possible.

See also setValueAtIterator(), canGetValueAtIterator(), begin(), and end().

QMetaType QMetaSequence::valueMetaType() const

Returns the meta type for values stored in the container.

© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-6.2/qmetasequence.html