|
|
Donner 0.5.0
Embeddable browser-grade SVG2 engine
|
Represents a reference to an SVG entity by its href, typically created from a url(#id) string. More...
#include "donner/svg/graph/Reference.h"
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< ResolvedReference > | resolve (Registry ®istry) const |
| Attempts to resolve the reference as a same-document reference using the provided registry. | |
| std::optional< ResolvedReference > | resolveFragment (Registry ®istry) 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. | |
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.
|
inline |
|
inline |
Constructs a Reference from a C-style string.
| href | The href string |
| 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:
| 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:
| 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.
| 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.
| registry | The Registry to use for resolution |
| 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.
| registry | The Registry to resolve the fragment against. |