![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
Represents part of a formula. More...
#include <agrum/base/core/math/formula.h>
Public Types | |
| enum | token_type { NUMBER , OPERATOR , PARENTHESIS , NIL , FUNCTION , ARG_SEP } |
| The tokens constituting a formula. More... | |
| enum | token_function { exp , log , ln , pow , sqrt , nil } |
| The functions allowed in a formula. More... | |
Public Member Functions | |
Constructors and destructor | |
| FormulaPart () | |
| Class constructor. | |
| FormulaPart (token_type t, double n) | |
| Constructor for doubles. | |
| FormulaPart (token_type t, char c) | |
| Constructor for chars. | |
| FormulaPart (token_type t, token_function func) | |
| Constructor for functions. | |
| FormulaPart (const FormulaPart &source) | |
| Copy constructor. | |
| FormulaPart (FormulaPart &&source) | |
| Move constructor. | |
| ~FormulaPart () | |
| Class destuctor. | |
source The gum::FormulaPart to copy. | |
Move operator.
| |
| FormulaPart & | operator= (const FormulaPart &source) |
| FormulaPart & | operator= (FormulaPart &&source) |
Getters and setters | |
| std::string | str () const |
| Returns a string representation of this gum::FormulaPart value. | |
| bool | isLeftAssociative () const |
| Returns true if this gum::FormulaPart is left associative. | |
| bool | isRightAssociative () const |
| Returns true if this gum::FormulaPart is right associative. | |
| int | precedence () const |
| Returns the precedence priority of the value stored in this gum::FormulaPart. | |
| size_t | argc () const |
| Returns the number of argument of the function stored in this gum::FormulaPart. | |
| FormulaPart | eval (const std::vector< FormulaPart > &args) const |
| Returns the evaluation of the vector of gum::FormulaPart as arguments of the value stored in this gum::FormulaPart. | |
Public Attributes | |
| token_type | type |
| The token_type stored by this gum::FormulaPart. | |
| double | number |
| The value stored by this gum::FormulaPart. | |
| char | character |
| The value stored by this gum::FormulaPart. | |
| token_function | function |
| The value stored by this gum::FormulaPart. | |
Private Member Functions | |
| double | _operator_eval_ (const std::vector< FormulaPart > &args) const |
| Returns the evaluation of the vector of gum::FormulaPart as arguments of the value stored in this gum::FormulaPart. | |
| double | _function_eval_ (const std::vector< FormulaPart > &args) const |
| Returns the evaluation of the vector of gum::FormulaPart as arguments of the value stored in this gum::FormulaPart. | |
| size_t | _operator_argc_ () const |
| Returns the number of arguments expected by the operator stored in this gum::FormulaPart. | |
| size_t | _function_argc_ () const |
| Returns the number of arguments expected by the function stored in this gum::FormulaPart. | |
Represents part of a formula.
This class is used by the gum::Formula class to store intermediate results when solving the formula using the Shuntin-yard algorithm.
| gum::FormulaPart::FormulaPart | ( | ) |
Class constructor.
Definition at line 105 of file formula.cpp.
References FormulaPart(), character, function, NIL, nil, number, and type.
Referenced by FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), ~FormulaPart(), eval(), operator=(), and operator=().
| gum::FormulaPart::FormulaPart | ( | token_type | t, |
| double | n ) |
Constructor for doubles.
| t | The token_type of this gum::FormulaPart. |
| n | The value of this gum::FormulaPart. |
Definition at line 109 of file formula.cpp.
References FormulaPart(), character, function, nil, number, and type.
| gum::FormulaPart::FormulaPart | ( | token_type | t, |
| char | c ) |
Constructor for chars.
| t | The token_type of this gum::FormulaPart. |
| c | The value of this gum::FormulaPart. |
Definition at line 114 of file formula.cpp.
References FormulaPart(), character, function, nil, number, and type.
| gum::FormulaPart::FormulaPart | ( | token_type | t, |
| token_function | func ) |
Constructor for functions.
| t | The token_type of this gum::FormulaPart. |
| func | The value of this gum::FormulaPart. |
Definition at line 119 of file formula.cpp.
References FormulaPart(), character, function, number, and type.
| gum::FormulaPart::FormulaPart | ( | const FormulaPart & | source | ) |
Copy constructor.
| source | The gum::FormulaPart to copy. |
Definition at line 124 of file formula.cpp.
References FormulaPart(), character, function, number, and type.
| gum::FormulaPart::FormulaPart | ( | FormulaPart && | source | ) |
Move constructor.
| source | The gum::FormulaPart to move. |
Definition at line 130 of file formula.cpp.
References FormulaPart(), character, function, number, and type.
| gum::FormulaPart::~FormulaPart | ( | ) |
Class destuctor.
Definition at line 136 of file formula.cpp.
References FormulaPart().
|
private |
Returns the number of arguments expected by the function stored in this gum::FormulaPart.
Definition at line 152 of file formula_inl.h.
References exp, function, GUM_ERROR, ln, log, pow, and sqrt.
Referenced by argc().
|
private |
Returns the evaluation of the vector of gum::FormulaPart as arguments of the value stored in this gum::FormulaPart.
Args are backwards !
| args | The arguments, in backards, passed to the value stored in this gum::FormulaPart. |
| OperationNotAllowed | Raised if the value stored is not a function. |
Definition at line 212 of file formula_inl.h.
References exp, function, GUM_ERROR, ln, log, number, pow, and sqrt.
Referenced by eval().
|
private |
Returns the number of arguments expected by the operator stored in this gum::FormulaPart.
Definition at line 132 of file formula_inl.h.
References character, and GUM_ERROR.
Referenced by argc().
|
private |
Returns the evaluation of the vector of gum::FormulaPart as arguments of the value stored in this gum::FormulaPart.
Args are backwards !
| args | The arguments, in backards, passed to the value stored in this gum::FormulaPart. |
| OperationNotAllowed | Raised if the value stored is not an operator. |
Definition at line 178 of file formula_inl.h.
References character, GUM_ERROR, and number.
Referenced by eval().
| INLINE size_t gum::FormulaPart::argc | ( | ) | const |
Returns the number of argument of the function stored in this gum::FormulaPart.
| OperationNotAllowed | Raised if the value stored is not a function. |
Definition at line 115 of file formula_inl.h.
References _function_argc_(), _operator_argc_(), FUNCTION, GUM_ERROR, OPERATOR, and type.
Referenced by gum::Formula::_reduceOperatorOrFunction_().
| INLINE FormulaPart gum::FormulaPart::eval | ( | const std::vector< FormulaPart > & | args | ) | const |
Returns the evaluation of the vector of gum::FormulaPart as arguments of the value stored in this gum::FormulaPart.
Args are backwards !
| args | The arguments, in backards, passed to the value stored in this gum::FormulaPart. |
| OperationNotAllowed | Raised if the value stored is neither a function nor an operator. |
Definition at line 238 of file formula_inl.h.
References FormulaPart(), _function_eval_(), _operator_eval_(), FUNCTION, GUM_ERROR, NUMBER, OPERATOR, and type.
Referenced by gum::Formula::_reduceOperatorOrFunction_().
| INLINE bool gum::FormulaPart::isLeftAssociative | ( | ) | const |
Returns true if this gum::FormulaPart is left associative.
| OperationNotAllowed | Raised if the value stored is not an operator. |
Definition at line 53 of file formula_inl.h.
References character, and GUM_ERROR.
Referenced by gum::Formula::_popOperator_(), and isRightAssociative().
| INLINE bool gum::FormulaPart::isRightAssociative | ( | ) | const |
Returns true if this gum::FormulaPart is right associative.
| OperationNotAllowed | Raised if the value stored is not an operator. |
Definition at line 76 of file formula_inl.h.
References character, and isLeftAssociative().
Referenced by gum::Formula::_popOperator_().
| FormulaPart & gum::FormulaPart::operator= | ( | const FormulaPart & | source | ) |
Definition at line 141 of file formula.cpp.
References FormulaPart(), character, function, number, and type.
| FormulaPart & gum::FormulaPart::operator= | ( | FormulaPart && | source | ) |
Definition at line 152 of file formula.cpp.
References FormulaPart(), character, function, number, and type.
| INLINE int gum::FormulaPart::precedence | ( | ) | const |
Returns the precedence priority of the value stored in this gum::FormulaPart.
| OperationNotAllowed | Raised if the value stored is not an operator. |
Definition at line 88 of file formula_inl.h.
References character, and GUM_ERROR.
Referenced by gum::Formula::_popOperator_().
| std::string gum::FormulaPart::str | ( | ) | const |
Returns a string representation of this gum::FormulaPart value.
Definition at line 163 of file formula.cpp.
References character, gum::func2str(), FUNCTION, function, GUM_ERROR, NUMBER, number, OPERATOR, PARENTHESIS, and type.
| char gum::FormulaPart::character |
The value stored by this gum::FormulaPart.
Definition at line 98 of file formula.h.
Referenced by FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), _operator_argc_(), _operator_eval_(), isLeftAssociative(), isRightAssociative(), operator=(), operator=(), precedence(), and str().
| token_function gum::FormulaPart::function |
The value stored by this gum::FormulaPart.
Definition at line 99 of file formula.h.
Referenced by FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), _function_argc_(), _function_eval_(), operator=(), operator=(), and str().
| double gum::FormulaPart::number |
The value stored by this gum::FormulaPart.
Definition at line 97 of file formula.h.
Referenced by FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), _function_eval_(), _operator_eval_(), operator=(), operator=(), and str().
| token_type gum::FormulaPart::type |
The token_type stored by this gum::FormulaPart.
Definition at line 88 of file formula.h.
Referenced by FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), FormulaPart(), argc(), eval(), operator=(), operator=(), and str().