HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
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 "../strings.hpp"
11#include <functional>
12#include <unordered_map>
13#include <vector>
14#include <string>
15#include <string_view>
16
17namespace tt {
18
20 using filter_type = std::function<std::string(std::string_view)>;
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 if (name == "super") {
36 if (super_stack.size() > 0) {
37 return super_stack.back();
38 } else {
39 return {};
40 }
41 }
42
43 ttlet i = functions.find(name);
44 if (i != functions.end()) {
45 return i->second;
46 }
47
48 ttlet j = global_functions.find(name);
49 if (j != global_functions.end()) {
50 return j->second;
51 }
52
53 return {};
54 }
55
56 [[nodiscard]] function_type set_function(std::string const &name, function_type func) noexcept {
57 using namespace std;
58
59 swap(functions[name], func);
60 return func;
61 }
62
63 void push_super(function_type func) noexcept {
64 super_stack.push_back(func);
65 }
66
67 void pop_super(void) noexcept {
68 super_stack.pop_back();
69 }
70
71 [[nodiscard]] filter_type get_filter(std::string const &name) const noexcept {
72 ttlet i = global_filters.find(name);
73 if (i != global_filters.end()) {
74 return i->second;
75 }
76
77 return {};
78 }
79
80 [[nodiscard]] method_type get_method(std::string const &name) const noexcept {
81 ttlet i = global_methods.find(name);
82 if (i != global_methods.end()) {
83 return i->second;
84 }
85
86 return {};
87 }
88};
89
90}
STL namespace.
A dynamic data type.
Definition datum.hpp:213
Definition formula_evaluation_context.hpp:16
Definition formula_post_process_context.hpp:19
T back(T... args)
T end(T... args)
T find(T... args)
T pop_back(T... args)
T push_back(T... args)
T size(T... args)