CoriEngine
Loading...
Searching...
No Matches
Cori::Math::Function< NumericType, ArgumentAmount > Class Template Reference

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>

Public Member Functions

 Function ()
 ~Function ()=default
 Function (Function &&other) noexcept=default
Functionoperator= (Function &&other) noexcept=default
 Function (const Function &)=delete
Functionoperator= (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

Detailed Description

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
NumericTypeNumerical type to use for calculation.
ArgumentAmountAmount of arguments of the main expression.

Definition at line 24 of file Function.hpp.

Constructor & Destructor Documentation

◆ Function() [1/3]

template<IsNumber NumericType, uint8_t ArgumentAmount>
Cori::Math::Function< NumericType, ArgumentAmount >::Function ( )
inline

Definition at line 26 of file Function.hpp.

◆ ~Function()

template<IsNumber NumericType, uint8_t ArgumentAmount>
Cori::Math::Function< NumericType, ArgumentAmount >::~Function ( )
default

◆ Function() [2/3]

template<IsNumber NumericType, uint8_t ArgumentAmount>
Cori::Math::Function< NumericType, ArgumentAmount >::Function ( Function< NumericType, ArgumentAmount > && other)
defaultnoexcept
Here is the call graph for this function:

◆ Function() [3/3]

template<IsNumber NumericType, uint8_t ArgumentAmount>
Cori::Math::Function< NumericType, ArgumentAmount >::Function ( const Function< NumericType, ArgumentAmount > & )
delete
Here is the call graph for this function:

Member Function Documentation

◆ 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
aliasNameName to passing to the aliased function.
aliasExpressionExpression 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
aliasAlias to assign to the constant.
valueValue 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
argsValues 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>
Function & Cori::Math::Function< NumericType, ArgumentAmount >::operator= ( const Function< NumericType, ArgumentAmount > & )
delete
Here is the call graph for this function:

◆ operator=() [2/2]

template<IsNumber NumericType, uint8_t ArgumentAmount>
Function & Cori::Math::Function< NumericType, ArgumentAmount >::operator= ( Function< NumericType, ArgumentAmount > && other)
defaultnoexcept
Here is the call graph for this function:

◆ Parse()

template<IsNumber NumericType, uint8_t ArgumentAmount>
void Cori::Math::Function< NumericType, ArgumentAmount >::Parse ( const std::string & expression)
inline

Parses the main mathematical expression. Can use any aliases created with AddAlias.

Parameters
expressionMain 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
argNamesArgument (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>
bool Cori::Math::Function< NumericType, ArgumentAmount >::Success ( ) const
inlinenodiscard

Definition at line 156 of file Function.hpp.


The documentation for this class was generated from the following file: