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 throw operation_error("{}: Unpacking values can only be done on vectors, got {}.", location, rhs);
34 }
35 if (values.size() < 1) {
36 throw operation_error("{}: Unpacking can only be done on 1 or more return values.", location);
37 }
38 if (values.size() != rhs.size()) {
39 throw operation_error("{}: Unpacking values can only be done on with a vector of size {} got {}.", location, values.size(), rhs.size());
40 }
41
42 // Make a copy, in case of self assignment.
43 ttlet rhs_copy = rhs;
44
45 size_t i = 0;
46 while (true) {
47 ttlet &lhs_ = values[i];
48 ttlet &rhs_ = rhs_copy[i];
49
50 if (++i < rhs.size()) {
51 lhs_->assign(context, rhs_);
52 } else {
53 return lhs_->assign(context, rhs_);
54 }
55 }
56 }
57
58 std::string string() const noexcept override {
59 std::string r = "[";
60 int i = 0;
61 for (ttlet &value: values) {
62 if (i++ > 0) {
63 r += ", ";
64 }
65 r += value->string();
66 }
67 return r + "]";
68 }
69};
70
71}
Exception thrown during execution of a dynamic operation.
Definition exception.hpp:42
Definition formula_evaluation_context.hpp:16
Definition formula_node.hpp:19
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)