![]() |
aGrUM
0.16.0
|
Represents part of a formula. More...
#include <agrum/core/math/formula.h>
Public Attributes | |
token_type | type |
The token_type stored by this gum::FormulaPart. More... | |
double | number |
The value stored by this gum::FormulaPart. More... | |
char | character |
The value stored by this gum::FormulaPart. More... | |
token_function | function |
The value stored by this gum::FormulaPart. More... | |
Public Member Functions | |
Constructors and destructor | |
FormulaPart () | |
Class constructor. More... | |
FormulaPart (token_type t, double n) | |
Constructor for doubles. More... | |
FormulaPart (token_type t, char c) | |
Constructor for chars. More... | |
FormulaPart (token_type t, token_function func) | |
Constructor for functions. More... | |
FormulaPart (const FormulaPart &source) | |
Copy constructor. More... | |
FormulaPart (FormulaPart &&source) | |
Move constructor. More... | |
~FormulaPart () | |
Class destuctor. More... | |
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. More... | |
bool | isLeftAssociative () const |
Returns true if this gum::FormulaPart is left associative. More... | |
bool | isRightAssociative () const |
Returns true if this gum::FormulaPart is right associative. More... | |
int | precedence () const |
Returns the precedence priority of the value stored in this gum::FormulaPart. More... | |
size_t | argc () const |
Returns the number of argument of the function stored in this gum::FormulaPart. More... | |
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. More... | |
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... | |
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.
The functions allowed in a formula.
Enumerator | |
---|---|
exp | |
log | |
ln | |
pow | |
sqrt | |
nil |
Definition at line 66 of file formula.h.
The tokens constituting a formula.
Enumerator | |
---|---|
NUMBER | |
OPERATOR | |
PARENTHESIS | |
NIL | |
FUNCTION | |
ARG_SEP |
Definition at line 63 of file formula.h.
gum::FormulaPart::FormulaPart | ( | ) |
Class constructor.
Definition at line 86 of file formula.cpp.
Referenced by gum::Formula::__push_comma(), gum::Formula::__push_rightParenthesis(), and eval().
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 91 of file formula.cpp.
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 96 of file formula.cpp.
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 101 of file formula.cpp.
gum::FormulaPart::FormulaPart | ( | const FormulaPart & | source | ) |
Copy constructor.
source | The gum::FormulaPart to copy. |
Definition at line 106 of file formula.cpp.
gum::FormulaPart::FormulaPart | ( | FormulaPart && | source | ) |
Move constructor.
source | The gum::FormulaPart to move. |
Definition at line 112 of file formula.cpp.
gum::FormulaPart::~FormulaPart | ( | ) |
|
private |
Returns the number of arguments expected by the function stored in this gum::FormulaPart.
Definition at line 132 of file formula_inl.h.
References 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 a function. |
Definition at line 194 of file formula_inl.h.
References GUM_ERROR, and number.
Referenced by eval().
|
private |
Returns the number of arguments expected by the operator stored in this gum::FormulaPart.
Definition at line 112 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 159 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 95 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 220 of file formula_inl.h.
References __function_eval(), __operator_eval(), FormulaPart(), FUNCTION, GUM_ERROR, 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 33 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 56 of file formula_inl.h.
References character, and isLeftAssociative().
Referenced by gum::Formula::__popOperator().
FormulaPart & gum::FormulaPart::operator= | ( | const FormulaPart & | source | ) |
Definition at line 121 of file formula.cpp.
References character, function, number, and type.
FormulaPart & gum::FormulaPart::operator= | ( | FormulaPart && | source | ) |
Definition at line 132 of file formula.cpp.
References character, 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 68 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 143 of file formula.cpp.
References character, gum::func2str(), GUM_ERROR, number, and type.
char gum::FormulaPart::character |
The value stored by this gum::FormulaPart.
Definition at line 79 of file formula.h.
Referenced by __operator_argc(), __operator_eval(), isLeftAssociative(), isRightAssociative(), operator=(), precedence(), and str().
token_function gum::FormulaPart::function |
The value stored by this gum::FormulaPart.
Definition at line 80 of file formula.h.
Referenced by operator=().
double gum::FormulaPart::number |
The value stored by this gum::FormulaPart.
Definition at line 78 of file formula.h.
Referenced by __function_eval(), __operator_eval(), operator=(), and str().
token_type gum::FormulaPart::type |
The token_type stored by this gum::FormulaPart.
Definition at line 69 of file formula.h.
Referenced by argc(), eval(), operator=(), and str().