Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
introspection.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2014-2017, 2019-2020 Tobias Ellinghaus.
4 Copyright (C) 2016 Roman Lebedev.
5 Copyright (C) 2020 Pascal Obry.
6 Copyright (C) 2022 Martin Baƙinka.
7
8 darktable is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 darktable 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 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with darktable. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#ifndef DT_COMMON_INTROSPECTION_H
23#define DT_COMMON_INTROSPECTION_H
24
25#include <inttypes.h>
26#include <glib.h>
27#include <stdlib.h>
28
29// some typedefs for structs that hold the data in a machine readable form
30
31#define DT_INTROSPECTION_VERSION 8
32
33// clang-format off
34
37
60
62{
63 dt_introspection_type_t type; // type of the field
64 const char *type_name; // the type as specified in the source. mostly interesting for enum, struct and the like
65 const char *name; // variable name, possibly with the name of parent structs, separated with '.'
66 const char *field_name; // variable name without any parents
67 const char *description; // some human readable description taken from the comments
68 size_t size; // size of the field in bytes
69 size_t offset; // offset from the beginning of the start of params. TODO: use start of parent struct instead?
70 struct dt_iop_module_so_t *so; // a pointer to the dlopen'ed module
72
77
79{
81 float Min; // minimum allowed value for this float field. taken from comments. defaults to -G_MAXFLOAT
82 float Max; // maximum allowed value for this float field. taken from comments. defaults to G_MAXFLOAT
83 float Default; // default value for this float field. taken from comments. defaults to 0.0
85
87{
89 double Min; // minimum allowed value for this double field. taken from comments. defaults to -G_MAXDOUBLE
90 double Max; // maximum allowed value for this double field. taken from comments. defaults to G_MAXDOUBLE
91 double Default; // default value for this double field. taken from comments. defaults to 0.0
93
95{
97 float _Complex Min; // minimum allowed value for this float complex field. taken from comments. defaults to -G_MAXFLOAT + -G_MAXFLOAT * _Complex_I
98 float _Complex Max; // maximum allowed value for this float complex field. taken from comments. defaults to G_MAXFLOAT + G_MAXFLOAT * _Complex_I
99 float _Complex Default; // default value for this float complex field. taken from comments. defaults to 0.0 + 0.0 * _Complex_I
101
103{
105 char Min; // minimum allowed value for this char field. taken from comments. defaults to CHAR_MIN
106 char Max; // maximum allowed value for this char field. taken from comments. defaults to CHAR_MAX
107 char Default; // default value for this char field. taken from comments. defaults to 0
109
111{
113 int8_t Min; // minimum allowed value for this int8_t field. taken from comments. defaults to G_MININT8
114 int8_t Max; // maximum allowed value for this int8_t field. taken from comments. defaults to G_MAXINT8
115 char Default; // default value for this int8_t field. taken from comments. defaults to 0
117
119{
121 uint8_t Min; // minimum allowed value for this uint8_t field. taken from comments. defaults to 0
122 uint8_t Max; // maximum allowed value for this uint8_t field. taken from comments. defaults to G_MAXUINT8
123 uint8_t Default; // default value for this uint8_t field. taken from comments. defaults to 0
125
127{
129 short Min; // minimum allowed value for this short field. taken from comments. defaults to G_MINSHORT
130 short Max; // maximum allowed value for this short field. taken from comments. defaults to G_MAXSHORT
131 short Default; // default value for this short field. taken from comments. defaults to 0
133
135{
137 unsigned short Min; // minimum allowed value for this unsigned short field. taken from comments. defaults to 0
138 unsigned short Max; // maximum allowed value for this unsigned short field. taken from comments. defaults to G_MAXUSHORT
139 unsigned short Default; // default value for this unsigned short field. taken from comments. defaults to 0
141
143{
145 int Min; // minimum allowed value for this int field. taken from comments. defaults to G_MININT
146 int Max; // maximum allowed value for this int field. taken from comments. defaults to G_MAXINT
147 int Default; // default value for this int field. taken from comments. defaults to 0
149
151{
153 unsigned int Min; // minimum allowed value for this unsigned int field. taken from comments. defaults to 0
154 unsigned int Max; // maximum allowed value for this unsigned int field. taken from comments. defaults to G_MAXUINT
155 unsigned int Default; // default value for this unsigned int field. taken from comments. defaults to 0
157
159{
161 long Min; // minimum allowed value for this long field. taken from comments. defaults to G_MINLONG
162 long Max; // maximum allowed value for this long field. taken from comments. defaults to G_MAXLONG
163 long Default; // default value for this long field. taken from comments. defaults to 0
165
167{
169 unsigned long Min; // minimum allowed value for this unsigned long field. taken from comments. defaults to 0
170 unsigned long Max; // maximum allowed value for this unsigned long field. taken from comments. defaults to G_MAXULONG
171 unsigned long Default; // default value for this unsigned long field. taken from comments. defaults to 0
173
175{
177 gboolean Default; // default value for this gboolean field. taken from comments. defaults to FALSE
179
181{
183 size_t count; // number of elements in the array
184 dt_introspection_type_t type; // type of the elements
185 union dt_introspection_field_t *field; // the relevant data of the elements, depending on type
187
189{
190 const char *name; // the id of the enum value as a string
191 int value; // the enum value
192 const char *description; // some human readable description taken from the comments
194
196{
198 size_t entries; // # entries in values (without the closing {NULL, 0})
199 dt_introspection_type_enum_tuple_t *values; // the enum tuples, consisting of { "STRING", VALUE }. terminated with { NULL, 0 }
200 int Default; // default value for this enum field. taken from comments. defaults to 0
202
204{
206 size_t entries; // # entries in fields (without the closing NULL)
207 union dt_introspection_field_t **fields; // the fields of the struct. NULL terminated
209
211{
213 size_t entries; // # entries in fields (without the closing NULL)
214 union dt_introspection_field_t **fields; // the fields of the union. NULL terminated
216
217// sorry for the camel case/Capitals, but we have to avoid reserved keywords
240
241typedef struct dt_introspection_t
242{
243 int api_version; // introspection API version
244 int params_version; // the version of the params layout. taken from DT_MODULE_INTROSPECTION()
245 const char *type_name; // the typedef'ed name for this type as passed to DT_MODULE_INTROSPECTION()
246 size_t size; // size of the params struct
247 dt_introspection_field_t *field; // the type of the params. should always be a DT_INTROSPECTION_TYPE_STRUCT
248 size_t self_size; // size of dt_iop_module_t. useful to not need dt headers
249 size_t default_params; // offset of the default_params in dt_iop_module_t. useful to not need dt headers
251
252// clang-format on
253
262static inline void *dt_introspection_access_array(dt_introspection_field_t *self, void *start,
263 unsigned int element, dt_introspection_field_t **child)
264{
265 if(!(start && self && self->header.type == DT_INTROSPECTION_TYPE_ARRAY && element < self->Array.count))
266 return NULL;
267
268 if(child) *child = self->Array.field;
269 return (void *)((char *)start + element * self->Array.field->header.size);
270}
271
272
281static inline void *dt_introspection_get_child(dt_introspection_field_t *self, void *start, const char *name,
283{
284 if(!(start && self && name && *name)) return NULL;
285
287
289 iter = self->Struct.fields;
290 else if(self->header.type == DT_INTROSPECTION_TYPE_UNION)
291 iter = self->Union.fields;
292 else
293 return NULL;
294
295 while(*iter)
296 {
297 if(!g_strcmp0((*iter)->header.field_name, name))
298 {
299 size_t parent_offset = self->header.offset;
300 size_t child_offset = (*iter)->header.offset;
301 size_t relative_offset = child_offset - parent_offset;
302 if(child) *child = *iter;
303 return (void *)((char *)start + relative_offset);
304 }
305 iter++;
306 }
307 return NULL;
308}
309
317{
318 if(!(self && self->header.type == DT_INTROSPECTION_TYPE_ENUM)) return NULL;
319
320 for(dt_introspection_type_enum_tuple_t *iter = self->Enum.values; iter->name; iter++)
321 if(iter->value == value)
322 return iter->name;
323
324 return NULL;
325}
326
334static inline gboolean dt_introspection_get_enum_value(dt_introspection_field_t *self, const char *name, int *value)
335{
336 if(!(self && self->header.type == DT_INTROSPECTION_TYPE_ENUM)) return FALSE;
337
338 for(dt_introspection_type_enum_tuple_t *iter = self->Enum.values; iter->name; iter++)
339 if(!g_strcmp0(iter->name, name))
340 {
341 *value = iter->value;
342 return TRUE;
343 }
344
345 return FALSE;
346}
347
348#endif // DT_COMMON_INTROSPECTION_H
349
350// clang-format off
351// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
352// vim: shiftwidth=2 expandtab tabstop=2 cindent
353// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
354// clang-format on
355
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
static void * dt_introspection_access_array(dt_introspection_field_t *self, void *start, unsigned int element, dt_introspection_field_t **child)
static void * dt_introspection_get_child(dt_introspection_field_t *self, void *start, const char *name, dt_introspection_field_t **child)
static gboolean dt_introspection_get_enum_value(dt_introspection_field_t *self, const char *name, int *value)
dt_introspection_type_t
@ DT_INTROSPECTION_TYPE_BOOL
@ DT_INTROSPECTION_TYPE_DOUBLE
@ DT_INTROSPECTION_TYPE_ENUM
@ DT_INTROSPECTION_TYPE_OPAQUE
@ DT_INTROSPECTION_TYPE_NONE
@ DT_INTROSPECTION_TYPE_ARRAY
@ DT_INTROSPECTION_TYPE_CHAR
@ DT_INTROSPECTION_TYPE_UINT8
@ DT_INTROSPECTION_TYPE_FLOAT
@ DT_INTROSPECTION_TYPE_SHORT
@ DT_INTROSPECTION_TYPE_LONG
@ DT_INTROSPECTION_TYPE_ULONG
@ DT_INTROSPECTION_TYPE_UNION
@ DT_INTROSPECTION_TYPE_UINT
@ DT_INTROSPECTION_TYPE_USHORT
@ DT_INTROSPECTION_TYPE_INT8
@ DT_INTROSPECTION_TYPE_STRUCT
@ DT_INTROSPECTION_TYPE_FLOATCOMPLEX
@ DT_INTROSPECTION_TYPE_INT
static const char * dt_introspection_get_enum_name(dt_introspection_field_t *self, int value)
const char * name
Definition pdf.h:90
static const dt_aligned_pixel_simd_t value
Definition simd.h:144
const char * type_name
dt_introspection_field_t * field
union dt_introspection_field_t * field
dt_introspection_type_header_t header
dt_introspection_type_t type
dt_introspection_type_header_t header
dt_introspection_type_header_t header
dt_introspection_type_header_t header
dt_introspection_type_enum_tuple_t * values
dt_introspection_type_header_t header
dt_introspection_type_header_t header
dt_introspection_type_header_t header
dt_introspection_type_t type
struct dt_iop_module_so_t * so
dt_introspection_type_header_t header
dt_introspection_type_header_t header
dt_introspection_type_header_t header
dt_introspection_type_header_t header
dt_introspection_type_header_t header
union dt_introspection_field_t ** fields
dt_introspection_type_header_t header
dt_introspection_type_header_t header
dt_introspection_type_header_t header
dt_introspection_type_header_t header
union dt_introspection_field_t ** fields
dt_introspection_type_header_t header
dt_introspection_type_header_t header
dt_introspection_type_long_t Long
dt_introspection_type_uint8_t UInt8
dt_introspection_type_ulong_t ULong
dt_introspection_type_float_complex_t FloatComplex
dt_introspection_type_header_t header
dt_introspection_type_ushort_t UShort
dt_introspection_type_float_t Float
dt_introspection_type_union_t Union
dt_introspection_type_bool_t Bool
dt_introspection_type_opaque_t Opaque
dt_introspection_type_uint_t UInt
dt_introspection_type_int_t Int
dt_introspection_type_short_t Short
dt_introspection_type_double_t Double
dt_introspection_type_char_t Char
dt_introspection_type_int8_t Int8
dt_introspection_type_array_t Array
dt_introspection_type_enum_t Enum
dt_introspection_type_struct_t Struct