|
|
Donner 0.5.1
Embeddable browser-grade SVG2 engine
|
A CSS component value, which is either a token, or a parsed function or block. More...
#include "donner/css/ComponentValue.h"
Public Types | |
| using | Type = std::variant<Token, Function, SimpleBlock> |
| The type of the component value, which is either a base Token or a logical group of tokens, Function or SimpleBlock. | |
Public Member Functions | |
| ComponentValue (Type &&value) | |
| Construct a new ComponentValue object, taking ownership of a Token. | |
| ~ComponentValue () | |
| Destructor. | |
| ComponentValue (const ComponentValue &)=default | |
| Copy constructor. | |
| ComponentValue & | operator= (const ComponentValue &)=default |
| Move constructor. | |
| ComponentValue (ComponentValue &&) noexcept=default | |
| Move assignment operator. | |
| ComponentValue & | operator= (ComponentValue &&) noexcept=default |
| Copy assignment operator. | |
| bool | operator== (const ComponentValue &other) const |
| Equality operator. | |
| template<typename T> | |
| bool | is () const |
| Check if the component value is of a given type. | |
| template<typename T> | |
| bool | isToken () const |
| Shorthand for checking if this component value holds a specific token. | |
| template<typename T> | |
| const T * | tryGetToken () const |
| Get the inner token value as a pointer, if the component value is a token and matches the requested type, or nullptr. | |
| template<typename T> | |
| T & | get () & |
| Get the component value as a reference. | |
| template<typename T> | |
| const T & | get () const & |
| Get the component value as a const-reference. | |
| template<typename T> | |
| T && | get () && |
| Get the component value as an rvalue-reference for move semantics. | |
| std::string | toCssText () const |
| Serialize this component value back to its CSS text representation. | |
| FileOffset | sourceOffset () const |
| Get the offset of this component value in the original source. | |
Public Attributes | |
| Type | value |
| The actual value of the component value. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const ComponentValue &component) |
| Output a human-readable representation of the component value to a stream. | |
A CSS component value, which is either a token, or a parsed function or block.
This is the second level of parsing, after Token. A Token is a single lexical unit, and ComponentValue groups those into logical function and block groups, as well as wrapping standalone Token.
ComponentValue is the base component traversed when parsing CSS into logical blocks, such as Selector and donner::svg::Property.
| donner::css::ComponentValue::ComponentValue | ( | Type && | value | ) |
Construct a new ComponentValue object, taking ownership of a Token.
| value | Token to construct from. |
|
inline |
Get the component value as a reference.
Example usage:
|
inline |
Get the component value as an rvalue-reference for move semantics.
Example usage:
|
inline |
Get the component value as a const-reference.
Example usage:
|
inline |
Check if the component value is of a given type.
For example:
|
inline |
Shorthand for checking if this component value holds a specific token.
For example:
Which is equivalent to component.is<Token>() && component.get<Token>().is<Token::Percentage>().
| T | Token type to check, which must be within the Token::TokenValue list. |
|
inline |
Get the offset of this component value in the original source.
For Function and SimpleBlock, returns the offset of the group opening token.
| std::string donner::css::ComponentValue::toCssText | ( | ) | const |
Serialize this component value back to its CSS text representation.
Unlike operator<< which outputs a debug representation, this produces valid CSS text that can be parsed back.
|
inline |
Get the inner token value as a pointer, if the component value is a token and matches the requested type, or nullptr.
See also Token::tryGet().
Example:
| T | Token type to check, which must be within the Token::TokenValue list. |
|
friend |
Output a human-readable representation of the component value to a stream.
| os | Output stream. |
| component | Component value to output. |