Donner 0.5.0
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::svg::components::SubDocumentCache Class Reference

Cache for parsed SVG sub-documents referenced by <image> or <use> elements. More...

#include "donner/svg/components/resources/SubDocumentCache.h"

Public Types

using ParseCallback
 Callback type for parsing SVG content into a document.

Public Member Functions

 SubDocumentCache ()=default
 Constructor.
 ~SubDocumentCache ()=default
 Destructor.
 SubDocumentCache (const SubDocumentCache &)=delete
SubDocumentCacheoperator= (const SubDocumentCache &)=delete
 SubDocumentCache (SubDocumentCache &&)=default
SubDocumentCacheoperator= (SubDocumentCache &&)=default
std::optional< SVGDocumentHandlegetOrParse (const RcString &resolvedUrl, const std::vector< uint8_t > &svgContent, const ParseCallback &parseCallback, ParseWarningSink &warningSink)
 Get a previously cached sub-document, or parse and cache a new one from raw SVG bytes.
std::optional< SVGDocumentHandleget (const RcString &resolvedUrl) const
 Get a previously cached sub-document by URL.
bool isLoading (const RcString &resolvedUrl) const
 Returns true if the given URL is currently being loaded (for recursion detection).
size_t size () const
 Returns the number of cached sub-documents.

Detailed Description

Cache for parsed SVG sub-documents referenced by <image> or <use> elements.

Sub-documents are parsed in ProcessingMode::SecureStatic mode, which prevents them from loading their own external resources (per SVG2 ยง2.7.1). This prevents infinite recursion when document A references document B which references document A.

This stores SVGDocumentHandle values, which are the same shared internal state used by SVGDocument's by-value facade.

Member Typedef Documentation

◆ ParseCallback

Initial value:
std::function<std::optional<SVGDocumentHandle>(
const std::vector<uint8_t>& svgContent, ParseWarningSink& warningSink)>
Collects parse warnings during parsing.
Definition ParseWarningSink.h:28

Callback type for parsing SVG content into a document.

Called by getOrParse when the URL is not cached. Should return an SVGDocumentHandle on success, or std::nullopt on failure.

Member Function Documentation

◆ get()

std::optional< SVGDocumentHandle > donner::svg::components::SubDocumentCache::get ( const RcString & resolvedUrl) const

Get a previously cached sub-document by URL.

Parameters
resolvedUrlThe resolved URL to look up.
Returns
Cached document-state handle, or std::nullopt if not found.

◆ getOrParse()

std::optional< SVGDocumentHandle > donner::svg::components::SubDocumentCache::getOrParse ( const RcString & resolvedUrl,
const std::vector< uint8_t > & svgContent,
const ParseCallback & parseCallback,
ParseWarningSink & warningSink )

Get a previously cached sub-document, or parse and cache a new one from raw SVG bytes.

If the URL is already being loaded (circular reference), returns std::nullopt.

Parameters
resolvedUrlThe resolved URL used as the cache key.
svgContentRaw SVG document bytes to parse if not already cached.
parseCallbackCallback to parse SVG content into a document.
warningSinkSink to collect parse warnings.
Returns
Cached document-state handle, or std::nullopt on failure.

The documentation for this class was generated from the following files:
  • donner/svg/components/resources/SubDocumentCache.h
  • donner/svg/components/resources/SubDocumentCache.cc