HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_ternary_operator_node.hpp
1// Copyright Take Vos 2020.
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 tt {
10
15
17 formula_node(std::move(location)), lhs(std::move(lhs))
18 {
19 formula_arguments* pair_ = dynamic_cast<formula_arguments*>(pair.get());
20 tt_assert(pair_ != nullptr);
21 tt_assert(pair_->args.size() == 2);
22
23 rhs_true = std::move(pair_->args[0]);
24 rhs_false = std::move(pair_->args[1]);
25 // The unique_ptrs inside pair_ are now empty.
26 }
27
29 lhs->post_process(context);
30 rhs_true->post_process(context);
31 rhs_false->post_process(context);
32 }
33
34 datum evaluate(formula_evaluation_context& context) const override {
35 ttlet lhs_ = lhs->evaluate(context);
36 if (lhs_) {
37 return rhs_true->evaluate(context);
38 } else {
39 return rhs_false->evaluate(context);
40 }
41 }
42
43 std::string string() const noexcept override {
44 return std::format("({} ? {} : {})", *lhs, *rhs_true, *rhs_false);
45 }
46};
47
48}
A dynamic data type.
Definition datum.hpp:213
A temporary node used during parsing.
Definition formula_arguments.hpp:13
Definition formula_evaluation_context.hpp:16
Definition formula_node.hpp:19
Definition formula_post_process_context.hpp:19
Definition formula_ternary_operator_node.hpp:11
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_ternary_operator_node.hpp:34
void post_process(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_ternary_operator_node.hpp:28
Definition parse_location.hpp:17
T get(T... args)
T move(T... args)
T size(T... args)