Mathematical function/expression. @detials Uses ExprTK internally, refer here https://github.com/ArashPartow/exprtk to see what it can parse.
By default, have some contents defined:
PI, alias: "pi"
Epsilon, alias: "epsilon"
Infinity, alias: "inf"
Euler's number, alias: "e".
More...
#include <Function.hpp>
|
| | Function () |
| | ~Function ()=default |
| | Function (Function &&other) noexcept=default |
| Function & | operator= (Function &&other) noexcept=default |
| | Function (const Function &)=delete |
| Function & | operator= (const Function &)=delete |
| void | RegisterValues (const std::vector< std::string > &argNames) |
| | Registers the names of the arguments for the function. This must be called before AddAlias or Parse.
|
| bool | AddConstant (const std::string &alias, const NumericType value) |
| | Ads a constant to the registered values.
|
| void | AddAlias (const std::string &aliasName, const std::string &aliasExpression) |
| | Creates a parameterized alias (a composited function). The alias will accept the same parameters as registered by RegisterValues.
|
| void | Parse (const std::string &expression) |
| | Parses the main mathematical expression. Can use any aliases created with AddAlias.
|
| NumericType | operator() (const IsNumber auto &... args) |
| | Makes function object a callable. Calculates the main expression result based on the passed values. @detials The values of args are assigned to the registered values in the same order they were registered in. The amount of arguments expected is ArgumentAmount.
Example:
We have an expression: a*b*c
We registered the values like this: RegisterValues({ "a", "b", "c" });
So when we call the function like this: ExampleFunction(1, 5, 10)
The expression becomes: 1 * 5 * 10
And 50 is returned.
|
| bool | Success () const |
template<IsNumber NumericType, uint8_t ArgumentAmount>
class Cori::Math::Function< NumericType, ArgumentAmount >
Mathematical function/expression. @detials Uses ExprTK internally, refer here https://github.com/ArashPartow/exprtk to see what it can parse.
By default, have some contents defined:
PI, alias: "pi"
Epsilon, alias: "epsilon"
Infinity, alias: "inf"
Euler's number, alias: "e".
- Template Parameters
-
| NumericType | Numerical type to use for calculation. |
| ArgumentAmount | Amount of arguments of the main expression. |
Definition at line 24 of file Function.hpp.
◆ Function() [1/3]
template<IsNumber NumericType, uint8_t ArgumentAmount>
◆ ~Function()
template<IsNumber NumericType, uint8_t ArgumentAmount>
◆ Function() [2/3]
template<IsNumber NumericType, uint8_t ArgumentAmount>
◆ Function() [3/3]
template<IsNumber NumericType, uint8_t ArgumentAmount>
◆ AddAlias()
template<IsNumber NumericType, uint8_t ArgumentAmount>
| void Cori::Math::Function< NumericType, ArgumentAmount >::AddAlias |
( |
const std::string & | aliasName, |
|
|
const std::string & | aliasExpression ) |
|
inline |
Creates a parameterized alias (a composited function). The alias will accept the same parameters as registered by RegisterValues.
- Parameters
-
| aliasName | Name to passing to the aliased function. |
| aliasExpression | Expression to parse and assign to the aliased function. |
Definition at line 77 of file Function.hpp.
◆ AddConstant()
template<IsNumber NumericType, uint8_t ArgumentAmount>
| bool Cori::Math::Function< NumericType, ArgumentAmount >::AddConstant |
( |
const std::string & | alias, |
|
|
const NumericType | value ) |
|
inline |
Ads a constant to the registered values.
- Parameters
-
| alias | Alias to assign to the constant. |
| value | Value to assign to the constant. |
- Returns
- True if constant was added, false on failure.
Definition at line 68 of file Function.hpp.
◆ operator()()
template<IsNumber NumericType, uint8_t ArgumentAmount>
| NumericType Cori::Math::Function< NumericType, ArgumentAmount >::operator() |
( |
const IsNumber auto &... | args | ) |
|
|
inline |
Makes function object a callable. Calculates the main expression result based on the passed values. @detials The values of args are assigned to the registered values in the same order they were registered in. The amount of arguments expected is ArgumentAmount.
Example:
We have an expression: a*b*c
We registered the values like this: RegisterValues({ "a", "b", "c" });
So when we call the function like this: ExampleFunction(1, 5, 10)
The expression becomes: 1 * 5 * 10
And 50 is returned.
- Parameters
-
| args | Values to assign to registered values. |
- Returns
- Expression result.
Definition at line 130 of file Function.hpp.
◆ operator=() [1/2]
template<IsNumber NumericType, uint8_t ArgumentAmount>
◆ operator=() [2/2]
template<IsNumber NumericType, uint8_t ArgumentAmount>
◆ Parse()
template<IsNumber NumericType, uint8_t ArgumentAmount>
Parses the main mathematical expression. Can use any aliases created with AddAlias.
- Parameters
-
| expression | Main expression to parse. |
Definition at line 100 of file Function.hpp.
◆ RegisterValues()
template<IsNumber NumericType, uint8_t ArgumentAmount>
| void Cori::Math::Function< NumericType, ArgumentAmount >::RegisterValues |
( |
const std::vector< std::string > & | argNames | ) |
|
|
inline |
Registers the names of the arguments for the function. This must be called before AddAlias or Parse.
- Parameters
-
| argNames | Argument (value) names to register. |
- Note
- You can't register types in multiple calls, you must register all of them at once.
Definition at line 46 of file Function.hpp.
◆ Success()
template<IsNumber NumericType, uint8_t ArgumentAmount>
The documentation for this class was generated from the following file: