Donner SVG 0.8.0-pre
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::xml::components::XMLNamespaceContext Class Reference

Manages XML namespace state for a document. More...

#include "donner/base/xml/components/XMLNamespaceContext.h"

Public Member Functions

 XMLNamespaceContext (Registry &registry, std::size_t maximumCachedScopeBindings=kMaximumCachedScopeBindings)
 Constructor, this should only be called once to construct on the given Registry, with registry.ctx().emplace<XMLNamespaceContext>(registry).
void addNamespaceOverride (Entity entity, const XMLQualifiedName &name, const RcString &uri)
 Add a namespace override for the given entity.
void removeNamespaceOverride (Entity entity, const XMLQualifiedName &name)
 Removes a namespace override for the given entity.
std::optional< RcStringgetNamespaceUri (Registry &registry, Entity entity, const RcString &prefix) const
 Get the URI for the given namespace prefix.
std::uint64_t scopeResolutionCountForTesting () const
 Number of entities whose scope has been computed from their ancestors, which only happens when the entity has no cached scope. Lets a test tell a cache hit from a recomputation.
std::size_t cachedScopeBindingsForTesting () const
 Number of unique prefix bindings retained by cached scope maps.
bool scopeCacheRejectedForTesting () const
 True after namespace-scope cache admission exceeded its aggregate bound.

Static Public Member Functions

static void InvalidateScopesForTreeChange (Registry &registry, Entity entity)
 Drop cached namespace scopes for a subtree that was just attached or detached.

Static Public Attributes

static constexpr std::size_t kMaximumCachedScopeBindings = 64 * 1024
 Maximum aggregate prefix bindings retained across cached namespace-scope maps.

Detailed Description

Manages XML namespace state for a document.

Access via the Registry::ctx API:

XMLNamespaceContext& context = registry.ctx().get<XMLNamespaceContext>();
XMLNamespaceContext(Registry &registry, std::size_t maximumCachedScopeBindings=kMaximumCachedScopeBindings)
Constructor, this should only be called once to construct on the given Registry, with registry....
Definition XMLNamespaceContext.h:50

Constructor & Destructor Documentation

◆ XMLNamespaceContext()

donner::xml::components::XMLNamespaceContext::XMLNamespaceContext ( Registry & registry,
std::size_t maximumCachedScopeBindings = kMaximumCachedScopeBindings )
inlineexplicit

Constructor, this should only be called once to construct on the given Registry, with registry.ctx().emplace<XMLNamespaceContext>(registry).

To use this class, access it via the Registry::ctx API.

XMLNamespaceContext& context = registry.ctx().get<XMLNamespaceContext>();
Parameters
registryUnderlying registry for the document.

Member Function Documentation

◆ addNamespaceOverride()

void donner::xml::components::XMLNamespaceContext::addNamespaceOverride ( Entity entity,
const XMLQualifiedName & name,
const RcString & uri )
inline

Add a namespace override for the given entity.

If the attribute has changed this may be called again with the same name but different URI.

Parameters
entityEntity to add the namespace override for.
nameNamespace attribute to override.
uriNamespace URI to use for the prefix.

◆ getNamespaceUri()

std::optional< RcString > donner::xml::components::XMLNamespaceContext::getNamespaceUri ( Registry & registry,
Entity entity,
const RcString & prefix ) const
inline

Get the URI for the given namespace prefix.

Resolved scopes are cached, so the first lookup below an element pays for the ancestor walk and later ones are a map lookup. Like the rest of the document's read paths that populate state on demand, this must not run concurrently with another access to the same document.

Parameters
registryRegistry to use for the lookup.
entityEntity to get the namespace URI for.
prefixNamespace prefix to get the URI for.
Returns
The URI for the given namespace prefix, or an empty string if the prefix is not found.

◆ InvalidateScopesForTreeChange()

void donner::xml::components::XMLNamespaceContext::InvalidateScopesForTreeChange ( Registry & registry,
Entity entity )
inlinestatic

Drop cached namespace scopes for a subtree that was just attached or detached.

An element's in-scope namespaces come from its ancestors, so re-parenting a node can change which declarations apply to it and to everything below it, and nothing else. Registries without an XMLNamespaceContext are ignored.

Parameters
registryRegistry whose tree changed.
entityRoot of the subtree that moved.

◆ removeNamespaceOverride()

void donner::xml::components::XMLNamespaceContext::removeNamespaceOverride ( Entity entity,
const XMLQualifiedName & name )
inline

Removes a namespace override for the given entity.

Parameters
entityEntity to remove the namespace override for.
nameNamespace attribute to remove.

The documentation for this class was generated from the following file: