HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
hikogui
formula
formula_post_process_context.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_evaluation_context.hpp"
8
#include "../utility/module.hpp"
9
#include "../datum.hpp"
10
#include "../strings.hpp"
11
#include <functional>
12
#include <unordered_map>
13
#include <vector>
14
#include <string>
15
#include <string_view>
16
17
namespace
hi::inline
v1
{
18
19
struct
formula_post_process_context
{
20
using
filter_type
=
std::function
<
std::string
(std::string_view)>;
21
using
filter_table
=
std::unordered_map<std::string, filter_type>
;
22
using
function_type
=
std::function
<
datum
(
formula_evaluation_context
&,
datum::vector_type
const
&)>;
23
using
function_table
=
std::unordered_map<std::string, function_type>
;
24
using
function_stack
=
std::vector<function_type>
;
25
using
method_type
=
std::function
<
datum
(
formula_evaluation_context
&,
datum
&,
datum::vector_type
const
&)>;
26
using
method_table
=
std::unordered_map<std::string, method_type>
;
27
28
function_table
functions;
29
function_stack
super_stack;
30
static
function_table
global_functions;
31
static
method_table
global_methods;
32
static
filter_table
global_filters;
33
34
[[nodiscard]]
function_type
get_function(
std::string
const
&name)
const
noexcept
35
{
36
if
(name ==
"super"
) {
37
if
(super_stack.
size
() > 0) {
38
return
super_stack.
back
();
39
}
else
{
40
return
{};
41
}
42
}
43
44
hilet
i = functions.
find
(name);
45
if
(i != functions.
end
()) {
46
return
i->second;
47
}
48
49
hilet
j = global_functions.
find
(name);
50
if
(j != global_functions.
end
()) {
51
return
j->second;
52
}
53
54
return
{};
55
}
56
57
[[nodiscard]]
function_type
set_function(
std::string
const
&name,
function_type
func)
noexcept
58
{
59
using
std::swap
;
60
61
swap(functions[name], func);
62
return
func;
63
}
64
65
void
push_super(
function_type
func)
noexcept
66
{
67
super_stack.
push_back
(func);
68
}
69
70
void
pop_super(
void
)
noexcept
71
{
72
super_stack.
pop_back
();
73
}
74
75
[[nodiscard]]
filter_type
get_filter(
std::string
const
&name)
const
noexcept
76
{
77
hilet
i = global_filters.
find
(name);
78
if
(i != global_filters.
end
()) {
79
return
i->second;
80
}
81
82
return
{};
83
}
84
85
[[nodiscard]]
method_type
get_method(
std::string
const
&name)
const
noexcept
86
{
87
hilet
i = global_methods.
find
(name);
88
if
(i != global_methods.
end
()) {
89
return
i->second;
90
}
91
92
return
{};
93
}
94
};
95
96
}
// namespace hi::inline v1
hilet
#define hilet
Invariant should be the default for variables.
Definition
utility.hpp:23
v1
DOXYGEN BUG.
Definition
algorithm.hpp:13
v1::datum
A dynamic data type.
Definition
datum.hpp:219
v1::formula_evaluation_context
Definition
formula_evaluation_context.hpp:15
v1::formula_post_process_context
Definition
formula_post_process_context.hpp:19
std::vector::back
T back(T... args)
std::string
std::unordered_map::end
T end(T... args)
std::unordered_map::find
T find(T... args)
std::function< std::string(std::string_view)>
std::vector::pop_back
T pop_back(T... args)
std::vector::push_back
T push_back(T... args)
std::vector::size
T size(T... args)
std::swap
T swap(T... args)
std::unordered_map
std::vector
Generated on Mon Apr 22 2024 12:52:45 for HikoGUI by
1.10.0