menu threaded test: run the mainloop after export
[glib.git] / gobject / gparam.h
blob8357477810d94256a0c5b8eec4c72510b3a95d8a
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 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
22 #error "Only <glib-object.h> can be included directly."
23 #endif
25 #ifndef __G_PARAM_H__
26 #define __G_PARAM_H__
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.
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 GParamSpec* g_param_spec_ref (GParamSpec *pspec);
275 void g_param_spec_unref (GParamSpec *pspec);
276 void g_param_spec_sink (GParamSpec *pspec);
277 GParamSpec* g_param_spec_ref_sink (GParamSpec *pspec);
278 gpointer g_param_spec_get_qdata (GParamSpec *pspec,
279 GQuark quark);
280 void g_param_spec_set_qdata (GParamSpec *pspec,
281 GQuark quark,
282 gpointer data);
283 void g_param_spec_set_qdata_full (GParamSpec *pspec,
284 GQuark quark,
285 gpointer data,
286 GDestroyNotify destroy);
287 gpointer g_param_spec_steal_qdata (GParamSpec *pspec,
288 GQuark quark);
289 GParamSpec* g_param_spec_get_redirect_target (GParamSpec *pspec);
291 void g_param_value_set_default (GParamSpec *pspec,
292 GValue *value);
293 gboolean g_param_value_defaults (GParamSpec *pspec,
294 GValue *value);
295 gboolean g_param_value_validate (GParamSpec *pspec,
296 GValue *value);
297 gboolean g_param_value_convert (GParamSpec *pspec,
298 const GValue *src_value,
299 GValue *dest_value,
300 gboolean strict_validation);
301 gint g_param_values_cmp (GParamSpec *pspec,
302 const GValue *value1,
303 const GValue *value2);
304 const gchar * g_param_spec_get_name (GParamSpec *pspec);
305 const gchar * g_param_spec_get_nick (GParamSpec *pspec);
306 const gchar * g_param_spec_get_blurb (GParamSpec *pspec);
307 void g_value_set_param (GValue *value,
308 GParamSpec *param);
309 GParamSpec* g_value_get_param (const GValue *value);
310 GParamSpec* g_value_dup_param (const GValue *value);
313 void g_value_take_param (GValue *value,
314 GParamSpec *param);
315 GLIB_DEPRECATED_FOR(g_value_take_param)
316 void g_value_set_param_take_ownership (GValue *value,
317 GParamSpec *param);
319 /* --- convenience functions --- */
320 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
322 * GParamSpecTypeInfo:
323 * @instance_size: Size of the instance (object) structure.
324 * @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.
325 * @instance_init: Location of the instance initialization function (optional).
326 * @value_type: The #GType of values conforming to this #GParamSpec
327 * @finalize: The instance finalization function (optional).
328 * @value_set_default: Resets a @value to the default value for @pspec
329 * (recommended, the default is g_value_reset()), see
330 * g_param_value_set_default().
331 * @value_validate: Ensures that the contents of @value comply with the
332 * specifications set out by @pspec (optional), see
333 * g_param_value_validate().
334 * @values_cmp: Compares @value1 with @value2 according to @pspec
335 * (recommended, the default is memcmp()), see g_param_values_cmp().
337 * This structure is used to provide the type system with the information
338 * required to initialize and destruct (finalize) a parameter's class and
339 * instances thereof.
340 * The initialized structure is passed to the g_param_type_register_static()
341 * The type system will perform a deep copy of this structure, so its memory
342 * does not need to be persistent across invocation of
343 * g_param_type_register_static().
345 struct _GParamSpecTypeInfo
347 /* type system portion */
348 guint16 instance_size; /* obligatory */
349 guint16 n_preallocs; /* optional */
350 void (*instance_init) (GParamSpec *pspec); /* optional */
352 /* class portion */
353 GType value_type; /* obligatory */
354 void (*finalize) (GParamSpec *pspec); /* optional */
355 void (*value_set_default) (GParamSpec *pspec, /* recommended */
356 GValue *value);
357 gboolean (*value_validate) (GParamSpec *pspec, /* optional */
358 GValue *value);
359 gint (*values_cmp) (GParamSpec *pspec, /* recommended */
360 const GValue *value1,
361 const GValue *value2);
363 GType g_param_type_register_static (const gchar *name,
364 const GParamSpecTypeInfo *pspec_info);
366 /* For registering builting types */
367 GType _g_param_type_register_static_constant (const gchar *name,
368 const GParamSpecTypeInfo *pspec_info,
369 GType opt_type);
372 /* --- protected --- */
373 gpointer g_param_spec_internal (GType param_type,
374 const gchar *name,
375 const gchar *nick,
376 const gchar *blurb,
377 GParamFlags flags);
378 GParamSpecPool* g_param_spec_pool_new (gboolean type_prefixing);
379 void g_param_spec_pool_insert (GParamSpecPool *pool,
380 GParamSpec *pspec,
381 GType owner_type);
382 void g_param_spec_pool_remove (GParamSpecPool *pool,
383 GParamSpec *pspec);
384 GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool,
385 const gchar *param_name,
386 GType owner_type,
387 gboolean walk_ancestors);
388 GList* g_param_spec_pool_list_owned (GParamSpecPool *pool,
389 GType owner_type);
390 GParamSpec** g_param_spec_pool_list (GParamSpecPool *pool,
391 GType owner_type,
392 guint *n_pspecs_p);
396 /* contracts:
398 * gboolean value_validate (GParamSpec *pspec,
399 * GValue *value):
400 * modify value contents in the least destructive way, so
401 * that it complies with pspec's requirements (i.e.
402 * according to minimum/maximum ranges etc...). return
403 * whether modification was necessary.
405 * gint values_cmp (GParamSpec *pspec,
406 * const GValue *value1,
407 * const GValue *value2):
408 * return value1 - value2, i.e. (-1) if value1 < value2,
409 * (+1) if value1 > value2, and (0) otherwise (equality)
412 G_END_DECLS
414 #endif /* __G_PARAM_H__ */