Template class can hold a value or a formula to calculate the value. More...
#include <formula.hpp>

Public Member Functions | |
| tformula (const std::string &str, const T value=T()) | |
| Constructor. | |
| T | operator() () const |
| Returns the value, can only be used if the data is no formula. | |
| T | operator() (const game_logic::map_formula_callable &variables) const |
| Returns the value, can always be used. | |
| bool | has_formula () const |
| Determine whether the class contains a formula. | |
Private Member Functions | |
| void | convert (const std::string &str) |
| Converts the string to the template type. | |
| T | execute (const game_logic::map_formula_callable &variables) const |
| Executes the formula. | |
| template<> | |
| bool | execute (const game_logic::map_formula_callable &variables) const |
| template<> | |
| int | execute (const game_logic::map_formula_callable &variables) const |
| template<> | |
| unsigned | execute (const game_logic::map_formula_callable &variables) const |
| template<> | |
| std::string | execute (const game_logic::map_formula_callable &variables) const |
| template<> | |
| t_string | execute (const game_logic::map_formula_callable &variables) const |
| template<> | |
| PangoAlignment | execute (const game_logic::map_formula_callable &variables) const |
| template<> | |
| void | convert (const std::string &str) |
| template<> | |
| void | convert (const std::string &str) |
| template<> | |
| void | convert (const std::string &str) |
| template<> | |
| void | convert (const std::string &str) |
Private Attributes | |
| std::string | formula_ |
| Contains the formuale for the variable. | |
| T | value_ |
| If there's no formula it contains the value. | |
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 49 of file formula.hpp.
| gui2::tformula< T >::tformula | ( | const std::string & | str, | |
| const T | value = T() | |||
| ) | [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 120 of file formula.hpp.
References gui2::tformula< T >::convert(), and gui2::tformula< T >::formula_.

| void gui2::tformula< T >::convert | ( | const std::string & | str | ) | [inline, private] |
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 228 of file formula.hpp.
References gui2::tformula< T >::value_.
Referenced by gui2::tformula< T >::tformula().

| void gui2::tformula< PangoAlignment >::convert | ( | const std::string & | str | ) | [inline, private] |
Definition at line 222 of file formula.hpp.
References gui2::decode_text_alignment(), and gui2::tformula< T >::value_.

| void gui2::tformula< bool >::convert | ( | const std::string & | str | ) | [inline, private] |
Definition at line 204 of file formula.hpp.
References utils::string_bool(), and gui2::tformula< T >::value_.

| void gui2::tformula< std::string >::convert | ( | const std::string & | str | ) | [inline, private] |
Definition at line 210 of file formula.hpp.
References gui2::tformula< T >::value_.
| void gui2::tformula< t_string >::convert | ( | const std::string & | str | ) | [inline, private] |
Definition at line 216 of file formula.hpp.
References gui2::tformula< T >::value_.
| PangoAlignment gui2::tformula< PangoAlignment >::execute | ( | const game_logic::map_formula_callable & | variables | ) | const [inline, private] |
Definition at line 186 of file formula.hpp.
References gui2::decode_text_alignment(), and gui2::tformula< T >::formula_.

| T gui2::tformula< T >::execute | ( | const game_logic::map_formula_callable & | variables | ) | const [inline, private] |
Executes the formula.
This function does the calculation and can only be called if the object contains a formula.
| variables | The state variables which might be used in the formula. For example a screen_width can be set so the formula can return the half width of the screen. |
Definition at line 194 of file formula.hpp.
Referenced by gui2::tformula< T >::operator()().

| unsigned gui2::tformula< unsigned >::execute | ( | const game_logic::map_formula_callable & | variables | ) | const [inline, private] |
Definition at line 165 of file formula.hpp.
| std::string gui2::tformula< std::string >::execute | ( | const game_logic::map_formula_callable & | variables | ) | const [inline, private] |
Definition at line 172 of file formula.hpp.
References gui2::tformula< T >::formula_.
| bool gui2::tformula< bool >::execute | ( | const game_logic::map_formula_callable & | variables | ) | const [inline, private] |
Definition at line 151 of file formula.hpp.
References gui2::tformula< T >::formula_.
| t_string gui2::tformula< t_string >::execute | ( | const game_logic::map_formula_callable & | variables | ) | const [inline, private] |
Definition at line 179 of file formula.hpp.
References gui2::tformula< T >::formula_.
| int gui2::tformula< int >::execute | ( | const game_logic::map_formula_callable & | variables | ) | const [inline, private] |
Definition at line 158 of file formula.hpp.
References gui2::tformula< T >::formula_.
| bool gui2::tformula< T >::has_formula | ( | ) | const [inline] |
Determine whether the class contains a formula.
Definition at line 79 of file formula.hpp.
Referenced by gui2::tformula< T >::operator()(), gui2::tformula< unsigned >::operator()(), and gui2::twindow_builder::tresolution::tresolution().

| T gui2::tformula< T >::operator() | ( | const game_logic::map_formula_callable & | variables | ) | const [inline] |
Returns the value, can always be used.
Definition at line 136 of file formula.hpp.
References gui2::tformula< T >::execute(), gui2::tformula< T >::formula_, gui2::tformula< T >::has_formula(), LOG_GUI_D, and gui2::tformula< T >::value_.

| T gui2::tformula< T >::operator() | ( | ) | const [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 69 of file formula.hpp.
std::string gui2::tformula< T >::formula_ [private] |
Contains the formuale for the variable.
If the string is empty, there's no formula.
Definition at line 113 of file formula.hpp.
Referenced by gui2::tformula< T >::execute(), gui2::tformula< unsigned >::has_formula(), gui2::tformula< T >::operator()(), and gui2::tformula< T >::tformula().
T gui2::tformula< T >::value_ [private] |
If there's no formula it contains the value.
Definition at line 116 of file formula.hpp.
Referenced by gui2::tformula< T >::convert(), gui2::tformula< T >::operator()(), and gui2::tformula< unsigned >::operator()().
| Generated by doxygen 1.7.1 on Thu May 24 2012 01:21:49 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |