HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_filter_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_binary_operator_node.hpp"
8#include "formula_post_process_context.hpp"
9#include "formula_name_node.hpp"
10
11namespace hi::inline v1 {
12
15 formula_name_node *rhs_name;
16
19 {
20 rhs_name = dynamic_cast<formula_name_node *>(this->rhs.get());
21 if (rhs_name == nullptr) {
22 throw parse_error(std::format("{}: Expecting a name token on the right hand side of a filter operator. got {}.", location, *rhs));
23 }
24 }
25
27 {
28 formula_binary_operator_node::post_process(context);
29
30 filter = context.get_filter(rhs_name->name);
31 if (!filter) {
32 throw parse_error(std::format("{}: Could not find filter .{}().", location, rhs_name->name));
33 }
34 }
35
36 datum evaluate(formula_evaluation_context &context) const override
37 {
38 auto lhs_ = lhs->evaluate(context);
39 try {
40 return datum{filter(static_cast<std::string>(lhs_))};
41 } catch (std::exception const &e) {
42 throw operation_error(std::format("{}: Can not evaluate filter.\n{}", location, e.what()));
43 }
44 }
45
46 std::string string() const noexcept override
47 {
48 return std::format("({} ! {})", *lhs, *rhs);
49 }
50};
51
52} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:13
A dynamic data type.
Definition datum.hpp:219
Definition formula_binary_operator_node.hpp:11
Definition formula_evaluation_context.hpp:15
Definition formula_filter_node.hpp:13
void post_process(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_filter_node.hpp:26
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_filter_node.hpp:36
Definition formula_name_node.hpp:11
Definition formula_post_process_context.hpp:19
Definition parse_location.hpp:18
T get(T... args)
T move(T... args)
T what(T... args)