QXmpp::Xml::Extensions Class
class QXmpp::Xml::ExtensionsA type-safe, ordered container for XML extension elements. More...
| Header: | #include <QXmppXmlExtensions.h> |
| Since: | QXmpp 1.16 |
Public Functions
| void | add(T value) |
| bool | contains() const |
| std::optional<T> | get() const |
| std::vector<T> | getAll() const |
| bool | remove() |
| int | removeAll() |
| void | toXml(QXmlStreamWriter *w) const |
| bool | tryParseAndAdd(QXmpp::Xml::Scope scope, const QDomElement &el) |
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.
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.
void Extensions::toXml(QXmlStreamWriter *w) const
Serializes all stored extensions to w.
Delegates to QXmpp::Xml::Registry::serializeAll for dispatch.
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).