Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/expr/Variables.h

raw
1 /*
2 * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2025 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 19 сент. 2019 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_EXPR_VARIABLES_H_
23 #define LSP_PLUG_IN_EXPR_VARIABLES_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/runtime/LSPString.h>
27 #include <lsp-plug.in/expr/Resolver.h>
28 #include <lsp-plug.in/lltl/parray.h>
29
30 namespace lsp
31 {
32 namespace expr
33 {
34 class Variables: public Resolver
35 {
36 protected:
37 typedef struct variable_t
38 {
39 LSPString name;
40 value_t value;
41 } variable_t;
42
43 typedef struct user_func_t
44 {
45 LSPString name;
46 function_t func;
47 void *context;
48 } user_func_t;
49
50 protected:
51 Resolver *pResolver;
52 lltl::parray<variable_t> vVars;
53 lltl::parray<user_func_t> vFunc;
54
55 protected:
56 status_t insert_var(const LSPString *name, const value_t *value, size_t idx);
57 status_t insert_var_move(const LSPString *name, value_t *value, size_t idx);
58 ssize_t index_of_var(const LSPString *name);
59
60 status_t insert_func(const LSPString *name, function_t func, void *context, size_t idx);
61 ssize_t index_of_func(const LSPString *name);
62
63 status_t set_move(const LSPString *name, value_t *value);
64
65 public:
66 explicit Variables();
67 explicit Variables(Resolver *r);
68 Variables(const Variables &) = delete;
69 Variables(Variables &&) = delete;
70 virtual ~Variables() override;
71
72 Variables & operator = (const Variables &) = delete;
73 Variables & operator = (Variables &&) = delete;
74
75 public:
76 virtual status_t resolve(value_t *value, const char *name, size_t num_indexes = 0, const ssize_t *indexes = NULL) override;
77 virtual status_t resolve(value_t *value, const LSPString *name, size_t num_indexes = 0, const ssize_t *indexes = NULL) override;
78 virtual status_t call(value_t *value, const char *name, size_t num_args, const value_t *args = NULL) override;
79 virtual status_t call(value_t *value, const LSPString *name, size_t num_args, const value_t *args = NULL) override;
80
81 public:
82 // Different variable operations
83 status_t set_int(const char *name, ssize_t value);
84 status_t set_float(const char *name, double value);
85 status_t set_bool(const char *name, bool value);
86 status_t set_string(const char *name, const char *value, const char *charset = NULL);
87 status_t set_string(const char *name, const LSPString *value);
88 status_t set_null(const char *name);
89
90 status_t set_int(const LSPString *name, ssize_t value);
91 status_t set_float(const LSPString *name, double value);
92 status_t set_bool(const LSPString *name, bool value);
93 status_t set_string(const LSPString *name, const char *value, const char *charset = NULL);
94 status_t set_string(const LSPString *name, const LSPString *value);
95 status_t set_null(const LSPString *name);
96
97 status_t set(const char *name, const value_t *value);
98 status_t set(const LSPString *name, const value_t *value);
99 status_t unset(const char *name, value_t *value = NULL);
100 status_t unset(const LSPString *name, value_t *value = NULL);
101
102 void clear_vars();
103
104 public:
105 status_t bind_func(const char *name, function_t func, void *context = NULL);
106 status_t bind_func(const LSPString *name, function_t func, void *context = NULL);
107
108 status_t unbind_func(const char *name);
109 status_t unbind_func(const LSPString *name);
110
111 void clear_func();
112
113 public:
114 void clear();
115
116 public:
117 /**
118 * Get variable resolver
119 * @return variable resolver
120 */
121 inline Resolver *resolver() { return pResolver; }
122
123 /**
124 * Sett variable resolver
125 * @param resolver variable resolver
126 */
127 inline void set_resolver(Resolver *resolver) { pResolver = resolver; }
128 };
129
130 } /* namespace expr */
131 } /* namespace lsp */
132
133 #endif /* LSP_PLUG_IN_EXPR_VARIABLES_H_ */