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#include "../macros.hpp"
9
10hi_export_module(hikogui.formula.formula_name_node);
11
12namespace hi { inline namespace v1 {
13
15 std::string name;
16 mutable formula_post_process_context::function_type function;
17
18 formula_name_node(size_t line_nr, size_t column_nr, std::string_view name) : formula_node(line_nr, column_nr), name(name) {}
19
21 {
22 function = context.get_function(name);
23 if (!function) {
24 throw parse_error(std::format("{}:{}: Could not find function {}().", line_nr, column_nr, name));
25 }
26 }
27
29 {
30 hilet &const_context = context;
31
32 try {
33 return const_context.get(name);
34 } catch (std::exception const &e) {
35 throw operation_error(std::format("{}:{}: Can not evaluate function.\n{}", line_nr, column_nr, e.what()));
36 }
37 }
38
40 {
41 try {
42 return context.get(name);
43 } catch (std::exception const &e) {
44 throw operation_error(std::format("{}:{}: Can not evaluate function.\n{}", line_nr, column_nr, e.what()));
45 }
46 }
47
48 bool has_evaluate_xvalue() const override
49 {
50 return true;
51 }
52
56 {
57 try {
58 return context.get(name);
59 } catch (std::exception const &e) {
60 throw operation_error(std::format("{}:{}: Can not evaluate function.\n{}", line_nr, column_nr, e.what()));
61 }
62 }
63
64 datum &assign(formula_evaluation_context &context, datum const &rhs) const override
65 {
66 try {
67 return context.set(name, rhs);
68 } catch (std::exception const &e) {
69 throw operation_error(std::format("{}:{}: Can not evaluate function.\n{}", line_nr, column_nr, e.what()));
70 }
71 }
72
74 {
75 return function(context, arguments);
76 }
77
79 {
80 return name;
81 }
82
83 std::string string() const noexcept override
84 {
85 return name;
86 }
87};
88
89}} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A dynamic data type.
Definition datum.hpp:212
friend constexpr T const & get(datum const &rhs) noexcept
Get the value of a datum.
Definition datum.hpp:1752
Definition formula_evaluation_context.hpp:18
Definition formula_name_node.hpp:14
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_name_node.hpp:28
datum & assign(formula_evaluation_context &context, datum const &rhs) const override
Assign to a non-existing or existing lvalue.
Definition formula_name_node.hpp:64
datum & evaluate_lvalue(formula_evaluation_context &context) const override
Evaluate an existing lvalue.
Definition formula_name_node.hpp:39
datum const & evaluate_xvalue(formula_evaluation_context const &context) const override
Evaluate an existing xvalue.
Definition formula_name_node.hpp:55
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:73
void resolve_function_pointer(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_name_node.hpp:20
std::string get_name() const noexcept override
Get the name of a formula_name_node.
Definition formula_name_node.hpp:78
Definition formula_node.hpp:21
Definition formula_post_process_context.hpp:237
Exception thrown during parsing on an error.
Definition exception_intf.hpp:47
Exception thrown during execution of a dynamic operation.
Definition exception_intf.hpp:160
T what(T... args)