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

Represents a reference to an SVG entity by its href, typically created from a url(#id) string. More...

#include "donner/svg/graph/Reference.h"

Collaboration diagram for donner::svg::Reference:
[legend]

Public Member Functions

 Reference (const RcString &href)
 Constructs a Reference from an RcString.
 Reference (const char *href)
 Constructs a Reference from a C-style string.
bool isExternal () const
 Returns true if this reference points to an external document (i.e., has a document URL component).
std::string_view documentUrl () const
 Returns the document URL component of the reference, or an empty string if this is a same-document reference.
std::string_view fragment () const
 Returns the fragment component of the reference (without the # prefix), or an empty string if there is no fragment.
std::optional< ResolvedReferenceresolve (Registry &registry) const
 Attempts to resolve the reference as a same-document reference using the provided registry.
std::optional< ResolvedReferenceresolveFragment (Registry &registry) const
 Resolves a fragment identifier against the given registry.
bool operator== (const Reference &other) const =default
 Equality operator.

Public Attributes

RcString href
 The href string identifying the referenced entity, e.g. #id.

Friends

std::ostream & operator<< (std::ostream &os, const Reference &ref)
 Outputs the href string to a stream.

Detailed Description

Represents a reference to an SVG entity by its href, typically created from a url(#id) string.

The reference can be resolved to an entity using resolve.

Supports both same-document and external references:

Source href value Type
url(#id) #id Same-document
href="#id" #id Same-document
href="file.svg" file.svg External (whole document)
href="file.svg#id" file.svg#id External (element by ID)

Same-document references are resolved via resolve(). External references require loading the external document first; use isExternal(), documentUrl(), and fragment() to inspect the reference components, then resolve the fragment against the external document's registry.

Constructor & Destructor Documentation

◆ Reference() [1/2]

donner::svg::Reference::Reference ( const RcString & href)
inline

Constructs a Reference from an RcString.

Parameters
hrefThe href string

◆ Reference() [2/2]

donner::svg::Reference::Reference ( const char * href)
inline

Constructs a Reference from a C-style string.

Parameters
hrefThe href string

Member Function Documentation

◆ documentUrl()

std::string_view donner::svg::Reference::documentUrl ( ) const

Returns the document URL component of the reference, or an empty string if this is a same-document reference.

Examples:

  • #id""
  • file.svg"file.svg"
  • file.svg#elementId"file.svg"
  • path/to/file.svg#id"path/to/file.svg"

◆ fragment()

std::string_view donner::svg::Reference::fragment ( ) const

Returns the fragment component of the reference (without the # prefix), or an empty string if there is no fragment.

Examples:

  • #id"id"
  • file.svg""
  • file.svg#elementId"elementId"

◆ isExternal()

bool donner::svg::Reference::isExternal ( ) const

Returns true if this reference points to an external document (i.e., has a document URL component).

A reference like #id is same-document; file.svg or file.svg#id is external.

◆ resolve()

std::optional< ResolvedReference > donner::svg::Reference::resolve ( Registry & registry) const

Attempts to resolve the reference as a same-document reference using the provided registry.

Only handles fragment-only references (#id). For external references, use isExternal() and load the external document separately.

Parameters
registryThe Registry to use for resolution
Returns
An optional ResolvedReference, which is empty if resolution fails

◆ resolveFragment()

std::optional< ResolvedReference > donner::svg::Reference::resolveFragment ( Registry & registry) const

Resolves a fragment identifier against the given registry.

Unlike resolve(), this does not require the href to start with # — it uses the fragment() component directly. This is used for resolving external references after loading the external document.

Parameters
registryThe Registry to resolve the fragment against.
Returns
An optional ResolvedReference, which is empty if the fragment is empty or not found.

The documentation for this struct was generated from the following files:
  • donner/svg/graph/Reference.h
  • donner/svg/graph/Reference.cc