HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_name_node.hpp
1// Copyright Take Vos 2020-2021.
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 hi::inline v1 {
10
12 std::string name;
14
15 formula_name_node(parse_location location, std::string_view name) : formula_node(std::move(location)), name(name) {}
16
18 {
19 function = context.get_function(name);
20 if (!function) {
21 throw parse_error(std::format("{}: Could not find function {}().", location, name));
22 }
23 }
24
25 datum evaluate(formula_evaluation_context &context) const override
26 {
27 hilet &const_context = context;
28
29 try {
30 return const_context.get(name);
31 } catch (std::exception const &e) {
32 throw operation_error(std::format("{}: Can not evaluate function.\n{}", location, e.what()));
33 }
34 }
35
37 {
38 try {
39 return context.get(name);
40 } catch (std::exception const &e) {
41 throw operation_error(std::format("{}: Can not evaluate function.\n{}", location, e.what()));
42 }
43 }
44
45 bool has_evaluate_xvalue() const override
46 {
47 return true;
48 }
49
52 datum const &evaluate_xvalue(formula_evaluation_context const &context) const override
53 {
54 try {
55 return context.get(name);
56 } catch (std::exception const &e) {
57 throw operation_error(std::format("{}: Can not evaluate function.\n{}", location, e.what()));
58 }
59 }
60
61 datum &assign(formula_evaluation_context &context, datum const &rhs) const override
62 {
63 try {
64 return context.set(name, rhs);
65 } catch (std::exception const &e) {
66 throw operation_error(std::format("{}: Can not evaluate function.\n{}", location, e.what()));
67 }
68 }
69
70 datum call(formula_evaluation_context &context, datum::vector_type const &arguments) const override
71 {
72 return function(context, arguments);
73 }
74
75 std::string get_name() const noexcept override
76 {
77 return name;
78 }
79
80 std::string string() const noexcept override
81 {
82 return name;
83 }
84};
85
86} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
A dynamic data type.
Definition datum.hpp:224
Definition formula_evaluation_context.hpp:16
Definition formula_name_node.hpp:11
datum & assign(formula_evaluation_context &context, datum const &rhs) const override
Assign to a non-existing or existing lvalue.
Definition formula_name_node.hpp:61
datum const & evaluate_xvalue(formula_evaluation_context const &context) const override
Evaluate an existing xvalue.
Definition formula_name_node.hpp:52
std::string get_name() const noexcept override
Get the name of a formula_name_node.
Definition formula_name_node.hpp:75
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_name_node.hpp:25
datum & evaluate_lvalue(formula_evaluation_context &context) const override
Evaluate an existing lvalue.
Definition formula_name_node.hpp:36
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:70
void resolve_function_pointer(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_name_node.hpp:17
Definition formula_node.hpp:29
Definition formula_post_process_context.hpp:19
Definition functional.hpp:14
Definition parse_location.hpp:18
T move(T... args)
T what(T... args)