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