NDEVR
API Documentation
Equation< t_type >

A solvable mathematical formula composed of variables, numbers, and operations. More...

Collaboration diagram for Equation< t_type >:
[legend]

Classes

struct  EquationPart
 Represents a single element in the equation stack, consisting of an operator and a value. More...

Public Member Functions

 Equation ()
 Default constructor.
void add (char operation, const String &value)
 Appends a variable-referencing equation part to the equation stack.
void add (char operation, t_type value)
 Appends a numeric equation part to the equation stack.
void addOrderOfOps (char operation, t_type value)
 Adds an equation part at a position determined by order-of-operations priority.
void refreshVariables ()
 Refreshes all variable locations in the equation stack using the currently stored variable values.
void setVariable (const StringView &var, t_type value)
 Sets the value of a named variable and updates all locations in the equation stack that reference it.
t_type solve () const
 Solves the entire equation by evaluating the equation stack from the beginning.
t_type solve (t_type start, uint04 &current_index) const
 Recursively solves the equation stack starting from the given index, accumulating onto a starting value.

Static Public Member Functions

static uint04 getOrderPriority (const char op)
 Returns the order-of-operations priority for the given operator.
static t_type solve (t_type left, const char op, t_type right)
 Solves a single binary or unary operation given a left operand, operator, and right operand.

Public Attributes

Buffer< EquationPartm_equation_stack
 The ordered stack of equation parts representing the formula.
Dictionary< String, Buffer< uint04 > > m_variable_locations
 Maps variable names to their indices within the equation stack.
Dictionary< String, t_type > m_variables
 Maps variable names to their current numeric values.

Detailed Description

template<class t_type>
class Equation< t_type >

A solvable mathematical formula composed of variables, numbers, and operations.


See also
StatementParser, Formula

Definition at line 44 of file Equation.h.

Constructor & Destructor Documentation

◆ Equation()

template<class t_type>
Equation< t_type >::Equation ( )
inline

Default constructor.

Creates an empty equation with no parts or variables.

Definition at line 50 of file Equation.h.

Member Function Documentation

◆ add() [1/2]

template<class t_type>
void Equation< t_type >::add ( char operation,
const String & value )
inline

Appends a variable-referencing equation part to the equation stack.

Parameters
[in]operationThe operator character for this part.
[in]valueThe name of the variable referenced by this part.

Definition at line 177 of file Equation.h.

References m_equation_stack, m_variable_locations, Equation< t_type >::EquationPart::operation, and Equation< t_type >::EquationPart::value.

◆ add() [2/2]

template<class t_type>
void Equation< t_type >::add ( char operation,
t_type value )
inline

Appends a numeric equation part to the equation stack.

Parameters
[in]operationThe operator character for this part.
[in]valueThe numeric value for this part.

Definition at line 130 of file Equation.h.

References m_equation_stack, Equation< t_type >::EquationPart::operation, and Equation< t_type >::EquationPart::value.

◆ addOrderOfOps()

template<class t_type>
void Equation< t_type >::addOrderOfOps ( char operation,
t_type value )
inline

Adds an equation part at a position determined by order-of-operations priority.

Parameters
[in]operationThe operator character for this part.
[in]valueThe numeric value for this part.

Definition at line 164 of file Equation.h.

References m_equation_stack, Equation< t_type >::EquationPart::operation, and Equation< t_type >::EquationPart::value.

◆ getOrderPriority()

template<class t_type>
uint04 Equation< t_type >::getOrderPriority ( const char op)
inlinestatic

Returns the order-of-operations priority for the given operator.

Parameters
[in]opThe operator character.
Returns
A priority value where higher numbers indicate higher precedence, or Invalid for unrecognized operators.

Definition at line 142 of file Equation.h.

◆ setVariable()

template<class t_type>
void Equation< t_type >::setVariable ( const StringView & var,
t_type value )
inline

Sets the value of a named variable and updates all locations in the equation stack that reference it.

Parameters
[in]varThe name of the variable to set.
[in]valueThe numeric value to assign to the variable.

Definition at line 65 of file Equation.h.

References m_equation_stack, m_variable_locations, and m_variables.

◆ solve() [1/3]

template<class t_type>
t_type Equation< t_type >::solve ( ) const
inline

Solves the entire equation by evaluating the equation stack from the beginning.

Returns
The computed result, or Invalid if the equation is malformed or contains unresolved variables.

Definition at line 116 of file Equation.h.

References cast(), m_equation_stack, and solve().

Referenced by solve(), and solve().

◆ solve() [2/3]

template<class t_type>
t_type Equation< t_type >::solve ( t_type left,
const char op,
t_type right )
inlinestatic

Solves a single binary or unary operation given a left operand, operator, and right operand.

Parameters
[in]leftThe left-hand operand.
[in]opThe operator character.
[in]rightThe right-hand operand.
Returns
The result of applying the operator, or Invalid if the operator is unrecognized.

Definition at line 94 of file Equation.h.

◆ solve() [3/3]

template<class t_type>
t_type Equation< t_type >::solve ( t_type start,
uint04 & current_index ) const
inline

Recursively solves the equation stack starting from the given index, accumulating onto a starting value.

Parameters
[in]startThe initial accumulated value to build upon.
[in]current_indexThe current position in the equation stack; advanced as parts are consumed.
Returns
The computed result for this sub-expression, or Invalid on error.

Definition at line 193 of file Equation.h.

References cast(), cos(), IsInvalid(), m_equation_stack, sin(), solve(), sqrt(), and tan().


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