HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_index_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 "../macros.hpp"
9
10hi_export_module(hikogui.formula.formula_index_node);
11
12namespace hi { inline namespace v1 {
13
15 formula_index_node(size_t line_nr, size_t column_nr, std::unique_ptr<formula_node> lhs, std::unique_ptr<formula_node> rhs) :
16 formula_binary_operator_node(line_nr, column_nr, std::move(lhs), std::move(rhs))
17 {
18 }
19
21 {
22 auto lhs_ = lhs->evaluate(context);
23 auto rhs_ = rhs->evaluate(context);
24
26 throw operation_error(std::format("{}:{}: Unknown key '{}'.", line_nr, column_nr, rhs_));
27 }
28
29 try {
30 return lhs_[rhs_];
31 } catch (std::exception const &e) {
32 throw operation_error(std::format("{}:{}: Can not evaluate indexing operation.\n{}", line_nr, column_nr, e.what()));
33 }
34 }
35
37 {
38 auto &lhs_ = lhs->evaluate_lvalue(context);
39 auto rhs_ = rhs->evaluate(context);
40 try {
41 return lhs_[rhs_];
42 } catch (std::exception const &e) {
43 throw operation_error(std::format("{}:{}: Can not evaluate indexing operation.\n{}", line_nr, column_nr, e.what()));
44 }
45 }
46
47 std::string string() const noexcept override
48 {
49 return std::format("({}[{}])", *lhs, *rhs);
50 }
51};
52
53}} // 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
Definition formula_binary_operator_node.hpp:14
Definition formula_evaluation_context.hpp:18
Definition formula_index_node.hpp:14
datum & evaluate_lvalue(formula_evaluation_context &context) const override
Evaluate an existing lvalue.
Definition formula_index_node.hpp:36
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_index_node.hpp:20
Exception thrown during execution of a dynamic operation.
Definition exception_intf.hpp:160
T move(T... args)
T what(T... args)