Class Value¶
Defined in File sixtyfps_interpreter.h
Class Documentation¶
-
class sixtyfps::interpreter::Value¶
This is a dynamically typed value used in the SixtyFPS interpreter. It can hold a value of different types, and you should use the different overloaded constructors and the to_xxx() functions to access the value within.
It is also possible to query the type the value holds by calling the Value::type() function.
Note that models are only represented in one direction: You can create a sixtyfps::Model<Value> in C++, store it in a std::shared_ptr and construct Value from it. Then you can set it on a property in your .60 code that was declared to be either an array (
property <[sometype]> foo;
) or an object literal (property <{foo: string, bar: int}> my_prop;
). Such properties are dynamic and accept models implemented in C++.Value v(42.0); // Creates a value that holds a double with the value 42. Value some_value = ...; // Check if the value has a string if (std::optional<sixtyfps::SharedString> string_value = some_value.to_string()) do_something(*string_value); // Extract the string by de-referencing
Public Types
-
enum Type¶
This enum describes the different types the Value class can represent.
Values:
-
enumerator Void¶
The variant that expresses the non-type. This is the default.
-
enumerator Number¶
An
int
or afloat
(this is also used for unit based type such aslength
orangle
)
-
enumerator String¶
Correspond to the
string
type in .60.
-
enumerator Bool¶
Correspond to the
bool
type in .60.
-
enumerator Array¶
An Array in the .60 language.
-
enumerator Model¶
A more complex model which is not created by the interpreter itself (Type::Array can also be used for models)
-
enumerator Struct¶
An object.
-
enumerator Brush¶
Correspond to
brush
orcolor
type in .60. For color, this is then a sixtyfps::Brush with just a color.
-
enumerator Image¶
Correspond to
image
type in .60.
-
enumerator Other¶
The type is not a public type but something internal.
-
enumerator Void¶
Public Functions
-
inline Value()¶
Constructs a new value of type Value::Type::Void.
-
inline ~Value()¶
Destroys the value.
-
inline std::optional<double> to_number() const¶
Returns a std::optional that contains a double if the type of this Value is Type::Double, otherwise an empty optional is returned.
-
inline std::optional<sixtyfps::SharedString> to_string() const¶
Returns a std::optional that contains a string if the type of this Value is Type::String, otherwise an empty optional is returned.
-
inline std::optional<bool> to_bool() const¶
Returns a std::optional that contains a bool if the type of this Value is Type::Bool, otherwise an empty optional is returned.
-
inline std::optional<sixtyfps::SharedVector<Value>> to_array() const¶
Returns a std::optional that contains a vector of values if the type of this Value is Type::Array, otherwise an empty optional is returned.
-
inline std::optional<sixtyfps::Brush> to_brush() const¶
Returns a std::optional that contains a brush if the type of this Value is Type::Brush, otherwise an empty optional is returned.
-
inline std::optional<Struct> to_struct() const¶
Returns a std::optional that contains a Struct if the type of this Value is Type::Struct, otherwise an empty optional is returned.
-
inline std::optional<Image> to_image() const¶
Returns a std::optional that contains an Image if the type of this Value is Type::Image, otherwise an empty optional is returned.
Constructs a new Value that holds the string str.
Constructs a new Value that holds the value vector v.
Constructs a new Value that holds the value model m.
Friends
- inline friend friend bool operator== (const Value &a, const Value &b)
Returns true if and hold values of the same type and the underlying vales are equal.
- inline friend friend bool operator!= (const Value &a, const Value &b)
Returns true if and hold values of the same type and the underlying vales are not equal.
-
enum Type¶