QXmpp::Xml::Extensions Class

class QXmpp::Xml::Extensions

A type-safe, ordered container for XML extension elements. More...

Header: #include <QXmppXmlExtensions.h>
Since: QXmpp 1.16

Public Functions

void add(T value)
(since QXmpp 1.18) void append(const QXmpp::Xml::Extensions &other)
bool contains() const
std::optional<T> get() const
std::vector<T> getAll() const
bool remove()
int removeAll()
int removeIf(const std::function<bool (const std::any &)> &predicate)
void toXml(QXmlStreamWriter *w) const
void toXml(QXmlStreamWriter *w, QXmpp::SceMode sceMode) const
bool tryParseAndAdd(QXmpp::Xml::Scope scope, const QDomElement &el)
bool tryParseAndAdd(QXmpp::Xml::Scope scope, const QDomElement &el, QXmpp::SceMode sceMode, QXmpp::Xml::Extensions &publicExtensions)

Detailed Description

Extensions stores zero or more XML extension values as type-erased std::any entries. Values are added either by the stanza's parseExtension hook via QXmpp::Xml::Registry (typed entries) or as a QXmpp::Xml::Element fallback for unknown elements. Values can be accessed, iterated, and mutated by the application without knowledge of the concrete type used internally.

The container follows value semantics with implicit sharing (copy-on-write).

Member Function Documentation

template <typename T> void Extensions::add(T value)

Appends value.

For value to be serialized when the stanza is sent, its type must be registered via QXmpp::Xml::Registry (the QXmpp::Xml::Element fallback type is the exception and is always serializable). Unregistered types are kept in the container but skipped during serialization with a warning.

[since QXmpp 1.18] void Extensions::append(const QXmpp::Xml::Extensions &other)

Appends all values of other.

This function was introduced in QXmpp 1.18.

template <typename T> bool Extensions::contains() const

Returns true if at least one value of type T is present.

template <typename T> std::optional<T> Extensions::get() const

Returns the first value of type T, or std::nullopt if none is present.

template <typename T> std::vector<T> Extensions::getAll() const

Returns all values of type T.

template <typename T> bool Extensions::remove()

Removes the first value of type T and returns true if one was found.

template <typename T> int Extensions::removeAll()

Removes all values of type T and returns how many were removed.

int Extensions::removeIf(const std::function<bool (const std::any &)> &predicate)

Removes all values for which predicate returns true and returns how many were removed.

void Extensions::toXml(QXmlStreamWriter *w) const

Serializes all stored extensions to w.

Delegates to QXmpp::Xml::Registry::serializeAll for dispatch.

void Extensions::toXml(QXmlStreamWriter *w, QXmpp::SceMode sceMode) const

Serializes the stored extensions of the part sceMode of an encrypted stanza to w.

bool Extensions::tryParseAndAdd(QXmpp::Xml::Scope scope, const QDomElement &el)

Parses el as a registered extension type and adds it to the container.

If the registry has no matching registration for scope, the element is stored as a QXmpp::Xml::Element fallback so that round-trip serialization is preserved.

Returns true always (the element is always consumed).

bool Extensions::tryParseAndAdd(QXmpp::Xml::Scope scope, const QDomElement &el, QXmpp::SceMode sceMode, QXmpp::Xml::Extensions &publicExtensions)

Like tryParseAndAdd(), but for parsing a part of an end-to-end encrypted stanza.

With QXmpp::ScePublic (the unencrypted part of an encrypted stanza), sensitive elements are added to publicExtensions instead, so they can't be mistaken for encrypted content.