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
9namespace hi::inline v1 {
10
15
17 parse_location location,
20 formula_node(std::move(location)), lhs(std::move(lhs))
21 {
22 formula_arguments *pair_ = dynamic_cast<formula_arguments *>(pair.get());
23 hi_assert(pair_ != nullptr);
24 hi_assert(pair_->args.size() == 2);
25
26 rhs_true = std::move(pair_->args[0]);
27 rhs_false = std::move(pair_->args[1]);
28 // The unique_ptrs inside pair_ are now empty.
29 }
30
32 {
33 lhs->post_process(context);
34 rhs_true->post_process(context);
35 rhs_false->post_process(context);
36 }
37
38 datum evaluate(formula_evaluation_context &context) const override
39 {
40 hilet lhs_ = lhs->evaluate(context);
41 if (lhs_) {
42 return rhs_true->evaluate(context);
43 } else {
44 return rhs_false->evaluate(context);
45 }
46 }
47
48 std::string string() const noexcept override
49 {
50 return std::format("({} ? {} : {})", *lhs, *rhs_true, *rhs_false);
51 }
52};
53
54} // namespace hi::inline v1
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:87
#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
A temporary node used during parsing.
Definition formula_arguments.hpp:13
Definition formula_evaluation_context.hpp:16
Definition formula_node.hpp:29
Definition formula_post_process_context.hpp:19
Definition formula_ternary_operator_node.hpp:11
void post_process(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_ternary_operator_node.hpp:31
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_ternary_operator_node.hpp:38
Definition parse_location.hpp:18
T get(T... args)
T move(T... args)
T size(T... args)