HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
formula_map_literal_node.hpp
1// Copyright Take Vos 2020-2021.
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 keys;
13 formula_vector values;
14
16 formula_node(std::move(location)), keys(std::move(keys)), values(std::move(values))
17 {
18 }
19
21 {
22 for (auto &key : keys) {
23 key->post_process(context);
24 }
25
26 for (auto &value : values) {
27 value->post_process(context);
28 }
29 }
30
31 datum evaluate(formula_evaluation_context &context) const override
32 {
33 hi_assert(keys.size() == values.size());
34
36 for (std::size_t i = 0; i < keys.size(); i++) {
37 hilet &key = keys[i];
38 hilet &value = values[i];
39
40 r[key->evaluate(context)] = value->evaluate(context);
41 }
42 return datum{std::move(r)};
43 }
44
45 std::string string() const noexcept override
46 {
47 hi_assert(keys.size() == values.size());
48
49 std::string r = "{";
50 for (std::size_t i = 0; i < keys.size(); i++) {
51 hilet &key = keys[i];
52 hilet &value = values[i];
53
54 if (i > 0) {
55 r += ", ";
56 }
57 r += key->string();
58 r += ": ";
59 r += value->string();
60 }
61 return r + "}";
62 }
63};
64
65} // namespace hi::inline v1
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:87
#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_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:20
datum evaluate(formula_evaluation_context &context) const override
Evaluate an rvalue.
Definition formula_map_literal_node.hpp:31
Definition formula_node.hpp:29
Definition formula_post_process_context.hpp:19
Definition parse_location.hpp:18
T move(T... args)
T size(T... args)