#include <Ultralight/js/Value.h>
A reference to a property of a Value (returned by Value::operator[]).
Reading a Ref gives you the property's value, assigning to it sets the property, and calling it calls the property as a method of the object. Refs chain (obj["a"]["b"] = 1).
Use a Ref within one expression. To keep a property's value, read it into a Value.
- Note
- A Ref has To(), Maybe(), and Or(). For the other conversions, read the property first (eg, obj["volume"].Get().ToNumber()).
|
| Value | Get () const |
| | Read the property.
|
| | operator Value () const |
| | Read the property (the same as Get()).
|
| template<typename T> |
| Ref & | operator= (T &&value) |
| | Set the property to value (converted through js::TypeTraits).
|
| Ref | operator[] (const char *name) const |
| | Read this property and access a property of its value.
|
template<typename I>
requires (std::is_integral_v<I> && !std::is_same_v<I, bool>) |
| Ref | operator[] (I index) const |
| template<typename R = Value, typename... A> |
| Result< R > | Invoke (A &&... args) const |
| | Call the property as a method of its object (otherwise the same as Value::Invoke()).
|
| template<typename... A> |
| Result< Value > | operator() (A &&... args) const |
| | Call the property as a method: obj["save"](path) is the same as obj["save"].Invoke(path).
|
| template<typename T> |
| Result< T > | To () const |
| | Read the property and convert it to a C++ type (see Value::To()).
|
| template<typename T> |
| std::optional< T > | Maybe () const |
| | Read the property and convert it to a C++ type like To() but without the failure reason.
|
| template<typename T> |
| T | Or (T fallback) const |
| | Read the property and convert it to a C++ type with a fallback.
|
| std::string | Or (const char *fallback) const |
| | Read the property and convert it to a std::string with a string-literal fallback.
|
| | Ref (const Ref &)=default |
| | Copy constructor (refers to the same property).
|
| Ref & | operator= (const Ref &other) |
| | Set this property to the value of another Ref's property.
|
◆ Ref()
Copy constructor (refers to the same property).
◆ Get()
◆ Invoke()
template<typename R = Value, typename... A>
| Result< R > Invoke |
( |
A &&... | args | ) |
const |
Call the property as a method of its object (otherwise the same as Value::Invoke()).
global["JSON"]["stringify"](payload);
Expected< T, Error > Result
The result of a JavaScript operation that can fail: a T or a js::Error.
Definition Error.h:520
- Parameters
-
| args | The arguments to pass to the method. |
- Returns
- Returns the call's result converted to R and fails the same way as Value::Invoke().
◆ Maybe()
template<typename T>
| std::optional< T > Maybe |
( |
| ) |
const |
|
nodiscard |
Read the property and convert it to a C++ type like To() but without the failure reason.
- Returns
- Returns the converted value or nullopt on any failure.
◆ operator Value()
Read the property (the same as Get()).
◆ operator()()
Call the property as a method: obj["save"](path) is the same as obj["save"].Invoke(path).
- Parameters
-
| args | The arguments to pass to the method. |
- Returns
- Returns the call's result and fails the same way as Invoke().
◆ operator=() [1/2]
| Ref & operator= |
( |
const Ref & | other | ) |
|
|
inline |
Set this property to the value of another Ref's property.
- Parameters
-
| other | The Ref to read the value from. |
- Returns
- Returns this Ref.
- Note
- A Ref always refers to the same property: assigning to it sets the property's value and never changes which property it refers to (like std::map's operator[]).
◆ operator=() [2/2]
template<typename T>
| Ref & operator= |
( |
T && | value | ) |
|
Set the property to value (converted through js::TypeTraits).
- Parameters
-
| value | The value to assign. |
- Returns
- Returns this Ref.
- Note
- Failures are ignored (eg, the page is gone or a setter throws). Use Value::SetProperty() if you need to check.
◆ operator[]() [1/2]
| Ref operator[] |
( |
const char * | name | ) |
const |
|
inline |
Read this property and access a property of its value.
- Parameters
-
- Returns
- Returns a Ref for the nested property.
◆ operator[]() [2/2]
template<typename I>
requires (std::is_integral_v<I> && !std::is_same_v<I, bool>)
| Ref operator[] |
( |
I | index | ) |
const |
|
inline |
◆ Or() [1/2]
| std::string Or |
( |
const char * | fallback | ) |
const |
|
inlinenodiscard |
Read the property and convert it to a std::string with a string-literal fallback.
- Parameters
-
| fallback | The text to return if the read or the conversion fails. |
- Returns
- Returns the converted string or fallback on any failure.
◆ Or() [2/2]
Read the property and convert it to a C++ type with a fallback.
- Parameters
-
| fallback | The value to return if the read or the conversion fails. |
- Returns
- Returns the converted value or fallback on any failure.
◆ To()
Read the property and convert it to a C++ type (see Value::To()).
- Returns
- Returns the converted value and fails the same way as Value::To().
◆ Context
◆ Value
The documentation for this class was generated from the following file: