HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_map_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 keys;
13 formula_vector values;
14
16 formula_node(std::move(location)), keys(std::move(keys)), values(std::move(values)) {}
17
19 for (auto &key: keys) {
20 key->post_process(context);
21 }
22
23 for (auto &value: values) {
24 value->post_process(context);
25 }
26 }
27
28 datum evaluate(formula_evaluation_context& context) const override {
29 tt_assert(keys.size() == values.size());
30
31 datum::map r;
32 for (size_t i = 0; i < keys.size(); i++) {
33 ttlet &key = keys[i];
34 ttlet &value = values[i];
35
36 r[key->evaluate(context)] = value->evaluate(context);
37 }
38 return datum{std::move(r)};
39 }
40
41 std::string string() const noexcept override {
42 tt_assert(keys.size() == values.size());
43
44 std::string r = "{";
45 for (size_t i = 0; i < keys.size(); i++) {
46 ttlet &key = keys[i];
47 ttlet &value = values[i];
48
49 if (i > 0) {
50 r += ", ";
51 }
52 r += key->string();
53 r += ": ";
54 r += value->string();
55 }
56 return r + "}";
57 }
58};
59
60}
Definition formula_evaluation_context.hpp:16
Definition formula_map_literal_node.hpp:11
void post_process(formula_post_process_context &context) override
Resolve function and method pointers.
Definition formula_map_literal_node.hpp:18
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_map_literal_node.hpp:28
Definition formula_node.hpp:19
Definition formula_post_process_context.hpp:19
Definition parse_location.hpp:17
T move(T... args)
T size(T... args)