Donner SVG main
0.8.0 ยท 382bd0190.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 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"

Classes

struct  Limits
 Local admission ceilings, also tightening the family when bound to a resource registry. Entity and parsed-payload admission snapshots include the original root. More...
struct  SecurityStats
 Observed cache size, parse work, and admission failures. More...

Public Types

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

Public Member Functions

 SubDocumentCache ()=default
 Constructor.
 SubDocumentCache (Limits limits)
 Create a cache with caller-selected document and parse limits.
 ~SubDocumentCache ()=default
 Destructor.
 SubDocumentCache (const SubDocumentCache &)=delete
SubDocumentCache & operator= (const SubDocumentCache &)=delete
 SubDocumentCache (SubDocumentCache &&)=default
 Move constructor.
SubDocumentCache & operator= (SubDocumentCache &&)=default
 Move assignment operator.
std::optional< SVGDocumentHandle > 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.
std::optional< SVGDocumentHandle > get (const RcString &resolvedUrl) const
 Get a previously cached sub-document by URL.
void rememberFailure (const RcString &resolvedUrl)
 Record a failed fetch or parse so the URL is not retried.
bool isRejected (const RcString &resolvedUrl) const
 Return true when the URL has a negative cache entry.
void clearFailures ()
 Clear failed-URL entries when the application replaces its resource loader.
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.
void setRootEntityCount (size_t count)
 Include root-document entities in the aggregate retained-node envelope.
void setRootPayloadBytes (size_t count)
 Include root-document parsed payload in the aggregate retained-payload envelope.
bool bindFamily (Registry &registry)
 Bind production resource admission to this registry and its requesting families.
const SecurityStats & securityStats () const
 Current parse, cache, and rejection counters.

Friends

class SubDocumentAdmission

Detailed Description

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

Default sub-document parsing uses ProcessingMode::SecureStatic, which blocks external fetching. Nested data resources also pass shared family admission and bounded cycle checks.

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


Class Documentation

◆ donner::svg::components::SubDocumentCache::Limits

struct donner::svg::components::SubDocumentCache::Limits

Local admission ceilings, also tightening the family when bound to a resource registry. Entity and parsed-payload admission snapshots include the original root.

Class Members
size_t maximumAggregateEntities = 32 * 1024 Root plus cached sub-document entities.
size_t maximumAggregatePayloadBytes Root plus cached parsed-payload bytes.
size_t maximumDocuments = 64 Distinct cached documents.
size_t maximumParseAttempts = 128 Parse attempts, including failures.

◆ donner::svg::components::SubDocumentCache::SecurityStats

struct donner::svg::components::SubDocumentCache::SecurityStats

Observed cache size, parse work, and admission failures.

Class Members
size_t documents = 0 Successfully cached sub-documents.
size_t entities = 0 Aggregate entities in cached sub-documents.
size_t negativeCacheHits = 0 Negative-cache or reject-all short-circuits.
size_t parseAttempts = 0 Parse attempts charged to this cache.
size_t payloadBytes = 0 Aggregate retained parsed-payload bytes.
bool rejected = false Whether an admission limit rejected a request.

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:29

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.

Constructor & Destructor Documentation

◆ SubDocumentCache()

donner::svg::components::SubDocumentCache::SubDocumentCache ( Limits limits)
inlineexplicit

Create a cache with caller-selected document and parse limits.

Parameters
limitsAdmission limits for referenced sub-documents.

Member Function Documentation

◆ bindFamily()

bool donner::svg::components::SubDocumentCache::bindFamily ( Registry & registry)

Bind production resource admission to this registry and its requesting families.

Parameters
registryRegistry owning this cache.

◆ 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 file: