1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
/*
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-runtime-lib
* Created on: 19 февр. 2020 г.
*
* lsp-runtime-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-runtime-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LSP_PLUG_IN_EXPR_PARAMETERS_H_
#define LSP_PLUG_IN_EXPR_PARAMETERS_H_
#include <lsp-plug.in/runtime/version.h>
#include <lsp-plug.in/lltl/parray.h>
#include <lsp-plug.in/expr/Resolver.h>
namespace lsp
{
namespace expr
{
/**
* Implements list of optionally named parameters which then can be used for string formatting.
* Parameters may have duplicate names. From set of named parameters with the same name the parameter
* with the least index will be visible by the name.
*/
class Parameters: public Resolver
{
private:
Parameters & operator = (const Parameters &);
protected:
typedef struct param_t
{
value_t value;
ssize_t len;
lsp_wchar_t name[];
} param_t;
protected:
lltl::parray<param_t> vParams;
protected:
param_t *lookup_by_name(const LSPString *name);
param_t *lookup_by_name(const LSPString *name, size_t *idx);
static param_t *allocate();
static param_t *allocate(const lsp_wchar_t *name, ssize_t len);
static param_t *clone(const param_t *src);
static void destroy(param_t *p);
inline static param_t *allocate(const LSPString *name) { return allocate(name->characters(), name->length()); };
static void destroy_params(lltl::parray<param_t> ¶ms);
status_t drop_value(size_t index, value_type_t type, param_t **out);
status_t drop_value(const char *name, value_type_t type, param_t **out);
status_t drop_value(const LSPString *name, value_type_t type, param_t **out);
protected:
/**
* This callback is called when the collection becomes modified.
* Method can be overridden to trigger different events like parent
* collection update.
*/
virtual void modified();
public:
explicit Parameters();
virtual ~Parameters();
public:
virtual status_t resolve(value_t *value, const char *name, size_t num_indexes = 0, const ssize_t *indexes = NULL);
virtual status_t resolve(value_t *value, const LSPString *name, size_t num_indexes = 0, const ssize_t *indexes = NULL);
public:
inline size_t size() const { return vParams.size(); }
void swap(Parameters *src);
void clear();
Parameters *clone() const;
// Adding: add parameter to the end of list.
status_t add_int(const char *name, ssize_t value);
status_t add_float(const char *name, double value);
status_t add_bool(const char *name, bool value);
status_t add_cstring(const char *name, const char *value);
status_t add_string(const char *name, const LSPString *value);
status_t add_null(const char *name);
status_t add_undef(const char *name);
status_t add(const char *name, const value_t *value);
status_t add_int(const LSPString *name, ssize_t value);
status_t add_float(const LSPString *name, double value);
status_t add_bool(const LSPString *name, bool value);
status_t add_cstring(const LSPString *name, const char *value);
status_t add_string(const LSPString *name, const LSPString *value);
status_t add_null(const LSPString *name);
status_t add_undef(const LSPString *name);
status_t add(const LSPString *name, const value_t *value);
status_t add_int(ssize_t value);
status_t add_float(double value);
status_t add_bool(bool value);
status_t add_cstring(const char *value);
status_t add_string(const LSPString *value);
status_t add_null();
status_t add_undef();
status_t add(const value_t *value);
status_t add(const Parameters *p, ssize_t first = 0, ssize_t last = -1);
// Inserting
status_t insert_int(size_t index, const char *name, ssize_t value);
status_t insert_float(size_t index, const char *name, double value);
status_t insert_bool(size_t index, const char *name, bool value);
status_t insert_string(size_t index, const char *name, const char *value);
status_t insert_string(size_t index, const char *name, const LSPString *value);
status_t insert_null(size_t index, const char *name);
status_t insert_undef(size_t index, const char *name);
status_t insert(size_t index, const char *name, const value_t *value);
status_t insert_int(size_t index, const LSPString *name, ssize_t value);
status_t insert_float(size_t index, const LSPString *name, double value);
status_t insert_bool(size_t index, const LSPString *name, bool value);
status_t insert_string(size_t index, const LSPString *name, const char *value);
status_t insert_string(size_t index, const LSPString *name, const LSPString *value);
status_t insert_null(size_t index, const LSPString *name);
status_t insert_undef(size_t index, const LSPString *name);
status_t insert(size_t index, const LSPString *name, const value_t *value);
status_t insert_int(size_t index, ssize_t value);
status_t insert_float(size_t index, double value);
status_t insert_bool(size_t index, bool value);
status_t insert_cstring(size_t index, const char *value);
status_t insert_string(size_t index, const LSPString *value);
status_t insert_null(size_t index);
status_t insert_undef(size_t index);
status_t insert(size_t index, const value_t *value);
status_t insert(size_t index, const Parameters *p, ssize_t first = 0, ssize_t last = -1);
// Getting
status_t get_int(size_t index, ssize_t *value) const;
status_t get_float(size_t index, double *value) const;
status_t get_bool(size_t index, bool *value) const;
status_t get_string(size_t index, LSPString *value) const;
status_t get_null(size_t index) const;
status_t get_undef(size_t index) const;
status_t get(size_t index, value_t *value) const;
status_t get_int(const char *name, ssize_t *value) const;
status_t get_float(const char *name, double *value) const;
status_t get_bool(const char *name, bool *value) const;
status_t get_string(const char *name, LSPString *value) const;
status_t get_null(const char *name) const;
status_t get_undef(const char *name) const;
status_t get(const char *name, value_t *value) const;
status_t get_int(const LSPString *name, ssize_t *value) const;
status_t get_float(const LSPString *name, double *value) const;
status_t get_bool(const LSPString *name, bool *value) const;
status_t get_string(const LSPString *name, LSPString *value) const;
status_t get_null(const LSPString *name) const;
status_t get_undef(const LSPString *name) const;
status_t get(const LSPString *name, value_t *value) const;
// Getting with cast
status_t as_int(size_t index, ssize_t *value) const;
status_t as_float(size_t index, double *value) const;
status_t as_bool(size_t index, bool *value) const;
status_t as_string(size_t index, LSPString *value) const;
status_t as_null(size_t index) const;
status_t as_undef(size_t index) const;
status_t as_value(size_t index, value_t *value, value_type_t type) const;
status_t as_int(const char *name, ssize_t *value) const;
status_t as_float(const char *name, double *value) const;
status_t as_bool(const char *name, bool *value) const;
status_t as_string(const char *name, LSPString *value) const;
status_t as_null(const char *name) const;
status_t as_undef(const char *name) const;
status_t as_value(const char *name, value_t *value, value_type_t type) const;
status_t as_int(const LSPString *name, ssize_t *value) const;
status_t as_float(const LSPString *name, double *value) const;
status_t as_bool(const LSPString *name, bool *value) const;
status_t as_string(const LSPString *name, LSPString *value) const;
status_t as_null(const LSPString *name) const;
status_t as_undef(const LSPString *name) const;
status_t as_value(const LSPString *name, value_t *value, value_type_t type) const;
// Setting
status_t set_int(const char *name, ssize_t value);
status_t set_float(const char *name, double value);
status_t set_bool(const char *name, bool value);
status_t set_cstring(const char *name, const char *value);
status_t set_string(const char *name, const LSPString *value);
status_t set_null(const char *name);
status_t set_undef(const char *name);
status_t set(const char *name, const value_t *value);
status_t set_int(const LSPString *name, ssize_t value);
status_t set_float(const LSPString *name, double value);
status_t set_bool(const LSPString *name, bool value);
status_t set_cstring(const LSPString *name, const char *value);
status_t set_string(const LSPString *name, const LSPString *value);
status_t set_null(const LSPString *name);
status_t set_undef(const LSPString *name);
status_t set(const LSPString *name, const value_t *value);
status_t set_int(size_t index, ssize_t value);
status_t set_float(size_t index, double value);
status_t set_bool(size_t index, bool value);
status_t set_cstring(size_t index, const char *value);
status_t set_string(size_t index, const LSPString *value);
status_t set_null(size_t index);
status_t set_undef(size_t index);
status_t set(size_t index, const value_t *value);
status_t set(const Parameters *p, ssize_t first = 0, ssize_t last = -1);
// Removing
status_t remove_int(size_t index, ssize_t *value = NULL);
status_t remove_float(size_t index, double *value = NULL);
status_t remove_bool(size_t index, bool *value = NULL);
status_t remove_string(size_t index, LSPString *value = NULL);
status_t remove_null(size_t index);
status_t remove_undef(size_t index);
status_t remove(size_t index, value_t *value = NULL);
status_t remove_value(size_t index, value_type_t type, value_t *value);
status_t remove_int(const char *name, ssize_t *value = NULL);
status_t remove_float(const char *name, double *value = NULL);
status_t remove_bool(const char *name, bool *value = NULL);
status_t remove_string(const char *name, LSPString *value = NULL);
status_t remove_null(const char *name = NULL);
status_t remove_undef(const char *name = NULL);
status_t remove(const char *name, value_t *value = NULL);
status_t remove_value(const char *name, value_type_t type, value_t *value = NULL);
status_t remove_int(const LSPString *name, ssize_t *value = NULL);
status_t remove_float(const LSPString *name, double *value = NULL);
status_t remove_bool(const LSPString *name, bool *value = NULL);
status_t remove_string(const LSPString *name, LSPString *value = NULL);
status_t remove_null(const LSPString *name = NULL);
status_t remove_undef(const LSPString *name = NULL);
status_t remove(const LSPString *name, value_t *value = NULL);
status_t remove_value(const LSPString *name, value_type_t type, value_t *value = NULL);
status_t remove(ssize_t first, ssize_t last);
// Obtaining type of parameter (negative result on error)
ssize_t get_type(size_t index) const;
ssize_t get_type(const char *name) const;
ssize_t get_type(const LSPString *name) const;
// Obtaining name of parameter
status_t get_name(size_t index, LSPString *name) const;
ssize_t get_index(const LSPString *name) const;
ssize_t get_index(const char *name) const;
// Checking for contents
inline bool contains(size_t index) const { return index < vParams.size(); }
inline bool contains(const char *name) const { return get_index(name) >= 0; }
inline bool contains(const LSPString *name) const { return get_index(name) >= 0; }
};
} /* namespace calc */
} /* namespace lsp */
#endif /* LSP_PLUG_IN_EXPR_PARAMETERS_H_ */
|