HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_ternary_operator_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_ternary_operator_node);
11
12namespace hi { inline namespace v1 {
13
18
20 size_t line_nr, size_t column_nr,
22 formula_node &pair) :
23 formula_node(line_nr, column_nr), lhs(std::move(lhs))
24 {
25 formula_arguments &pair_ = dynamic_cast<formula_arguments &>(pair);
26 hi_assert(pair_.args.size() == 2);
27
28 rhs_true = std::move(pair_.args[0]);
29 rhs_false = std::move(pair_.args[1]);
30 // The unique_ptrs inside pair_ are now empty.
31 }
32
34 {
35 lhs->post_process(context);
36 rhs_true->post_process(context);
37 rhs_false->post_process(context);
38 }
39
41 {
42 hilet lhs_ = lhs->evaluate(context);
43 if (lhs_) {
44 return rhs_true->evaluate(context);
45 } else {
46 return rhs_false->evaluate(context);
47 }
48 }
49
50 std::string string() const noexcept override
51 {
52 return std::format("({} ? {} : {})", *lhs, *rhs_true, *rhs_false);
53 }
54};
55
56}} // 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
A temporary node used during parsing.
Definition formula_arguments.hpp:16
Definition formula_evaluation_context.hpp:18
Definition formula_node.hpp:21
Definition formula_post_process_context.hpp:237
Definition formula_ternary_operator_node.hpp:14
void post_process(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_ternary_operator_node.hpp:33
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_ternary_operator_node.hpp:40
T move(T... args)