HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_name_node.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "formula_node.hpp"
8
9namespace tt {
10
12 std::string name;
14
15 formula_name_node(parse_location location, std::string_view name) :
16 formula_node(std::move(location)), name(name) {}
17
19 function = context.get_function(name);
20 if (!function) {
21 throw parse_error("{}: Could not find function {}().", location, name);
22 }
23 }
24
25 datum evaluate(formula_evaluation_context& context) const override {
26 ttlet &const_context = context;
27
28 try {
29 return const_context.get(name);
30 } catch (std::exception const &e) {
31 throw operation_error("{}: Can not evaluate function.\n{}", location, e.what());
32 }
33 }
34
36 try {
37 return context.get(name);
38 } catch (std::exception const &e) {
39 throw operation_error("{}: Can not evaluate function.\n{}", location, e.what());
40 }
41 }
42
43 bool has_evaluate_xvalue() const override {
44 return true;
45 }
46
49 datum const &evaluate_xvalue(formula_evaluation_context const& context) const override {
50 try {
51 return context.get(name);
52 } catch (std::exception const &e) {
53 throw operation_error("{}: Can not evaluate function.\n{}", location, e.what());
54 }
55 }
56
57 datum &assign(formula_evaluation_context& context, datum const &rhs) const override {
58 try {
59 return context.set(name, rhs);
60 } catch (std::exception const &e) {
61 throw operation_error("{}: Can not evaluate function.\n{}", location, e.what());
62 }
63 }
64
65 datum call(formula_evaluation_context& context, datum::vector_type const &arguments) const override {
66 return function(context, arguments);
67 }
68
69 std::string get_name() const noexcept override {
70 return name;
71 }
72
73 std::string string() const noexcept override {
74 return name;
75 }
76};
77
78}
A dynamic data type.
Definition datum.hpp:213
Exception thrown during parsing on an error.
Definition exception.hpp:26
Exception thrown during execution of a dynamic operation.
Definition exception.hpp:42
Definition formula_evaluation_context.hpp:16
Definition formula_name_node.hpp:11
void resolve_function_pointer(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_name_node.hpp:18
datum const & evaluate_xvalue(formula_evaluation_context const &context) const override
Evaluate an existing xvalue.
Definition formula_name_node.hpp:49
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_name_node.hpp:25
datum & assign(formula_evaluation_context &context, datum const &rhs) const override
Assign to a non-existing or existing lvalue.
Definition formula_name_node.hpp:57
std::string get_name() const noexcept override
Get the name of a formula_name_node.
Definition formula_name_node.hpp:69
datum call(formula_evaluation_context &context, datum::vector_type const &arguments) const override
Call a function with a datum::vector as arguments.
Definition formula_name_node.hpp:65
datum & evaluate_lvalue(formula_evaluation_context &context) const override
Evaluate an existing lvalue.
Definition formula_name_node.hpp:35
Definition formula_node.hpp:19
Definition formula_post_process_context.hpp:19
Definition parse_location.hpp:17
T move(T... args)
T what(T... args)