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
static const dt_aligned_pixel_simd_t value
Definition darktable.h:577
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 * 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