GLib 2.39.3
[glib.git] / gobject / gparam.h
blob7e734e32551660ec064d5e0cb1ec4c0b7c16e964
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * gparam.h: GParamSpec base class implementation
21 #ifndef __G_PARAM_H__
22 #define __G_PARAM_H__
24 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
25 #error "Only <glib-object.h> can be included directly."
26 #endif
28 #include <gobject/gvalue.h>
30 G_BEGIN_DECLS
32 /* --- standard type macros --- */
33 /**
34 * G_TYPE_IS_PARAM:
35 * @type: a #GType ID
37 * Checks whether @type "is a" %G_TYPE_PARAM.
39 #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
40 /**
41 * G_PARAM_SPEC:
42 * @pspec: a valid #GParamSpec
44 * Casts a derived #GParamSpec object (e.g. of type #GParamSpecInt) into
45 * a #GParamSpec object.
47 #define G_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM, GParamSpec))
48 /**
49 * G_IS_PARAM_SPEC:
50 * @pspec: a #GParamSpec
52 * Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM
53 * or derived.
55 #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM))
56 /**
57 * G_PARAM_SPEC_CLASS:
58 * @pclass: a valid #GParamSpecClass
60 * Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure.
62 #define G_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_CAST ((pclass), G_TYPE_PARAM, GParamSpecClass))
63 /**
64 * G_IS_PARAM_SPEC_CLASS:
65 * @pclass: a #GParamSpecClass
67 * Checks whether @pclass "is a" valid #GParamSpecClass structure of type
68 * %G_TYPE_PARAM or derived.
70 #define G_IS_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_TYPE ((pclass), G_TYPE_PARAM))
71 /**
72 * G_PARAM_SPEC_GET_CLASS:
73 * @pspec: a valid #GParamSpec
75 * Retrieves the #GParamSpecClass of a #GParamSpec.
77 #define G_PARAM_SPEC_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass))
80 /* --- convenience macros --- */
81 /**
82 * G_PARAM_SPEC_TYPE:
83 * @pspec: a valid #GParamSpec
85 * Retrieves the #GType of this @pspec.
87 #define G_PARAM_SPEC_TYPE(pspec) (G_TYPE_FROM_INSTANCE (pspec))
88 /**
89 * G_PARAM_SPEC_TYPE_NAME:
90 * @pspec: a valid #GParamSpec
92 * Retrieves the #GType name of this @pspec.
94 #define G_PARAM_SPEC_TYPE_NAME(pspec) (g_type_name (G_PARAM_SPEC_TYPE (pspec)))
95 /**
96 * G_PARAM_SPEC_VALUE_TYPE:
97 * @pspec: a valid #GParamSpec
99 * Retrieves the #GType to initialize a #GValue for this parameter.
101 #define G_PARAM_SPEC_VALUE_TYPE(pspec) (G_PARAM_SPEC (pspec)->value_type)
103 * G_VALUE_HOLDS_PARAM:
104 * @value: a valid #GValue structure
106 * Checks whether the given #GValue can hold values derived from type %G_TYPE_PARAM.
108 * Returns: %TRUE on success.
110 #define G_VALUE_HOLDS_PARAM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM))
113 /* --- flags --- */
115 * GParamFlags:
116 * @G_PARAM_READABLE: the parameter is readable
117 * @G_PARAM_WRITABLE: the parameter is writable
118 * @G_PARAM_CONSTRUCT: the parameter will be set upon object construction
119 * @G_PARAM_CONSTRUCT_ONLY: the parameter will only be set upon object construction
120 * @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert())
121 * strict validation is not required
122 * @G_PARAM_STATIC_NAME: the string used as name when constructing the
123 * parameter is guaranteed to remain valid and
124 * unmodified for the lifetime of the parameter.
125 * Since 2.8
126 * @G_PARAM_STATIC_NICK: the string used as nick when constructing the
127 * parameter is guaranteed to remain valid and
128 * unmmodified for the lifetime of the parameter.
129 * Since 2.8
130 * @G_PARAM_STATIC_BLURB: the string used as blurb when constructing the
131 * parameter is guaranteed to remain valid and
132 * unmodified for the lifetime of the parameter.
133 * Since 2.8
134 * @G_PARAM_PRIVATE: internal
135 * @G_PARAM_DEPRECATED: the parameter is deprecated and will be removed
136 * in a future version. A warning will be generated if it is used
137 * while running with G_ENABLE_DIAGNOSTIC=1.
138 * Since 2.26
140 * Through the #GParamFlags flag values, certain aspects of parameters
141 * can be configured. See also #G_PARAM_READWRITE and #G_PARAM_STATIC_STRINGS.
143 typedef enum
145 G_PARAM_READABLE = 1 << 0,
146 G_PARAM_WRITABLE = 1 << 1,
147 G_PARAM_CONSTRUCT = 1 << 2,
148 G_PARAM_CONSTRUCT_ONLY = 1 << 3,
149 G_PARAM_LAX_VALIDATION = 1 << 4,
150 G_PARAM_STATIC_NAME = 1 << 5,
151 #ifndef G_DISABLE_DEPRECATED
152 G_PARAM_PRIVATE = G_PARAM_STATIC_NAME,
153 #endif
154 G_PARAM_STATIC_NICK = 1 << 6,
155 G_PARAM_STATIC_BLURB = 1 << 7,
156 /* User defined flags go up to 30 */
157 G_PARAM_DEPRECATED = 1 << 31
158 } GParamFlags;
160 * G_PARAM_READWRITE:
162 * #GParamFlags value alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE.
164 #define G_PARAM_READWRITE (G_PARAM_READABLE | G_PARAM_WRITABLE)
166 * G_PARAM_STATIC_STRINGS:
168 * #GParamFlags value alias for %G_PARAM_STATIC_NAME | %G_PARAM_STATIC_NICK | %G_PARAM_STATIC_BLURB.
170 * Since 2.13.0
172 #define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
173 /* bits in the range 0xffffff00 are reserved for 3rd party usage */
175 * G_PARAM_MASK:
177 * Mask containing the bits of #GParamSpec.flags which are reserved for GLib.
179 #define G_PARAM_MASK (0x000000ff)
181 * G_PARAM_USER_SHIFT:
183 * Minimum shift count to be used for user defined flags, to be stored in
184 * #GParamSpec.flags. The maximum allowed is 30 + G_PARAM_USER_SHIFT.
186 #define G_PARAM_USER_SHIFT (8)
188 /* --- typedefs & structures --- */
189 typedef struct _GParamSpec GParamSpec;
190 typedef struct _GParamSpecClass GParamSpecClass;
191 typedef struct _GParameter GParameter;
192 typedef struct _GParamSpecPool GParamSpecPool;
194 * GParamSpec:
195 * @g_type_instance: private #GTypeInstance portion
196 * @name: name of this parameter: always an interned string
197 * @flags: #GParamFlags flags for this parameter
198 * @value_type: the #GValue type for this parameter
199 * @owner_type: #GType type that uses (introduces) this parameter
201 * All other fields of the <structname>GParamSpec</structname> struct are private and
202 * should not be used directly.
204 struct _GParamSpec
206 GTypeInstance g_type_instance;
208 const gchar *name; /* interned string */
209 GParamFlags flags;
210 GType value_type;
211 GType owner_type; /* class or interface using this property */
213 /*< private >*/
214 gchar *_nick;
215 gchar *_blurb;
216 GData *qdata;
217 guint ref_count;
218 guint param_id; /* sort-criteria */
221 * GParamSpecClass:
222 * @g_type_class: the parent class
223 * @value_type: the #GValue type for this parameter
224 * @finalize: The instance finalization function (optional), should chain
225 * up to the finalize method of the parent class.
226 * @value_set_default: Resets a @value to the default value for this type
227 * (recommended, the default is g_value_reset()), see
228 * g_param_value_set_default().
229 * @value_validate: Ensures that the contents of @value comply with the
230 * specifications set out by this type (optional), see
231 * g_param_value_validate().
232 * @values_cmp: Compares @value1 with @value2 according to this type
233 * (recommended, the default is memcmp()), see g_param_values_cmp().
235 * The class structure for the <structname>GParamSpec</structname> type.
236 * Normally, <structname>GParamSpec</structname> classes are filled by
237 * g_param_type_register_static().
239 struct _GParamSpecClass
241 GTypeClass g_type_class;
243 GType value_type;
245 void (*finalize) (GParamSpec *pspec);
247 /* GParam methods */
248 void (*value_set_default) (GParamSpec *pspec,
249 GValue *value);
250 gboolean (*value_validate) (GParamSpec *pspec,
251 GValue *value);
252 gint (*values_cmp) (GParamSpec *pspec,
253 const GValue *value1,
254 const GValue *value2);
255 /*< private >*/
256 gpointer dummy[4];
259 * GParameter:
260 * @name: the parameter name
261 * @value: the parameter value
263 * The <structname>GParameter</structname> struct is an auxiliary structure used
264 * to hand parameter name/value pairs to g_object_newv().
266 struct _GParameter /* auxiliary structure for _setv() variants */
268 const gchar *name;
269 GValue value;
273 /* --- prototypes --- */
274 GLIB_AVAILABLE_IN_ALL
275 GParamSpec* g_param_spec_ref (GParamSpec *pspec);
276 GLIB_AVAILABLE_IN_ALL
277 void g_param_spec_unref (GParamSpec *pspec);
278 GLIB_AVAILABLE_IN_ALL
279 void g_param_spec_sink (GParamSpec *pspec);
280 GLIB_AVAILABLE_IN_ALL
281 GParamSpec* g_param_spec_ref_sink (GParamSpec *pspec);
282 GLIB_AVAILABLE_IN_ALL
283 gpointer g_param_spec_get_qdata (GParamSpec *pspec,
284 GQuark quark);
285 GLIB_AVAILABLE_IN_ALL
286 void g_param_spec_set_qdata (GParamSpec *pspec,
287 GQuark quark,
288 gpointer data);
289 GLIB_AVAILABLE_IN_ALL
290 void g_param_spec_set_qdata_full (GParamSpec *pspec,
291 GQuark quark,
292 gpointer data,
293 GDestroyNotify destroy);
294 GLIB_AVAILABLE_IN_ALL
295 gpointer g_param_spec_steal_qdata (GParamSpec *pspec,
296 GQuark quark);
297 GLIB_AVAILABLE_IN_ALL
298 GParamSpec* g_param_spec_get_redirect_target (GParamSpec *pspec);
300 GLIB_AVAILABLE_IN_ALL
301 void g_param_value_set_default (GParamSpec *pspec,
302 GValue *value);
303 GLIB_AVAILABLE_IN_ALL
304 gboolean g_param_value_defaults (GParamSpec *pspec,
305 GValue *value);
306 GLIB_AVAILABLE_IN_ALL
307 gboolean g_param_value_validate (GParamSpec *pspec,
308 GValue *value);
309 GLIB_AVAILABLE_IN_ALL
310 gboolean g_param_value_convert (GParamSpec *pspec,
311 const GValue *src_value,
312 GValue *dest_value,
313 gboolean strict_validation);
314 GLIB_AVAILABLE_IN_ALL
315 gint g_param_values_cmp (GParamSpec *pspec,
316 const GValue *value1,
317 const GValue *value2);
318 GLIB_AVAILABLE_IN_ALL
319 const gchar * g_param_spec_get_name (GParamSpec *pspec);
320 GLIB_AVAILABLE_IN_ALL
321 const gchar * g_param_spec_get_nick (GParamSpec *pspec);
322 GLIB_AVAILABLE_IN_ALL
323 const gchar * g_param_spec_get_blurb (GParamSpec *pspec);
324 GLIB_AVAILABLE_IN_ALL
325 void g_value_set_param (GValue *value,
326 GParamSpec *param);
327 GLIB_AVAILABLE_IN_ALL
328 GParamSpec* g_value_get_param (const GValue *value);
329 GLIB_AVAILABLE_IN_ALL
330 GParamSpec* g_value_dup_param (const GValue *value);
333 GLIB_AVAILABLE_IN_ALL
334 void g_value_take_param (GValue *value,
335 GParamSpec *param);
336 GLIB_DEPRECATED_FOR(g_value_take_param)
337 void g_value_set_param_take_ownership (GValue *value,
338 GParamSpec *param);
339 GLIB_AVAILABLE_IN_2_36
340 const GValue * g_param_spec_get_default_value (GParamSpec *param);
342 /* --- convenience functions --- */
343 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
345 * GParamSpecTypeInfo:
346 * @instance_size: Size of the instance (object) structure.
347 * @n_preallocs: Prior to GLib 2.10, it specified the number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching). Since GLib 2.10, it is ignored, since instances are allocated with the <link linkend="glib-Memory-Slices">slice allocator</link> now.
348 * @instance_init: Location of the instance initialization function (optional).
349 * @value_type: The #GType of values conforming to this #GParamSpec
350 * @finalize: The instance finalization function (optional).
351 * @value_set_default: Resets a @value to the default value for @pspec
352 * (recommended, the default is g_value_reset()), see
353 * g_param_value_set_default().
354 * @value_validate: Ensures that the contents of @value comply with the
355 * specifications set out by @pspec (optional), see
356 * g_param_value_validate().
357 * @values_cmp: Compares @value1 with @value2 according to @pspec
358 * (recommended, the default is memcmp()), see g_param_values_cmp().
360 * This structure is used to provide the type system with the information
361 * required to initialize and destruct (finalize) a parameter's class and
362 * instances thereof.
363 * The initialized structure is passed to the g_param_type_register_static()
364 * The type system will perform a deep copy of this structure, so its memory
365 * does not need to be persistent across invocation of
366 * g_param_type_register_static().
368 struct _GParamSpecTypeInfo
370 /* type system portion */
371 guint16 instance_size; /* obligatory */
372 guint16 n_preallocs; /* optional */
373 void (*instance_init) (GParamSpec *pspec); /* optional */
375 /* class portion */
376 GType value_type; /* obligatory */
377 void (*finalize) (GParamSpec *pspec); /* optional */
378 void (*value_set_default) (GParamSpec *pspec, /* recommended */
379 GValue *value);
380 gboolean (*value_validate) (GParamSpec *pspec, /* optional */
381 GValue *value);
382 gint (*values_cmp) (GParamSpec *pspec, /* recommended */
383 const GValue *value1,
384 const GValue *value2);
386 GLIB_AVAILABLE_IN_ALL
387 GType g_param_type_register_static (const gchar *name,
388 const GParamSpecTypeInfo *pspec_info);
390 /* For registering builting types */
391 GType _g_param_type_register_static_constant (const gchar *name,
392 const GParamSpecTypeInfo *pspec_info,
393 GType opt_type);
396 /* --- protected --- */
397 GLIB_AVAILABLE_IN_ALL
398 gpointer g_param_spec_internal (GType param_type,
399 const gchar *name,
400 const gchar *nick,
401 const gchar *blurb,
402 GParamFlags flags);
403 GLIB_AVAILABLE_IN_ALL
404 GParamSpecPool* g_param_spec_pool_new (gboolean type_prefixing);
405 GLIB_AVAILABLE_IN_ALL
406 void g_param_spec_pool_insert (GParamSpecPool *pool,
407 GParamSpec *pspec,
408 GType owner_type);
409 GLIB_AVAILABLE_IN_ALL
410 void g_param_spec_pool_remove (GParamSpecPool *pool,
411 GParamSpec *pspec);
412 GLIB_AVAILABLE_IN_ALL
413 GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool,
414 const gchar *param_name,
415 GType owner_type,
416 gboolean walk_ancestors);
417 GLIB_AVAILABLE_IN_ALL
418 GList* g_param_spec_pool_list_owned (GParamSpecPool *pool,
419 GType owner_type);
420 GLIB_AVAILABLE_IN_ALL
421 GParamSpec** g_param_spec_pool_list (GParamSpecPool *pool,
422 GType owner_type,
423 guint *n_pspecs_p);
426 /* contracts:
428 * gboolean value_validate (GParamSpec *pspec,
429 * GValue *value):
430 * modify value contents in the least destructive way, so
431 * that it complies with pspec's requirements (i.e.
432 * according to minimum/maximum ranges etc...). return
433 * whether modification was necessary.
435 * gint values_cmp (GParamSpec *pspec,
436 * const GValue *value1,
437 * const GValue *value2):
438 * return value1 - value2, i.e. (-1) if value1 < value2,
439 * (+1) if value1 > value2, and (0) otherwise (equality)
442 G_END_DECLS
444 #endif /* __G_PARAM_H__ */