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#pragma once
23
24#include <inttypes.h>
25#include <glib.h>
26#include <stdlib.h>
27
28// some typedefs for structs that hold the data in a machine readable form
29
30#define DT_INTROSPECTION_VERSION 8
31
32// clang-format off
33
36
59
61{
62 dt_introspection_type_t type; // type of the field
63 const char *type_name; // the type as specified in the source. mostly interesting for enum, struct and the like
64 const char *name; // variable name, possibly with the name of parent structs, separated with '.'
65 const char *field_name; // variable name without any parents
66 const char *description; // some human readable description taken from the comments
67 size_t size; // size of the field in bytes
68 size_t offset; // offset from the beginning of the start of params. TODO: use start of parent struct instead?
69 struct dt_iop_module_so_t *so; // a pointer to the dlopen'ed module
71
76
78{
80 float Min; // minimum allowed value for this float field. taken from comments. defaults to -G_MAXFLOAT
81 float Max; // maximum allowed value for this float field. taken from comments. defaults to G_MAXFLOAT
82 float Default; // default value for this float field. taken from comments. defaults to 0.0
84
86{
88 double Min; // minimum allowed value for this double field. taken from comments. defaults to -G_MAXDOUBLE
89 double Max; // maximum allowed value for this double field. taken from comments. defaults to G_MAXDOUBLE
90 double Default; // default value for this double field. taken from comments. defaults to 0.0
92
94{
96 float _Complex Min; // minimum allowed value for this float complex field. taken from comments. defaults to -G_MAXFLOAT + -G_MAXFLOAT * _Complex_I
97 float _Complex Max; // maximum allowed value for this float complex field. taken from comments. defaults to G_MAXFLOAT + G_MAXFLOAT * _Complex_I
98 float _Complex Default; // default value for this float complex field. taken from comments. defaults to 0.0 + 0.0 * _Complex_I
100
102{
104 char Min; // minimum allowed value for this char field. taken from comments. defaults to CHAR_MIN
105 char Max; // maximum allowed value for this char field. taken from comments. defaults to CHAR_MAX
106 char Default; // default value for this char field. taken from comments. defaults to 0
108
110{
112 int8_t Min; // minimum allowed value for this int8_t field. taken from comments. defaults to G_MININT8
113 int8_t Max; // maximum allowed value for this int8_t field. taken from comments. defaults to G_MAXINT8
114 char Default; // default value for this int8_t field. taken from comments. defaults to 0
116
118{
120 uint8_t Min; // minimum allowed value for this uint8_t field. taken from comments. defaults to 0
121 uint8_t Max; // maximum allowed value for this uint8_t field. taken from comments. defaults to G_MAXUINT8
122 uint8_t Default; // default value for this uint8_t field. taken from comments. defaults to 0
124
126{
128 short Min; // minimum allowed value for this short field. taken from comments. defaults to G_MINSHORT
129 short Max; // maximum allowed value for this short field. taken from comments. defaults to G_MAXSHORT
130 short Default; // default value for this short field. taken from comments. defaults to 0
132
134{
136 unsigned short Min; // minimum allowed value for this unsigned short field. taken from comments. defaults to 0
137 unsigned short Max; // maximum allowed value for this unsigned short field. taken from comments. defaults to G_MAXUSHORT
138 unsigned short Default; // default value for this unsigned short field. taken from comments. defaults to 0
140
142{
144 int Min; // minimum allowed value for this int field. taken from comments. defaults to G_MININT
145 int Max; // maximum allowed value for this int field. taken from comments. defaults to G_MAXINT
146 int Default; // default value for this int field. taken from comments. defaults to 0
148
150{
152 unsigned int Min; // minimum allowed value for this unsigned int field. taken from comments. defaults to 0
153 unsigned int Max; // maximum allowed value for this unsigned int field. taken from comments. defaults to G_MAXUINT
154 unsigned int Default; // default value for this unsigned int field. taken from comments. defaults to 0
156
158{
160 long Min; // minimum allowed value for this long field. taken from comments. defaults to G_MINLONG
161 long Max; // maximum allowed value for this long field. taken from comments. defaults to G_MAXLONG
162 long Default; // default value for this long field. taken from comments. defaults to 0
164
166{
168 unsigned long Min; // minimum allowed value for this unsigned long field. taken from comments. defaults to 0
169 unsigned long Max; // maximum allowed value for this unsigned long field. taken from comments. defaults to G_MAXULONG
170 unsigned long Default; // default value for this unsigned long field. taken from comments. defaults to 0
172
174{
176 gboolean Default; // default value for this gboolean field. taken from comments. defaults to FALSE
178
180{
182 size_t count; // number of elements in the array
183 dt_introspection_type_t type; // type of the elements
184 union dt_introspection_field_t *field; // the relevant data of the elements, depending on type
186
188{
189 const char *name; // the id of the enum value as a string
190 int value; // the enum value
191 const char *description; // some human readable description taken from the comments
193
195{
197 size_t entries; // # entries in values (without the closing {NULL, 0})
198 dt_introspection_type_enum_tuple_t *values; // the enum tuples, consisting of { "STRING", VALUE }. terminated with { NULL, 0 }
199 int Default; // default value for this enum field. taken from comments. defaults to 0
201
203{
205 size_t entries; // # entries in fields (without the closing NULL)
206 union dt_introspection_field_t **fields; // the fields of the struct. NULL terminated
208
210{
212 size_t entries; // # entries in fields (without the closing NULL)
213 union dt_introspection_field_t **fields; // the fields of the union. NULL terminated
215
216// sorry for the camel case/Capitals, but we have to avoid reserved keywords
239
240typedef struct dt_introspection_t
241{
242 int api_version; // introspection API version
243 int params_version; // the version of the params layout. taken from DT_MODULE_INTROSPECTION()
244 const char *type_name; // the typedef'ed name for this type as passed to DT_MODULE_INTROSPECTION()
245 size_t size; // size of the params struct
246 dt_introspection_field_t *field; // the type of the params. should always be a DT_INTROSPECTION_TYPE_STRUCT
247 size_t self_size; // size of dt_iop_module_t. useful to not need dt headers
248 size_t default_params; // offset of the default_params in dt_iop_module_t. useful to not need dt headers
250
251// clang-format on
252
261static inline void *dt_introspection_access_array(dt_introspection_field_t *self, void *start,
262 unsigned int element, dt_introspection_field_t **child)
263{
264 if(!(start && self && self->header.type == DT_INTROSPECTION_TYPE_ARRAY && element < self->Array.count))
265 return NULL;
266
267 if(child) *child = self->Array.field;
268 return (void *)((char *)start + element * self->Array.field->header.size);
269}
270
271
280static inline void *dt_introspection_get_child(dt_introspection_field_t *self, void *start, const char *name,
282{
283 if(!(start && self && name && *name)) return NULL;
284
286
288 iter = self->Struct.fields;
289 else if(self->header.type == DT_INTROSPECTION_TYPE_UNION)
290 iter = self->Union.fields;
291 else
292 return NULL;
293
294 while(*iter)
295 {
296 if(!g_strcmp0((*iter)->header.field_name, name))
297 {
298 size_t parent_offset = self->header.offset;
299 size_t child_offset = (*iter)->header.offset;
300 size_t relative_offset = child_offset - parent_offset;
301 if(child) *child = *iter;
302 return (void *)((char *)start + relative_offset);
303 }
304 iter++;
305 }
306 return NULL;
307}
308
316{
317 if(!(self && self->header.type == DT_INTROSPECTION_TYPE_ENUM)) return NULL;
318
319 for(dt_introspection_type_enum_tuple_t *iter = self->Enum.values; iter->name; iter++)
320 if(iter->value == value)
321 return iter->name;
322
323 return NULL;
324}
325
333static inline gboolean dt_introspection_get_enum_value(dt_introspection_field_t *self, const char *name, int *value)
334{
335 if(!(self && self->header.type == DT_INTROSPECTION_TYPE_ENUM)) return FALSE;
336
337 for(dt_introspection_type_enum_tuple_t *iter = self->Enum.values; iter->name; iter++)
338 if(!g_strcmp0(iter->name, name))
339 {
340 *value = iter->value;
341 return TRUE;
342 }
343
344 return FALSE;
345}
346
347// clang-format off
348// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
349// vim: shiftwidth=2 expandtab tabstop=2 cindent
350// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
351// clang-format on
352
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
char * name
Definition common/metadata.c:61
static const dt_aligned_pixel_simd_t value
Definition darktable.h:501
static void * dt_introspection_access_array(dt_introspection_field_t *self, void *start, unsigned int element, dt_introspection_field_t **child)
Definition introspection.h:261
static void * dt_introspection_get_child(dt_introspection_field_t *self, void *start, const char *name, dt_introspection_field_t **child)
Definition introspection.h:280
static gboolean dt_introspection_get_enum_value(dt_introspection_field_t *self, const char *name, int *value)
Definition introspection.h:333
dt_introspection_type_t
Definition introspection.h:38
@ DT_INTROSPECTION_TYPE_BOOL
Definition introspection.h:53
@ DT_INTROSPECTION_TYPE_DOUBLE
Definition introspection.h:42
@ DT_INTROSPECTION_TYPE_ENUM
Definition introspection.h:55
@ DT_INTROSPECTION_TYPE_OPAQUE
Definition introspection.h:40
@ DT_INTROSPECTION_TYPE_NONE
Definition introspection.h:39
@ DT_INTROSPECTION_TYPE_ARRAY
Definition introspection.h:54
@ DT_INTROSPECTION_TYPE_CHAR
Definition introspection.h:44
@ DT_INTROSPECTION_TYPE_UINT8
Definition introspection.h:46
@ DT_INTROSPECTION_TYPE_FLOAT
Definition introspection.h:41
@ DT_INTROSPECTION_TYPE_SHORT
Definition introspection.h:47
@ DT_INTROSPECTION_TYPE_LONG
Definition introspection.h:51
@ DT_INTROSPECTION_TYPE_ULONG
Definition introspection.h:52
@ DT_INTROSPECTION_TYPE_UNION
Definition introspection.h:57
@ DT_INTROSPECTION_TYPE_UINT
Definition introspection.h:50
@ DT_INTROSPECTION_TYPE_USHORT
Definition introspection.h:48
@ DT_INTROSPECTION_TYPE_INT8
Definition introspection.h:45
@ DT_INTROSPECTION_TYPE_STRUCT
Definition introspection.h:56
@ DT_INTROSPECTION_TYPE_FLOATCOMPLEX
Definition introspection.h:43
@ DT_INTROSPECTION_TYPE_INT
Definition introspection.h:49
static const char * dt_introspection_get_enum_name(dt_introspection_field_t *self, int value)
Definition introspection.h:315
Definition introspection.h:241
int api_version
Definition introspection.h:242
const char * type_name
Definition introspection.h:244
int params_version
Definition introspection.h:243
dt_introspection_field_t * field
Definition introspection.h:246
size_t self_size
Definition introspection.h:247
size_t size
Definition introspection.h:245
size_t default_params
Definition introspection.h:248
Definition introspection.h:180
union dt_introspection_field_t * field
Definition introspection.h:184
dt_introspection_type_header_t header
Definition introspection.h:181
size_t count
Definition introspection.h:182
dt_introspection_type_t type
Definition introspection.h:183
Definition introspection.h:174
dt_introspection_type_header_t header
Definition introspection.h:175
gboolean Default
Definition introspection.h:176
Definition introspection.h:102
char Min
Definition introspection.h:104
dt_introspection_type_header_t header
Definition introspection.h:103
char Max
Definition introspection.h:105
char Default
Definition introspection.h:106
Definition introspection.h:86
double Default
Definition introspection.h:90
double Max
Definition introspection.h:89
double Min
Definition introspection.h:88
dt_introspection_type_header_t header
Definition introspection.h:87
Definition introspection.h:195
int Default
Definition introspection.h:199
dt_introspection_type_enum_tuple_t * values
Definition introspection.h:198
dt_introspection_type_header_t header
Definition introspection.h:196
size_t entries
Definition introspection.h:197
Definition introspection.h:188
int value
Definition introspection.h:190
const char * description
Definition introspection.h:191
const char * name
Definition introspection.h:189
Definition introspection.h:94
float _Complex Min
Definition introspection.h:96
float _Complex Default
Definition introspection.h:98
dt_introspection_type_header_t header
Definition introspection.h:95
float _Complex Max
Definition introspection.h:97
Definition introspection.h:78
dt_introspection_type_header_t header
Definition introspection.h:79
float Max
Definition introspection.h:81
float Min
Definition introspection.h:80
float Default
Definition introspection.h:82
Definition introspection.h:61
dt_introspection_type_t type
Definition introspection.h:62
const char * field_name
Definition introspection.h:65
struct dt_iop_module_so_t * so
Definition introspection.h:69
size_t size
Definition introspection.h:67
const char * description
Definition introspection.h:66
const char * type_name
Definition introspection.h:63
const char * name
Definition introspection.h:64
size_t offset
Definition introspection.h:68
Definition introspection.h:110
dt_introspection_type_header_t header
Definition introspection.h:111
int8_t Min
Definition introspection.h:112
int8_t Max
Definition introspection.h:113
char Default
Definition introspection.h:114
Definition introspection.h:142
int Default
Definition introspection.h:146
int Max
Definition introspection.h:145
dt_introspection_type_header_t header
Definition introspection.h:143
int Min
Definition introspection.h:144
Definition introspection.h:158
long Default
Definition introspection.h:162
long Min
Definition introspection.h:160
dt_introspection_type_header_t header
Definition introspection.h:159
long Max
Definition introspection.h:161
Definition introspection.h:73
dt_introspection_type_header_t header
Definition introspection.h:74
Definition introspection.h:126
dt_introspection_type_header_t header
Definition introspection.h:127
short Min
Definition introspection.h:128
short Default
Definition introspection.h:130
short Max
Definition introspection.h:129
Definition introspection.h:203
size_t entries
Definition introspection.h:205
union dt_introspection_field_t ** fields
Definition introspection.h:206
dt_introspection_type_header_t header
Definition introspection.h:204
Definition introspection.h:118
uint8_t Max
Definition introspection.h:121
uint8_t Default
Definition introspection.h:122
uint8_t Min
Definition introspection.h:120
dt_introspection_type_header_t header
Definition introspection.h:119
Definition introspection.h:150
dt_introspection_type_header_t header
Definition introspection.h:151
unsigned int Default
Definition introspection.h:154
unsigned int Min
Definition introspection.h:152
unsigned int Max
Definition introspection.h:153
Definition introspection.h:166
dt_introspection_type_header_t header
Definition introspection.h:167
unsigned long Default
Definition introspection.h:170
unsigned long Max
Definition introspection.h:169
unsigned long Min
Definition introspection.h:168
Definition introspection.h:210
union dt_introspection_field_t ** fields
Definition introspection.h:213
dt_introspection_type_header_t header
Definition introspection.h:211
size_t entries
Definition introspection.h:212
Definition introspection.h:134
dt_introspection_type_header_t header
Definition introspection.h:135
unsigned short Min
Definition introspection.h:136
unsigned short Default
Definition introspection.h:138
unsigned short Max
Definition introspection.h:137
Definition imageop.h:190
Definition introspection.h:218
dt_introspection_type_long_t Long
Definition introspection.h:231
dt_introspection_type_uint8_t UInt8
Definition introspection.h:226
dt_introspection_type_ulong_t ULong
Definition introspection.h:232
dt_introspection_type_float_complex_t FloatComplex
Definition introspection.h:223
dt_introspection_type_header_t header
Definition introspection.h:219
dt_introspection_type_ushort_t UShort
Definition introspection.h:228
dt_introspection_type_float_t Float
Definition introspection.h:221
dt_introspection_type_union_t Union
Definition introspection.h:237
dt_introspection_type_bool_t Bool
Definition introspection.h:233
dt_introspection_type_opaque_t Opaque
Definition introspection.h:220
dt_introspection_type_uint_t UInt
Definition introspection.h:230
dt_introspection_type_int_t Int
Definition introspection.h:229
dt_introspection_type_short_t Short
Definition introspection.h:227
dt_introspection_type_double_t Double
Definition introspection.h:222
dt_introspection_type_char_t Char
Definition introspection.h:224
dt_introspection_type_int8_t Int8
Definition introspection.h:225
dt_introspection_type_array_t Array
Definition introspection.h:234
dt_introspection_type_enum_t Enum
Definition introspection.h:235
dt_introspection_type_struct_t Struct
Definition introspection.h:236