Public Member Functions | Private Member Functions | Private Attributes

gui2::tformula< T > Class Template Reference

Template class can hold a value or a formula to calculate the value. More...

#include <formula.hpp>

Collaboration diagram for gui2::tformula< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 tformula (const std::string &str, const T value=T())
 Constructor.
operator() () const
 Returns the value, can only be used if the data is no formula.
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.
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.
value_
 If there's no formula it contains the value.

Detailed Description

template<class T>
class gui2::tformula< T >

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.

Template Parameters:
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.


Constructor & Destructor Documentation

template<class T>
gui2::tformula< T >::tformula ( const std::string &  str,
const T  value = T() 
) [explicit]

Constructor.

Parameters:
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_.

Here is the call graph for this function:


Member Function Documentation

template<class T >
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.

Parameters:
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().

Here is the caller graph for this function:

template<>
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_.

Here is the call graph for this function:

template<>
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_.

Here is the call graph for this function:

template<>
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_.

template<>
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_.

template<>
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_.

Here is the call graph for this function:

template<class T >
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.

Parameters:
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.
Returns:
The calculated value.

Definition at line 194 of file formula.hpp.

Referenced by gui2::tformula< T >::operator()().

Here is the caller graph for this function:

template<>
unsigned gui2::tformula< unsigned >::execute ( const game_logic::map_formula_callable variables  )  const [inline, private]

Definition at line 165 of file formula.hpp.

template<>
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_.

template<>
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_.

template<>
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_.

template<>
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_.

template<class T>
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().

Here is the caller graph for this function:

template<class T >
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_.

Here is the call graph for this function:

template<class T>
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.


Member Data Documentation

template<class T>
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().

template<class T>
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()().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:21:49 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs