HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
skeleton_do_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 "skeleton_node.hpp"
8
9namespace tt {
10
12 statement_vector children;
14 parse_location formula_location;
15
16 skeleton_do_node(parse_location location) noexcept :
17 skeleton_node(std::move(location)) {}
18
19
20 bool found_while(parse_location _location, std::unique_ptr<formula_node> x) noexcept override {
21 if (expression) {
22 return false;
23 } else {
24 expression = std::move(x);
25 formula_location = std::move(_location);
26 return true;
27 }
28 }
29
32 bool append(std::unique_ptr<skeleton_node> x) noexcept override {
33 if (expression) {
34 return false;
35 } else {
36 append_child(children, std::move(x));
37 return true;
38 }
39 }
40
41 void post_process(formula_post_process_context &context) override {
42 if (std::ssize(children) > 0) {
43 children.back()->left_align();
44 }
45
46 post_process_expression(context, *expression, location);
47
48 for (ttlet &child: children) {
49 child->post_process(context);
50 }
51 }
52
54 ttlet output_size = context.output_size();
55
56 ssize_t loop_count = 0;
57 do {
58 context.loop_push(loop_count++);
59 auto tmp = evaluate_children(context, children);
60 context.loop_pop();
61
62 if (tmp.is_break()) {
63 break;
64 } else if (tmp.is_continue()) {
65 continue;
66 } else if (!tmp.is_undefined()) {
67 context.set_output_size(output_size);
68 return tmp;
69 }
70
71 } while (evaluate_formula_without_output(context, *expression, formula_location));
72 return {};
73 }
74
75 std::string string() const noexcept override {
76 tt_assert(expression);
77 std::string s = "<do ";
78 s += join(transform<std::vector<std::string>>(children, [](auto &x) { return to_string(*x); }));
79 s += to_string(*expression);
80 s += ">";
81 return s;
82 }
83};
84
85}
Definition formula_evaluation_context.hpp:16
void set_output_size(ssize_t new_size) noexcept
Set the size of the output.
Definition formula_evaluation_context.hpp:67
ssize_t output_size() const noexcept
Get the size of the output.
Definition formula_evaluation_context.hpp:60
Definition formula_post_process_context.hpp:18
Definition parse_location.hpp:16
Definition skeleton_do_node.hpp:11
datum evaluate(formula_evaluation_context &context) override
Evaluate the template.
Definition skeleton_do_node.hpp:53
bool append(std::unique_ptr< skeleton_node > x) noexcept override
Append a template-piece to the current template.
Definition skeleton_do_node.hpp:32
Definition skeleton_node.hpp:16
T move(T... args)