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
24 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
25 #error "Only <glib-object.h> can be included directly."
28 #include <gobject/gvalue.h>
32 /* --- standard type macros --- */
37 * Checks whether @type "is a" %G_TYPE_PARAM.
39 #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
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))
50 * @pspec: a #GParamSpec
52 * Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM
55 #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM))
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))
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))
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 --- */
83 * @pspec: a valid #GParamSpec
85 * Retrieves the #GType of this @pspec.
87 #define G_PARAM_SPEC_TYPE(pspec) (G_TYPE_FROM_INSTANCE (pspec))
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)))
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))
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.
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.
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.
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.
140 * Through the #GParamFlags flag values, certain aspects of parameters
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,
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
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.
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 */
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;
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.
206 GTypeInstance g_type_instance;
208 const gchar *name; /* interned string */
211 GType owner_type; /* class or interface using this property */
218 guint param_id; /* sort-criteria */
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;
245 void (*finalize) (GParamSpec *pspec);
248 void (*value_set_default) (GParamSpec *pspec,
250 gboolean (*value_validate) (GParamSpec *pspec,
252 gint (*values_cmp) (GParamSpec *pspec,
253 const GValue *value1,
254 const GValue *value2);
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 */
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,
285 GLIB_AVAILABLE_IN_ALL
286 void g_param_spec_set_qdata (GParamSpec *pspec,
289 GLIB_AVAILABLE_IN_ALL
290 void g_param_spec_set_qdata_full (GParamSpec *pspec,
293 GDestroyNotify destroy);
294 GLIB_AVAILABLE_IN_ALL
295 gpointer g_param_spec_steal_qdata (GParamSpec *pspec,
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,
303 GLIB_AVAILABLE_IN_ALL
304 gboolean g_param_value_defaults (GParamSpec *pspec,
306 GLIB_AVAILABLE_IN_ALL
307 gboolean g_param_value_validate (GParamSpec *pspec,
309 GLIB_AVAILABLE_IN_ALL
310 gboolean g_param_value_convert (GParamSpec *pspec,
311 const GValue *src_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,
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,
336 GLIB_DEPRECATED_FOR(g_value_take_param)
337 void g_value_set_param_take_ownership (GValue *value,
340 /* --- convenience functions --- */
341 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
343 * GParamSpecTypeInfo:
344 * @instance_size: Size of the instance (object) structure.
345 * @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.
346 * @instance_init: Location of the instance initialization function (optional).
347 * @value_type: The #GType of values conforming to this #GParamSpec
348 * @finalize: The instance finalization function (optional).
349 * @value_set_default: Resets a @value to the default value for @pspec
350 * (recommended, the default is g_value_reset()), see
351 * g_param_value_set_default().
352 * @value_validate: Ensures that the contents of @value comply with the
353 * specifications set out by @pspec (optional), see
354 * g_param_value_validate().
355 * @values_cmp: Compares @value1 with @value2 according to @pspec
356 * (recommended, the default is memcmp()), see g_param_values_cmp().
358 * This structure is used to provide the type system with the information
359 * required to initialize and destruct (finalize) a parameter's class and
361 * The initialized structure is passed to the g_param_type_register_static()
362 * The type system will perform a deep copy of this structure, so its memory
363 * does not need to be persistent across invocation of
364 * g_param_type_register_static().
366 struct _GParamSpecTypeInfo
368 /* type system portion */
369 guint16 instance_size; /* obligatory */
370 guint16 n_preallocs; /* optional */
371 void (*instance_init) (GParamSpec *pspec); /* optional */
374 GType value_type; /* obligatory */
375 void (*finalize) (GParamSpec *pspec); /* optional */
376 void (*value_set_default) (GParamSpec *pspec, /* recommended */
378 gboolean (*value_validate) (GParamSpec *pspec, /* optional */
380 gint (*values_cmp) (GParamSpec *pspec, /* recommended */
381 const GValue *value1,
382 const GValue *value2);
384 GLIB_AVAILABLE_IN_ALL
385 GType g_param_type_register_static (const gchar *name,
386 const GParamSpecTypeInfo *pspec_info);
388 /* For registering builting types */
389 GType _g_param_type_register_static_constant (const gchar *name,
390 const GParamSpecTypeInfo *pspec_info,
394 /* --- protected --- */
395 GLIB_AVAILABLE_IN_ALL
396 gpointer g_param_spec_internal (GType param_type,
401 GLIB_AVAILABLE_IN_ALL
402 GParamSpecPool* g_param_spec_pool_new (gboolean type_prefixing);
403 GLIB_AVAILABLE_IN_ALL
404 void g_param_spec_pool_insert (GParamSpecPool *pool,
407 GLIB_AVAILABLE_IN_ALL
408 void g_param_spec_pool_remove (GParamSpecPool *pool,
410 GLIB_AVAILABLE_IN_ALL
411 GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool,
412 const gchar *param_name,
414 gboolean walk_ancestors);
415 GLIB_AVAILABLE_IN_ALL
416 GList* g_param_spec_pool_list_owned (GParamSpecPool *pool,
418 GLIB_AVAILABLE_IN_ALL
419 GParamSpec** g_param_spec_pool_list (GParamSpecPool *pool,
427 * gboolean value_validate (GParamSpec *pspec,
429 * modify value contents in the least destructive way, so
430 * that it complies with pspec's requirements (i.e.
431 * according to minimum/maximum ranges etc...). return
432 * whether modification was necessary.
434 * gint values_cmp (GParamSpec *pspec,
435 * const GValue *value1,
436 * const GValue *value2):
437 * return value1 - value2, i.e. (-1) if value1 < value2,
438 * (+1) if value1 > value2, and (0) otherwise (equality)
443 #endif /* __G_PARAM_H__ */