tcalc 0.2.0
 
Loading...
Searching...
No Matches
tcalc::EvalContext Class Reference

Evaluation context which stores variables and built-in functions. More...

#include <eval.hpp>

Public Member Functions

 EvalContext (std::unordered_map< std::string, double > vars, std::unordered_map< std::string, builtins::Function > funcs, std::size_t call_depth=0)
 Construct a new Eval Context object.
 
TCALC_INLINE auto & vars () noexcept
 Get variables.
 
TCALC_INLINE auto & funcs () noexcept
 Get built-in functions.
 
error::Result< double > var (const std::string &name) const
 Get a variable.
 
TCALC_INLINE void var (const std::string &name, double value) noexcept
 Set a variable.
 
error::Result< builtins::Functionfunc (const std::string &name) const
 Get a built-in function.
 
TCALC_INLINE void func (const std::string &name, builtins::Function func) noexcept
 Set a built-in function.
 
TCALC_INLINE auto call_depth () const noexcept
 Get the call depth.
 
TCALC_INLINE void call_depth (std::size_t depth)
 Set the call depth.
 
TCALC_INLINE void increment_call_depth () noexcept
 Increment the call depth.
 
void update_with (const EvalContext &ctx)
 Update the context with another context.
 

Static Public Attributes

static constexpr std::size_t MAX_CALL_DEPTH = 1000
 

Detailed Description

Evaluation context which stores variables and built-in functions.

Constructor & Destructor Documentation

◆ EvalContext()

tcalc::EvalContext::EvalContext ( std::unordered_map< std::string, double >  vars,
std::unordered_map< std::string, builtins::Function funcs,
std::size_t  call_depth = 0 
)
inline

Construct a new Eval Context object.

Parameters
varsVariables map.
funcsBuilt-in functions map.

Member Function Documentation

◆ call_depth() [1/2]

TCALC_INLINE auto tcalc::EvalContext::call_depth ( ) const
inlinenoexcept

Get the call depth.

Returns
std::size_t Call depth.

◆ call_depth() [2/2]

TCALC_INLINE void tcalc::EvalContext::call_depth ( std::size_t  depth)
inline

Set the call depth.

Parameters
depthCall depth.

◆ func() [1/2]

error::Result< builtins::Function > tcalc::EvalContext::func ( const std::string &  name) const

Get a built-in function.

Parameters
nameFunction name.
Returns
error::Result<BuiltinFunc> Function pointer result.

◆ func() [2/2]

TCALC_INLINE void tcalc::EvalContext::func ( const std::string &  name,
builtins::Function  func 
)
inlinenoexcept

Set a built-in function.

Parameters
nameFunction name.
funcFunction pointer.

◆ funcs()

TCALC_INLINE auto & tcalc::EvalContext::funcs ( )
inlinenoexcept

Get built-in functions.

Returns
std::unordered_map<std::string, BuiltinFunc>& Built-in functions map.

◆ update_with()

void tcalc::EvalContext::update_with ( const EvalContext ctx)

Update the context with another context.

Parameters
ctxOther context.

◆ var() [1/2]

error::Result< double > tcalc::EvalContext::var ( const std::string &  name) const

Get a variable.

Parameters
nameVariable name.
Returns
error::Result<double> Variable value result.

◆ var() [2/2]

TCALC_INLINE void tcalc::EvalContext::var ( const std::string &  name,
double  value 
)
inlinenoexcept

Set a variable.

Parameters
nameVariable name.
valueVariable value.

◆ vars()

TCALC_INLINE auto & tcalc::EvalContext::vars ( )
inlinenoexcept

Get variables.

Returns
std::unordered_map<std::string, double>& Variables map.

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