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