Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::svg::Property< T, kCascade > Struct Template Reference

Holds a CSS property, which has a name and value, and integrates with inheritance to allow cascading values using the CSS model with specificity. More...

#include "donner/svg/properties/Property.h"

Collaboration diagram for donner::svg::Property< T, kCascade >:
[legend]

Public Types

using Type = T
 Type of the property value.
 

Public Member Functions

 Property (std::string_view name, GetInitialFn< T > getInitialFn=[]() -> std::optional< T > { return std::nullopt;})
 Property constructor, which is initially unset.
 
std::optional< T > get () const
 Get the property value, without considering inheritance.
 
getRequired () const
 Gets the value of the property, requiring that the value is not std::nullopt.
 
const T & getRequiredRef () const
 Gets a const-ref to the value, for accessing complex types without copying.
 
void set (std::optional< T > newValue, css::Specificity newSpecificity)
 Set the property to a new value at the given specificity.
 
void set (PropertyState newState, css::Specificity newSpecificity)
 Unset the current value and set the property to a specific state.
 
void substitute (std::optional< T > newValue)
 Replace the current property's value with a new value at the current specificity.
 
void clear ()
 Clear the current property's value.
 
Property< T, kCascade > inheritFrom (const Property< T, kCascade > &parent, PropertyInheritOptions options=PropertyInheritOptions::All) const
 Inherit the property from the parent element, if the parent has the property set at a higher specificity.
 
bool hasValue () const
 

Public Attributes

std::string_view name
 Property name, such as "color".
 
std::optional< T > value
 Property value, or std::nullopt if not set.
 
PropertyState state = PropertyState::NotSet
 Current state of the property, such as set or inherited.
 
css::Specificity specificity
 Specificity of the property, used for inheritance.
 
GetInitialFn< T > getInitialFn
 Function which is called to get the initial value of the property.
 

Detailed Description

template<typename T, PropertyCascade kCascade = PropertyCascade::None>
struct donner::svg::Property< T, kCascade >

Holds a CSS property, which has a name and value, and integrates with inheritance to allow cascading values using the CSS model with specificity.

Template Parameters
TThe type of the property value.
kCascadeDetermines how this property type participates in the cascade, to allow for specific property types to be excluded from inheritance.

Constructor & Destructor Documentation

◆ Property()

template<typename T , PropertyCascade kCascade = PropertyCascade::None>
donner::svg::Property< T, kCascade >::Property ( std::string_view name,
GetInitialFn< T > getInitialFn = []() -> std::optional<T> { return std::nullopt; } )
inline

Property constructor, which is initially unset.

Parameters
nameName of the property, such as "color".
getInitialFnFunction to get the initial value of the property.

Member Function Documentation

◆ get()

template<typename T , PropertyCascade kCascade = PropertyCascade::None>
std::optional< T > donner::svg::Property< T, kCascade >::get ( ) const
inline

Get the property value, without considering inheritance.

Returns the initial value if the property has not been set.

Returns
The value if it is set, or the initial value if it is not. Returns std::nullopt if the property is none.

◆ getRequired()

template<typename T , PropertyCascade kCascade = PropertyCascade::None>
T donner::svg::Property< T, kCascade >::getRequired ( ) const
inline

Gets the value of the property, requiring that the value is not std::nullopt.

Returns
The value.

◆ getRequiredRef()

template<typename T , PropertyCascade kCascade = PropertyCascade::None>
const T & donner::svg::Property< T, kCascade >::getRequiredRef ( ) const
inline

Gets a const-ref to the value, for accessing complex types without copying.

Requires that hasValue() is true.

Returns
const T& Reference to the value.

◆ hasValue()

template<typename T , PropertyCascade kCascade = PropertyCascade::None>
bool donner::svg::Property< T, kCascade >::hasValue ( ) const
inline
Returns
true if the property has any value set, including CSS built-in values.

◆ inheritFrom()

template<typename T , PropertyCascade kCascade = PropertyCascade::None>
Property< T, kCascade > donner::svg::Property< T, kCascade >::inheritFrom ( const Property< T, kCascade > & parent,
PropertyInheritOptions options = PropertyInheritOptions::All ) const
inline

Inherit the property from the parent element, if the parent has the property set at a higher specificity.

Note that this typically inherits "backwards", taking a local property which may already have a value and then overriding it if the parent has a more specific one. This is not required, but doing so is more efficient since we don't need to keep setting the property as the child overrides each parent.

Parameters
parentParent property to inherit into this one.
optionsOptions to control how inheritance is performed, to conditionally disable inheritance.
Returns
Property with the resolved value after inheritance.

◆ set() [1/2]

template<typename T , PropertyCascade kCascade = PropertyCascade::None>
void donner::svg::Property< T, kCascade >::set ( PropertyState newState,
css::Specificity newSpecificity )
inline

Unset the current value and set the property to a specific state.

Parameters
newStateNew state to set.
newSpecificitySpecificity to use.

◆ set() [2/2]

template<typename T , PropertyCascade kCascade = PropertyCascade::None>
void donner::svg::Property< T, kCascade >::set ( std::optional< T > newValue,
css::Specificity newSpecificity )
inline

Set the property to a new value at the given specificity.

Parameters
newValueValue to set, or std::nullopt to set to an empty value.
newSpecificitySpecificity to use.

◆ substitute()

template<typename T , PropertyCascade kCascade = PropertyCascade::None>
void donner::svg::Property< T, kCascade >::substitute ( std::optional< T > newValue)
inline

Replace the current property's value with a new value at the current specificity.

Parameters
newValueValue to use to replace the existing one.

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