34 constexpr static std::size_t MAX_CALL_DEPTH = 1000;
37 std::unordered_map<std::string, double> _vars;
38 std::unordered_map<std::string, builtins::Function> _funcs;
40 std::size_t _call_depth{ 0 };
50 std::unordered_map<std::string, builtins::Function> funcs,
51 std::size_t call_depth = 0)
52 : _vars{ std::move(vars) }
53 , _funcs{ std::move(funcs) }
54 , _call_depth{ call_depth }
66 [[nodiscard]] TCALC_INLINE
auto&
vars() noexcept {
return _vars; }
74 [[nodiscard]] TCALC_INLINE
auto&
funcs() noexcept {
return _funcs; }
90 TCALC_INLINE
void var(
const std::string& name,
double value)
noexcept
109 TCALC_INLINE
void func(
const std::string& name,
112 _funcs[name] = std::move(func);
130 TCALC_INLINE
void call_depth(std::size_t depth) { _call_depth = depth; }
Evaluation context which stores variables and built-in functions.
Definition eval.hpp:32
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.
Definition eval.hpp:49
TCALC_INLINE auto & funcs() noexcept
Get built-in functions.
Definition eval.hpp:74
TCALC_INLINE void increment_call_depth() noexcept
Increment the call depth.
Definition eval.hpp:136
TCALC_INLINE void var(const std::string &name, double value) noexcept
Set a variable.
Definition eval.hpp:90
TCALC_INLINE auto call_depth() const noexcept
Get the call depth.
Definition eval.hpp:120
TCALC_INLINE void call_depth(std::size_t depth)
Set the call depth.
Definition eval.hpp:130
TCALC_INLINE void func(const std::string &name, builtins::Function func) noexcept
Set a built-in function.
Definition eval.hpp:109
TCALC_INLINE auto & vars() noexcept
Get variables.
Definition eval.hpp:66