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#include "../macros.hpp"
9
10hi_export_module(hikogui.formula.formula_vector_literal_node);
11
12namespace hi { inline namespace v1 {
13
15 formula_vector values;
16
17 formula_vector_literal_node(size_t line_nr, size_t column_nr, formula_vector values) :
18 formula_node(line_nr, column_nr), values(std::move(values))
19 {
20 }
21
23 {
24 for (auto &value : values) {
25 value->post_process(context);
26 }
27 }
28
30 {
32 for (hilet &value : values) {
33 r.push_back(value->evaluate(context));
34 }
35 return datum{std::move(r)};
36 }
37
38 datum &assign(formula_evaluation_context &context, datum const &rhs) const override
39 {
41 throw operation_error(std::format("{}:{}: Unpacking values can only be done on vectors, got {}.", line_nr, column_nr, rhs));
42 }
43 if (values.size() < 1) {
44 throw operation_error(std::format("{}:{}: Unpacking can only be done on 1 or more return values.", line_nr, column_nr));
45 }
46 if (values.size() != rhs.size()) {
47 throw operation_error(std::format(
48 "{}:{}: Unpacking values can only be done on with a vector of size {} got {}.",
49 line_nr, column_nr,
50 values.size(),
51 rhs.size()));
52 }
53
54 // Make a copy, in case of self assignment.
55 hilet rhs_copy = rhs;
56
57 std::size_t i = 0;
58 while (true) {
59 hilet &lhs_ = values[i];
60 hilet &rhs_ = rhs_copy[i];
61
62 if (++i < rhs.size()) {
63 lhs_->assign(context, rhs_);
64 } else {
65 return lhs_->assign(context, rhs_);
66 }
67 }
68 }
69
70 std::string string() const noexcept override
71 {
72 std::string r = "[";
73 int i = 0;
74 for (hilet &value : values) {
75 if (i++ > 0) {
76 r += ", ";
77 }
78 r += value->string();
79 }
80 return r + "]";
81 }
82};
83
84}} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A dynamic data type.
Definition datum.hpp:212
Definition formula_evaluation_context.hpp:18
Definition formula_node.hpp:21
Definition formula_post_process_context.hpp:237
Definition formula_vector_literal_node.hpp:14
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:38
void post_process(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_vector_literal_node.hpp:22
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_vector_literal_node.hpp:29
Exception thrown during execution of a dynamic operation.
Definition exception_intf.hpp:160
T move(T... args)
T push_back(T... args)