HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_vector_literal_node.hpp
1// Copyright Take Vos 2020-2022.
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
12 formula_vector values;
13
15 formula_node(std::move(location)), values(std::move(values))
16 {
17 }
18
20 {
21 for (auto &value : values) {
22 value->post_process(context);
23 }
24 }
25
26 datum evaluate(formula_evaluation_context &context) const override
27 {
29 for (hilet &value : values) {
30 r.push_back(value->evaluate(context));
31 }
32 return datum{std::move(r)};
33 }
34
35 datum &assign(formula_evaluation_context &context, datum const &rhs) const override
36 {
37 if (!holds_alternative<datum::vector_type>(rhs)) {
38 throw operation_error(std::format("{}: Unpacking values can only be done on vectors, got {}.", location, rhs));
39 }
40 if (values.size() < 1) {
41 throw operation_error(std::format("{}: Unpacking can only be done on 1 or more return values.", location));
42 }
43 if (values.size() != rhs.size()) {
44 throw operation_error(std::format(
45 "{}: Unpacking values can only be done on with a vector of size {} got {}.",
46 location,
47 values.size(),
48 rhs.size()));
49 }
50
51 // Make a copy, in case of self assignment.
52 hilet rhs_copy = rhs;
53
54 std::size_t i = 0;
55 while (true) {
56 hilet &lhs_ = values[i];
57 hilet &rhs_ = rhs_copy[i];
58
59 if (++i < rhs.size()) {
60 lhs_->assign(context, rhs_);
61 } else {
62 return lhs_->assign(context, rhs_);
63 }
64 }
65 }
66
67 std::string string() const noexcept override
68 {
69 std::string r = "[";
70 int i = 0;
71 for (hilet &value : values) {
72 if (i++ > 0) {
73 r += ", ";
74 }
75 r += value->string();
76 }
77 return r + "]";
78 }
79};
80
81} // namespace hi::inline v1
#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
Definition formula_evaluation_context.hpp:16
Definition formula_node.hpp:29
Definition formula_post_process_context.hpp:19
Definition formula_vector_literal_node.hpp:11
datum & assign(formula_evaluation_context &context, datum const &rhs) const override
Assign to a non-existing or existing lvalue.
Definition formula_vector_literal_node.hpp:35
void post_process(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_vector_literal_node.hpp:19
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_vector_literal_node.hpp:26
Definition parse_location.hpp:18
T move(T... args)
T push_back(T... args)