Template class can hold a value or a formula to calculate the value. More...
#include <typed_formula.hpp>
Public Member Functions | |
typed_formula (const std::string &str, const T value=T()) | |
Constructor. More... | |
T | operator() () const |
Returns the value, can only be used if the data is no formula. More... | |
T | operator() (const wfl::map_formula_callable &variables, wfl::function_symbol_table *functions=nullptr) const |
Returns the value, can always be used. More... | |
bool | has_formula () const |
Determine whether the class contains a formula. More... | |
Private Member Functions | |
void | convert (const std::string &str) |
Converts the string to the template type. More... | |
T | execute (wfl::variant &v) const |
Executes the formula. More... | |
bool | execute (wfl::variant &v) const |
Template specializations. More... | |
void | convert (const std::string &str) |
int | execute (wfl::variant &v) const |
unsigned | execute (wfl::variant &v) const |
std::string | execute (wfl::variant &v) const |
void | convert (const std::string &str) |
t_string | execute (wfl::variant &v) const |
void | convert (const std::string &str) |
PangoAlignment | execute (wfl::variant &v) const |
void | convert (const std::string &str) |
color_t | execute (wfl::variant &v) const |
void | convert (const std::string &str) |
Private Attributes | |
utils::optional< std::string > | formula_ |
Contains the formula for the variable. More... | |
T | value_ |
If there's no formula it contains the value. More... | |
Template class can hold a value or a formula to calculate the value.
A string is a formula when it starts with a right paren, no other validation is done by this function, leading whitespace is significant.
Upon getting the value of the formula a variable map is send. The variables in the map can be used in the formula. The 'owners' of the class need to document the variables available.
T | The type of the formula. This type needs to be constructable form a string, either by a lexical_cast or a template specialization in this header. |
Definition at line 50 of file typed_formula.hpp.
|
explicit |
Constructor.
str | The string used to initialize the class, this can either be a formula or a string which can be converted to the type T. |
value | The default value for the object. |
Definition at line 137 of file typed_formula.hpp.
References gui2::typed_formula< T >::convert(), and gui2::typed_formula< T >::formula_.
|
inlineprivate |
Converts the string to the template type.
This function is used by the constructor to convert the string to the wanted value, if not a formula.
str | The str send to the constructor. |
Definition at line 272 of file typed_formula.hpp.
Referenced by gui2::typed_formula< T >::typed_formula().
|
inlineprivate |
Definition at line 180 of file typed_formula.hpp.
References utils::string_bool().
|
inlineprivate |
Definition at line 209 of file typed_formula.hpp.
|
inlineprivate |
Definition at line 222 of file typed_formula.hpp.
|
inlineprivate |
Definition at line 235 of file typed_formula.hpp.
References gui2::decode_text_alignment().
|
inlineprivate |
Definition at line 256 of file typed_formula.hpp.
References color_t::from_rgba_string().
|
inlineprivate |
Executes the formula.
This function does the calculation and can only be called if the object contains a formula.
v | A variant object containing the evaluated value of the formula. |
Definition at line 263 of file typed_formula.hpp.
|
inlineprivate |
Template specializations.
Each type must have an execute specialization, and optionally one for convert.
Definition at line 174 of file typed_formula.hpp.
References wfl::variant::as_bool().
|
inlineprivate |
Definition at line 187 of file typed_formula.hpp.
References wfl::variant::as_int().
|
inlineprivate |
Definition at line 194 of file typed_formula.hpp.
References wfl::variant::as_int().
|
inlineprivate |
Definition at line 203 of file typed_formula.hpp.
References wfl::variant::as_string().
|
inlineprivate |
Definition at line 216 of file typed_formula.hpp.
References wfl::variant::as_string().
|
inlineprivate |
Definition at line 229 of file typed_formula.hpp.
References wfl::variant::as_string(), and gui2::decode_text_alignment().
|
inlineprivate |
Definition at line 242 of file typed_formula.hpp.
References ALPHA_OPAQUE, and wfl::variant::as_list().
|
inline |
Determine whether the class contains a formula.
Definition at line 96 of file typed_formula.hpp.
References gui2::typed_formula< T >::formula_.
Referenced by gui2::spacer::fills_available_space(), gui2::typed_formula< T >::operator()(), gui2::rectangle_shape::rectangle_shape(), gui2::round_rectangle_shape::round_rectangle_shape(), and gui2::builder_window::window_resolution::window_resolution().
|
inline |
Returns the value, can only be used if the data is no formula.
Another option would be to cache the output of the formula in value_ and always allow this function. But for now decided that the caller needs to do the caching. It might be changed later.
Definition at line 70 of file typed_formula.hpp.
References gui2::typed_formula< T >::has_formula(), and gui2::typed_formula< T >::value_.
|
inline |
Returns the value, can always be used.
variables | The state variables which might be used in the formula. For example, screen_width can be set so the formula can return the half width of the screen. |
functions | The variables, which can be called during the evaluation of the formula. (Note it is also possible to add extra functions to the table, when the variable is not nullptr . |
Definition at line 152 of file typed_formula.hpp.
References DBG_GUI_D, and wfl::formula::evaluate().
|
private |
Contains the formula for the variable.
If without value, there's no formula.
Definition at line 130 of file typed_formula.hpp.
Referenced by gui2::typed_formula< T >::has_formula(), and gui2::typed_formula< T >::typed_formula().
|
private |
If there's no formula it contains the value.
Definition at line 133 of file typed_formula.hpp.
Referenced by gui2::typed_formula< T >::operator()().