QXmpp::Xml::Registry Class
class QXmpp::Xml::RegistryA global registry for type-driven parsing and serialization of XML extension elements. More...
| Header: | #include <QXmppXmlRegistry.h> |
| Since: | QXmpp 1.16 |
Static Public Members
| void | registerElement(QXmpp::Xml::Scopes scopes) |
| void | serializeAll(QXmlStreamWriter &w, const std::vector<std::any> &items) |
| std::optional<std::any> | tryParse(QXmpp::Xml::Scope scope, const QDomElement &el) |
| void | unregisterElement() |
Detailed Description
Registered types are matched by their XmlTag static member. When a stanza's parseExtension hook encounters an unknown element, Registry::tryParse is consulted. The first matching entry returns a typed std::any value which is stored in the stanza's QXmpp::Xml::Extensions container.
The registry is a process-wide singleton protected by a read-write lock. Lookup takes roughly 30 ns and is negligible compared to XML parse costs.
Registration
Register a type once at application startup:
QXmpp::Xml::Registry::registerElement<MyFlag>(QXmpp::Xml::Scope::Message);
// Generic scope matches in every stanza context:
QXmpp::Xml::Registry::registerElement<MyDebugTag>(QXmpp::Xml::Scope::Generic);
Constraints on T
T must satisfy:
T::XmlTag— a tag/namespace pair (seeQXmpp::Private::HasXmlTag).- One of the three parse styles (
QXmpp::Private::DomParsable):staticstd::optional<T> T::fromDom(const QDomElement &)boolT::parse(const QDomElement &)voidT::parse(const QDomElement &)
voidT::toXml(QXmlStreamWriter *) const (serialization).
Member Function Documentation
[static] template <typename T> requires QXmpp::Private::HasXmlTag<T> && QXmpp::Private::DomParsable<T> && QXmpp::Private::QXmlStreamSerializeable<T> void Registry::registerElement(QXmpp::Xml::Scopes scopes)
Registers T for the given scopes.
If a type with the same XmlTag is already registered, the previous entry is replaced and a warning is emitted.
[static] void Registry::serializeAll(QXmlStreamWriter &w, const std::vector<std::any> &items)
Serializes all items to w by dispatching to each item's registered serializer. QXmpp::Xml::Element fallback items are handled directly. Items with no registered serializer emit a warning and are skipped.
[static] std::optional<std::any> Registry::tryParse(QXmpp::Xml::Scope scope, const QDomElement &el)
Attempts to parse el as a registered extension type for scope.
Returns a typed std::any on success, or std::nullopt if no matching registration is found.
[static] template <typename T> void Registry::unregisterElement()
Removes the registration for T.
After this call, unknown elements with T's tag/namespace are stored as a QXmpp::Xml::Element fallback instead.