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-2020 darktable developers.
4
5 darktable is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 darktable is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with darktable. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#include <inttypes.h>
22#include <glib.h>
23#include <stdlib.h>
24
25// some typedefs for structs that hold the data in a machine readable form
26
27#define DT_INTROSPECTION_VERSION 8
28
29// clang-format off
30
33
56
58{
59 dt_introspection_type_t type; // type of the field
60 const char *type_name; // the type as specified in the source. mostly interesting for enum, struct and the like
61 const char *name; // variable name, possibly with the name of parent structs, separated with '.'
62 const char *field_name; // variable name without any parents
63 const char *description; // some human readable description taken from the comments
64 size_t size; // size of the field in bytes
65 size_t offset; // offset from the beginning of the start of params. TODO: use start of parent struct instead?
66 struct dt_iop_module_so_t *so; // a pointer to the dlopen'ed module
68
73
75{
77 float Min; // minimum allowed value for this float field. taken from comments. defaults to -G_MAXFLOAT
78 float Max; // maximum allowed value for this float field. taken from comments. defaults to G_MAXFLOAT
79 float Default; // default value for this float field. taken from comments. defaults to 0.0
81
83{
85 double Min; // minimum allowed value for this double field. taken from comments. defaults to -G_MAXDOUBLE
86 double Max; // maximum allowed value for this double field. taken from comments. defaults to G_MAXDOUBLE
87 double Default; // default value for this double field. taken from comments. defaults to 0.0
89
91{
93 float _Complex Min; // minimum allowed value for this float complex field. taken from comments. defaults to -G_MAXFLOAT + -G_MAXFLOAT * _Complex_I
94 float _Complex Max; // maximum allowed value for this float complex field. taken from comments. defaults to G_MAXFLOAT + G_MAXFLOAT * _Complex_I
95 float _Complex Default; // default value for this float complex field. taken from comments. defaults to 0.0 + 0.0 * _Complex_I
97
99{
101 char Min; // minimum allowed value for this char field. taken from comments. defaults to CHAR_MIN
102 char Max; // maximum allowed value for this char field. taken from comments. defaults to CHAR_MAX
103 char Default; // default value for this char field. taken from comments. defaults to 0
105
107{
109 int8_t Min; // minimum allowed value for this int8_t field. taken from comments. defaults to G_MININT8
110 int8_t Max; // maximum allowed value for this int8_t field. taken from comments. defaults to G_MAXINT8
111 char Default; // default value for this int8_t field. taken from comments. defaults to 0
113
115{
117 uint8_t Min; // minimum allowed value for this uint8_t field. taken from comments. defaults to 0
118 uint8_t Max; // maximum allowed value for this uint8_t field. taken from comments. defaults to G_MAXUINT8
119 uint8_t Default; // default value for this uint8_t field. taken from comments. defaults to 0
121
123{
125 short Min; // minimum allowed value for this short field. taken from comments. defaults to G_MINSHORT
126 short Max; // maximum allowed value for this short field. taken from comments. defaults to G_MAXSHORT
127 short Default; // default value for this short field. taken from comments. defaults to 0
129
131{
133 unsigned short Min; // minimum allowed value for this unsigned short field. taken from comments. defaults to 0
134 unsigned short Max; // maximum allowed value for this unsigned short field. taken from comments. defaults to G_MAXUSHORT
135 unsigned short Default; // default value for this unsigned short field. taken from comments. defaults to 0
137
139{
141 int Min; // minimum allowed value for this int field. taken from comments. defaults to G_MININT
142 int Max; // maximum allowed value for this int field. taken from comments. defaults to G_MAXINT
143 int Default; // default value for this int field. taken from comments. defaults to 0
145
147{
149 unsigned int Min; // minimum allowed value for this unsigned int field. taken from comments. defaults to 0
150 unsigned int Max; // maximum allowed value for this unsigned int field. taken from comments. defaults to G_MAXUINT
151 unsigned int Default; // default value for this unsigned int field. taken from comments. defaults to 0
153
155{
157 long Min; // minimum allowed value for this long field. taken from comments. defaults to G_MINLONG
158 long Max; // maximum allowed value for this long field. taken from comments. defaults to G_MAXLONG
159 long Default; // default value for this long field. taken from comments. defaults to 0
161
163{
165 unsigned long Min; // minimum allowed value for this unsigned long field. taken from comments. defaults to 0
166 unsigned long Max; // maximum allowed value for this unsigned long field. taken from comments. defaults to G_MAXULONG
167 unsigned long Default; // default value for this unsigned long field. taken from comments. defaults to 0
169
171{
173 gboolean Default; // default value for this gboolean field. taken from comments. defaults to FALSE
175
177{
179 size_t count; // number of elements in the array
180 dt_introspection_type_t type; // type of the elements
181 union dt_introspection_field_t *field; // the relevant data of the elements, depending on type
183
185{
186 const char *name; // the id of the enum value as a string
187 int value; // the enum value
188 const char *description; // some human readable description taken from the comments
190
192{
194 size_t entries; // # entries in values (without the closing {NULL, 0})
195 dt_introspection_type_enum_tuple_t *values; // the enum tuples, consisting of { "STRING", VALUE }. terminated with { NULL, 0 }
196 int Default; // default value for this enum field. taken from comments. defaults to 0
198
200{
202 size_t entries; // # entries in fields (without the closing NULL)
203 union dt_introspection_field_t **fields; // the fields of the struct. NULL terminated
205
207{
209 size_t entries; // # entries in fields (without the closing NULL)
210 union dt_introspection_field_t **fields; // the fields of the union. NULL terminated
212
213// sorry for the camel case/Capitals, but we have to avoid reserved keywords
236
237typedef struct dt_introspection_t
238{
239 int api_version; // introspection API version
240 int params_version; // the version of the params layout. taken from DT_MODULE_INTROSPECTION()
241 const char *type_name; // the typedef'ed name for this type as passed to DT_MODULE_INTROSPECTION()
242 size_t size; // size of the params struct
243 dt_introspection_field_t *field; // the type of the params. should always be a DT_INTROSPECTION_TYPE_STRUCT
244 size_t self_size; // size of dt_iop_module_t. useful to not need dt headers
245 size_t default_params; // offset of the default_params in dt_iop_module_t. useful to not need dt headers
247
248// clang-format on
249
258static inline void *dt_introspection_access_array(dt_introspection_field_t *self, void *start,
259 unsigned int element, dt_introspection_field_t **child)
260{
261 if(!(start && self && self->header.type == DT_INTROSPECTION_TYPE_ARRAY && element < self->Array.count))
262 return NULL;
263
264 if(child) *child = self->Array.field;
265 return (void *)((char *)start + element * self->Array.field->header.size);
266}
267
268
277static inline void *dt_introspection_get_child(dt_introspection_field_t *self, void *start, const char *name,
279{
280 if(!(start && self && name && *name)) return NULL;
281
283
285 iter = self->Struct.fields;
286 else if(self->header.type == DT_INTROSPECTION_TYPE_UNION)
287 iter = self->Union.fields;
288 else
289 return NULL;
290
291 while(*iter)
292 {
293 if(!g_strcmp0((*iter)->header.field_name, name))
294 {
295 size_t parent_offset = self->header.offset;
296 size_t child_offset = (*iter)->header.offset;
297 size_t relative_offset = child_offset - parent_offset;
298 if(child) *child = *iter;
299 return (void *)((char *)start + relative_offset);
300 }
301 iter++;
302 }
303 return NULL;
304}
305
312static inline const char *dt_introspection_get_enum_name(dt_introspection_field_t *self, int value)
313{
314 if(!(self && self->header.type == DT_INTROSPECTION_TYPE_ENUM)) return NULL;
315
316 for(dt_introspection_type_enum_tuple_t *iter = self->Enum.values; iter->name; iter++)
317 if(iter->value == value)
318 return iter->name;
319
320 return NULL;
321}
322
330static inline gboolean dt_introspection_get_enum_value(dt_introspection_field_t *self, const char *name, int *value)
331{
332 if(!(self && self->header.type == DT_INTROSPECTION_TYPE_ENUM)) return FALSE;
333
334 for(dt_introspection_type_enum_tuple_t *iter = self->Enum.values; iter->name; iter++)
335 if(!g_strcmp0(iter->name, name))
336 {
337 *value = iter->value;
338 return TRUE;
339 }
340
341 return FALSE;
342}
343
344// clang-format off
345// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
346// vim: shiftwidth=2 expandtab tabstop=2 cindent
347// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
348// clang-format on
349
#define TRUE
Definition ashift_lsd.c:151
#define FALSE
Definition ashift_lsd.c:147
char * name
Definition common/metadata.c:41
static void * dt_introspection_access_array(dt_introspection_field_t *self, void *start, unsigned int element, dt_introspection_field_t **child)
Definition introspection.h:258
static void * dt_introspection_get_child(dt_introspection_field_t *self, void *start, const char *name, dt_introspection_field_t **child)
Definition introspection.h:277
static gboolean dt_introspection_get_enum_value(dt_introspection_field_t *self, const char *name, int *value)
Definition introspection.h:330
dt_introspection_type_t
Definition introspection.h:35
@ DT_INTROSPECTION_TYPE_BOOL
Definition introspection.h:50
@ DT_INTROSPECTION_TYPE_DOUBLE
Definition introspection.h:39
@ DT_INTROSPECTION_TYPE_ENUM
Definition introspection.h:52
@ DT_INTROSPECTION_TYPE_OPAQUE
Definition introspection.h:37
@ DT_INTROSPECTION_TYPE_NONE
Definition introspection.h:36
@ DT_INTROSPECTION_TYPE_ARRAY
Definition introspection.h:51
@ DT_INTROSPECTION_TYPE_CHAR
Definition introspection.h:41
@ DT_INTROSPECTION_TYPE_UINT8
Definition introspection.h:43
@ DT_INTROSPECTION_TYPE_FLOAT
Definition introspection.h:38
@ DT_INTROSPECTION_TYPE_SHORT
Definition introspection.h:44
@ DT_INTROSPECTION_TYPE_LONG
Definition introspection.h:48
@ DT_INTROSPECTION_TYPE_ULONG
Definition introspection.h:49
@ DT_INTROSPECTION_TYPE_UNION
Definition introspection.h:54
@ DT_INTROSPECTION_TYPE_UINT
Definition introspection.h:47
@ DT_INTROSPECTION_TYPE_USHORT
Definition introspection.h:45
@ DT_INTROSPECTION_TYPE_INT8
Definition introspection.h:42
@ DT_INTROSPECTION_TYPE_STRUCT
Definition introspection.h:53
@ DT_INTROSPECTION_TYPE_FLOATCOMPLEX
Definition introspection.h:40
@ DT_INTROSPECTION_TYPE_INT
Definition introspection.h:46
static const char * dt_introspection_get_enum_name(dt_introspection_field_t *self, int value)
Definition introspection.h:312
Definition introspection.h:238
int api_version
Definition introspection.h:239
const char * type_name
Definition introspection.h:241
int params_version
Definition introspection.h:240
dt_introspection_field_t * field
Definition introspection.h:243
size_t self_size
Definition introspection.h:244
size_t size
Definition introspection.h:242
size_t default_params
Definition introspection.h:245
Definition introspection.h:177
union dt_introspection_field_t * field
Definition introspection.h:181
dt_introspection_type_header_t header
Definition introspection.h:178
size_t count
Definition introspection.h:179
dt_introspection_type_t type
Definition introspection.h:180
Definition introspection.h:171
dt_introspection_type_header_t header
Definition introspection.h:172
gboolean Default
Definition introspection.h:173
Definition introspection.h:99
char Min
Definition introspection.h:101
dt_introspection_type_header_t header
Definition introspection.h:100
char Max
Definition introspection.h:102
char Default
Definition introspection.h:103
Definition introspection.h:83
double Default
Definition introspection.h:87
double Max
Definition introspection.h:86
double Min
Definition introspection.h:85
dt_introspection_type_header_t header
Definition introspection.h:84
Definition introspection.h:192
int Default
Definition introspection.h:196
dt_introspection_type_enum_tuple_t * values
Definition introspection.h:195
dt_introspection_type_header_t header
Definition introspection.h:193
size_t entries
Definition introspection.h:194
Definition introspection.h:185
int value
Definition introspection.h:187
const char * description
Definition introspection.h:188
const char * name
Definition introspection.h:186
Definition introspection.h:91
float _Complex Min
Definition introspection.h:93
float _Complex Default
Definition introspection.h:95
dt_introspection_type_header_t header
Definition introspection.h:92
float _Complex Max
Definition introspection.h:94
Definition introspection.h:75
dt_introspection_type_header_t header
Definition introspection.h:76
float Max
Definition introspection.h:78
float Min
Definition introspection.h:77
float Default
Definition introspection.h:79
Definition introspection.h:58
dt_introspection_type_t type
Definition introspection.h:59
const char * field_name
Definition introspection.h:62
struct dt_iop_module_so_t * so
Definition introspection.h:66
size_t size
Definition introspection.h:64
const char * description
Definition introspection.h:63
const char * type_name
Definition introspection.h:60
const char * name
Definition introspection.h:61
size_t offset
Definition introspection.h:65
Definition introspection.h:107
dt_introspection_type_header_t header
Definition introspection.h:108
int8_t Min
Definition introspection.h:109
int8_t Max
Definition introspection.h:110
char Default
Definition introspection.h:111
Definition introspection.h:139
int Default
Definition introspection.h:143
int Max
Definition introspection.h:142
dt_introspection_type_header_t header
Definition introspection.h:140
int Min
Definition introspection.h:141
Definition introspection.h:155
long Default
Definition introspection.h:159
long Min
Definition introspection.h:157
dt_introspection_type_header_t header
Definition introspection.h:156
long Max
Definition introspection.h:158
Definition introspection.h:70
dt_introspection_type_header_t header
Definition introspection.h:71
Definition introspection.h:123
dt_introspection_type_header_t header
Definition introspection.h:124
short Min
Definition introspection.h:125
short Default
Definition introspection.h:127
short Max
Definition introspection.h:126
Definition introspection.h:200
size_t entries
Definition introspection.h:202
union dt_introspection_field_t ** fields
Definition introspection.h:203
dt_introspection_type_header_t header
Definition introspection.h:201
Definition introspection.h:115
uint8_t Max
Definition introspection.h:118
uint8_t Default
Definition introspection.h:119
uint8_t Min
Definition introspection.h:117
dt_introspection_type_header_t header
Definition introspection.h:116
Definition introspection.h:147
dt_introspection_type_header_t header
Definition introspection.h:148
unsigned int Default
Definition introspection.h:151
unsigned int Min
Definition introspection.h:149
unsigned int Max
Definition introspection.h:150
Definition introspection.h:163
dt_introspection_type_header_t header
Definition introspection.h:164
unsigned long Default
Definition introspection.h:167
unsigned long Max
Definition introspection.h:166
unsigned long Min
Definition introspection.h:165
Definition introspection.h:207
union dt_introspection_field_t ** fields
Definition introspection.h:210
dt_introspection_type_header_t header
Definition introspection.h:208
size_t entries
Definition introspection.h:209
Definition introspection.h:131
dt_introspection_type_header_t header
Definition introspection.h:132
unsigned short Min
Definition introspection.h:133
unsigned short Default
Definition introspection.h:135
unsigned short Max
Definition introspection.h:134
Definition imageop.h:155
Definition introspection.h:215
dt_introspection_type_long_t Long
Definition introspection.h:228
dt_introspection_type_uint8_t UInt8
Definition introspection.h:223
dt_introspection_type_ulong_t ULong
Definition introspection.h:229
dt_introspection_type_float_complex_t FloatComplex
Definition introspection.h:220
dt_introspection_type_header_t header
Definition introspection.h:216
dt_introspection_type_ushort_t UShort
Definition introspection.h:225
dt_introspection_type_float_t Float
Definition introspection.h:218
dt_introspection_type_union_t Union
Definition introspection.h:234
dt_introspection_type_bool_t Bool
Definition introspection.h:230
dt_introspection_type_opaque_t Opaque
Definition introspection.h:217
dt_introspection_type_uint_t UInt
Definition introspection.h:227
dt_introspection_type_int_t Int
Definition introspection.h:226
dt_introspection_type_short_t Short
Definition introspection.h:224
dt_introspection_type_double_t Double
Definition introspection.h:219
dt_introspection_type_char_t Char
Definition introspection.h:221
dt_introspection_type_int8_t Int8
Definition introspection.h:222
dt_introspection_type_array_t Array
Definition introspection.h:231
dt_introspection_type_enum_t Enum
Definition introspection.h:232
dt_introspection_type_struct_t Struct
Definition introspection.h:233