Biorbd Release_1.13.0
Loading...
Searching...
No Matches
BIORBD_NAMESPACE::utils::Equation Class Reference

Strings that are to be interpreted as equation that can be evaluated. More...

#include <Equation.h>

Inheritance diagram for BIORBD_NAMESPACE::utils::Equation:
BIORBD_NAMESPACE::utils::String

Public Member Functions

 Equation ()
 Construct Equation.
 Equation (const char *string)
 Construct Equation.
 Equation (const String &string)
 Construct Equation.
 Equation (const std::basic_string< char > &string)
 Construct Equation.
Public Member Functions inherited from BIORBD_NAMESPACE::utils::String
 String ()
 Construct string.
 String (const char *text)
 Construct string.
 String (const String &text)
 Construct string.
 String (const std::basic_string< char > &text)
 Construct string.
String & operator= (const String &other)
 Allow to use operator=.
String operator+ (size_t val)
 Append an unsigned int to the string.
String operator+ (int val)
 Append an int to the string.
String operator+ (double val)
 Append a double to the string.
String operator+ (const char *text)
 Append a char to the string.
String operator() (size_t idx) const
 Get a specific character in the string.
String operator() (size_t startIdx, size_t lastIdx) const
 Extract a portion of the string.
virtual ~String ()
 Destroy class properly.
String tolower () const
 Return a lower case string.
String toupper () const
 Return an upper case string.

Static Public Member Functions

static std::vector< Equation > splitIntoEquation (Equation wholeEq, const std::map< Equation, double > &variables)
 Split equation into smaller parts, down to number or math symbols.
static double evaluateEquation (std::vector< Equation > wholeEq)
 Evaluate and return an equation.
static double evaluateEquation (Equation wholeEq)
 Evaluate and return an equation.
static double evaluateEquation (Equation wholeEq, const std::map< Equation, double > &variables)
 Evaluate and return an equation.
static void replaceCste (std::vector< Equation > &eq)
 Replace constants in the split equation by a number.
static void replaceVar (Equation &eq, const std::map< Equation, double > &variables)
 Replace the varirables in the equation by their values.
Static Public Member Functions inherited from BIORBD_NAMESPACE::utils::String
static String tolower (const String &str)
 Convert a string to a lower case string.
static String toupper (const String &str)
 Convert a string to a upper case string.
static String to_string (double val)
 Overload of the to_string C++11 function to allow for X-digits precision.
static String to_string (float val)
 Overload of the to_string C++11 function to allow for X-digits precision.
static String removeTrailing (const String &origin, const String &trailTag)
 The trailing tags of a string.

Static Protected Member Functions

static double evaluateEquation (std::vector< Equation > eq, size_t math)
 Resolve the equation.
static std::vector< Equation > prepareMathSymbols ()
 Prepare the mathematical symbols.

Detailed Description

Strings that are to be interpreted as equation that can be evaluated.

Definition at line 17 of file Equation.h.

Constructor & Destructor Documentation

◆ Equation() [1/4]

utils::Equation::Equation ( )

Construct Equation.

Definition at line 28 of file Equation.cpp.

◆ Equation() [2/4]

utils::Equation::Equation ( const char * string)

Construct Equation.

Parameters
stringThe equation in a char format

Definition at line 30 of file Equation.cpp.

◆ Equation() [3/4]

utils::Equation::Equation ( const String & string)

Construct Equation.

Parameters
stringThe equation in a string format

Definition at line 32 of file Equation.cpp.

◆ Equation() [4/4]

utils::Equation::Equation ( const std::basic_string< char > & string)

Construct Equation.

Parameters
stringThe equation in a list of char format

Definition at line 34 of file Equation.cpp.

Member Function Documentation

◆ evaluateEquation() [1/4]

double utils::Equation::evaluateEquation ( utils::Equation wholeEq)
static

Evaluate and return an equation.

Parameters
wholeEqThe whole equation to evaluate
Returns
The evaluated equation

Definition at line 244 of file Equation.cpp.

◆ evaluateEquation() [2/4]

double utils::Equation::evaluateEquation ( utils::Equation wholeEq,
const std::map< Equation, double > & variables )
static

Evaluate and return an equation.

Parameters
wholeEqThe whole equation to evaluate
variablesThe variables in the equation
Returns
The evaluated equation

Definition at line 239 of file Equation.cpp.

◆ evaluateEquation() [3/4]

double utils::Equation::evaluateEquation ( std::vector< Equation > eq,
size_t math )
staticprotected

Resolve the equation.

Parameters
eqThe equation to resolve
mathThe mathematical symbol that is being evaluated now
Returns
The value of the equation

Definition at line 153 of file Equation.cpp.

◆ evaluateEquation() [4/4]

double utils::Equation::evaluateEquation ( std::vector< Equation > wholeEq)
static

Evaluate and return an equation.

Parameters
wholeEqThe already split equation to evaluate
Returns
The evaluated equation

Definition at line 149 of file Equation.cpp.

◆ prepareMathSymbols()

std::vector< utils::Equation > utils::Equation::prepareMathSymbols ( )
staticprotected

Prepare the mathematical symbols.

Returns
The math symbols in an order that respect the order of operation

The supported symbols are:

  • "(" – Open a parenthese
  • ")" – Close a parenthese
  • "e" – value of the format 1e2 (i.e. 1x10^2)
  • "/" – Division
  • "*" – Multiplication
  • "+" – Addition
  • "-" – Subtraction, or negative number if it starts the equation

Definition at line 14 of file Equation.cpp.

◆ replaceCste()

void utils::Equation::replaceCste ( std::vector< Equation > & eq)
static

Replace constants in the split equation by a number.

Parameters
eqThe split equation

The supported constants are:

  • pi – that evaluates to M_PI, that is \(3.14159265358979323846\) on UNIX

Definition at line 130 of file Equation.cpp.

◆ replaceVar()

void utils::Equation::replaceVar ( Equation & eq,
const std::map< Equation, double > & variables )
static

Replace the varirables in the equation by their values.

Parameters
eqThe equation to replace the variables
variablesThe variable set

Definition at line 137 of file Equation.cpp.

◆ splitIntoEquation()

std::vector< utils::Equation > utils::Equation::splitIntoEquation ( Equation wholeEq,
const std::map< Equation, double > & variables )
static

Split equation into smaller parts, down to number or math symbols.

Parameters
wholeEqThe whole equation to split
variablesThe set of variables in the equation
Returns
The split equation

Definition at line 37 of file Equation.cpp.


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