![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
Evaluates a string as a algebraic formula. More...
#include <formula.h>
Public Member Functions | |
Formula (const std::string &f) | |
Class constructor. More... | |
Formula (const Formula &source) | |
Copy constructor. More... | |
Formula (Formula &&source) | |
Move constructor. More... | |
~Formula () | |
Class destructor. More... | |
Constructors and destructor | |
Formula (short s) | |
Constructor. More... | |
Formula (unsigned short us) | |
Constructor. More... | |
Formula (int i) | |
Constructor. More... | |
Formula (unsigned int ui) | |
Constructor. More... | |
Formula (long l) | |
Constructor. More... | |
Formula (unsigned long ul) | |
Constructor. More... | |
Formula (long long l) | |
Constructor. More... | |
Formula (unsigned long long ul) | |
Constructor. More... | |
Formula (float f) | |
Constructor. More... | |
Formula (double d) | |
Constructor. More... | |
Operators | |
Formula & | operator= (const Formula &source) |
Copy operator. More... | |
Formula & | operator= (Formula &&source) |
Move operator. More... | |
operator double () const | |
Allows implicit conversion to doubles. More... | |
Accessors & modifiers | |
HashTable< std::string, double > & | variables () |
Returns the variables used by this gum::Formula. More... | |
const HashTable< std::string, double > & | variables () const |
Returns the variables used by this gum::Formula. More... | |
double | result () const |
Returns the result of this gum::Formula. More... | |
const std::string & | formula () const |
Returns the formula. More... | |
std::string & | formula () |
Returns the formula. More... | |
Friends | |
class | gum::formula::Parser |
Evaluates a string as a algebraic formula.
Implementation of the Shunting-yard algorithm to convert infix notation to RPN. The gum::Formula::result() method implements the postfix algorithm to compute the formula result.
gum::Formula::Formula | ( | short | s | ) |
Constructor.
Definition at line 187 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | unsigned short | us | ) |
Constructor.
Definition at line 192 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | int | i | ) |
Constructor.
Definition at line 197 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | unsigned int | ui | ) |
Constructor.
Definition at line 202 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | long | l | ) |
Constructor.
Definition at line 207 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | unsigned long | ul | ) |
Constructor.
Definition at line 212 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | long long | l | ) |
Constructor.
Definition at line 217 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | unsigned long long | ul | ) |
Constructor.
Definition at line 222 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | float | f | ) |
Constructor.
Definition at line 228 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | double | d | ) |
Constructor.
Definition at line 233 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | const std::string & | f | ) |
Class constructor.
f | An algebraic formula. |
Definition at line 238 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | const Formula & | source | ) |
Copy constructor.
source | The gum::Formula to copy. |
Definition at line 244 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::Formula | ( | Formula && | source | ) |
Move constructor.
source | The gum::Formula to move. |
Definition at line 252 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
gum::Formula::~Formula | ( | ) |
Class destructor.
Definition at line 261 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
|
private |
Finalize the formula and prepare it for evaluation.
Definition at line 340 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Initialise the formula scanner and parser.
Definition at line 177 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
|
private |
Returns true if o is an unary operator.
Definition at line 275 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Pop the operator in the inner formula's stack.
o | The operator to pop. |
Definition at line 251 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push a comma in the formula.
Definition at line 404 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push a function in the formula.
func | The function to push. |
Definition at line 377 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Use this if you don't know if ident is a function or a variable.
Definition at line 434 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push a left parenthesis in the formula.
Definition at line 311 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push a number in the formula.
v | The number to push. |
Definition at line 245 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push an operator in the formula.
o | The operator to push. |
Definition at line 264 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push an operator.
t | The operator to push. |
Definition at line 301 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push the gum::FormulaPart in the output vector.
t | The gum::FormulaPart to push. |
Definition at line 365 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push a right parenthesis in the formula.
Definition at line 317 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push the gum::FormulaPart in the stack.
t | The gum::FormulaPart to push. |
Definition at line 371 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push an unary operator.
o | The unary operator to push. |
Definition at line 294 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Push a variable in the formula.
Definition at line 424 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
Evaluate an operator or function and push its result.
item | The operator or function to reduce. |
stack | The stack to evaluate. |
Definition at line 350 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE const std::string & gum::Formula::formula | ( | ) | const |
Returns the formula.
Definition at line 239 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE std::string & gum::Formula::formula | ( | ) |
Returns the formula.
Definition at line 242 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
inlineexplicit |
Allows implicit conversion to doubles.
Definition at line 360 of file formula.h.
Copy operator.
source | The gum::Formula to copy. |
Definition at line 266 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
Move operator.
source | The gum::Formula to move. |
Definition at line 279 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
double gum::Formula::result | ( | ) | const |
Returns the result of this gum::Formula.
Each call to Formula::result() will reevaluate the formulas result.
Definition at line 293 of file formula.cpp.
References gum::Set< Key, Alloc >::emplace().
Returns the variables used by this gum::Formula.
Definition at line 418 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
Returns the variables used by this gum::Formula.
Definition at line 421 of file formula_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |