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, see <http://www.gnu.org/licenses/>.
17 * gparam.h: GParamSpec base class implementation
22 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
23 #error "Only <glib-object.h> can be included directly."
26 #include <gobject/gvalue.h>
30 /* --- standard type macros --- */
35 * Checks whether @type "is a" %G_TYPE_PARAM.
37 #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
40 * @pspec: a valid #GParamSpec
42 * Casts a derived #GParamSpec object (e.g. of type #GParamSpecInt) into
43 * a #GParamSpec object.
45 #define G_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM, GParamSpec))
48 * @pspec: a #GParamSpec
50 * Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM
53 #if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_42
54 #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_FUNDAMENTAL_TYPE ((pspec), G_TYPE_PARAM))
56 #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM))
60 * @pclass: a valid #GParamSpecClass
62 * Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure.
64 #define G_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_CAST ((pclass), G_TYPE_PARAM, GParamSpecClass))
66 * G_IS_PARAM_SPEC_CLASS:
67 * @pclass: a #GParamSpecClass
69 * Checks whether @pclass "is a" valid #GParamSpecClass structure of type
70 * %G_TYPE_PARAM or derived.
72 #define G_IS_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_TYPE ((pclass), G_TYPE_PARAM))
74 * G_PARAM_SPEC_GET_CLASS:
75 * @pspec: a valid #GParamSpec
77 * Retrieves the #GParamSpecClass of a #GParamSpec.
79 #define G_PARAM_SPEC_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass))
82 /* --- convenience macros --- */
85 * @pspec: a valid #GParamSpec
87 * Retrieves the #GType of this @pspec.
89 #define G_PARAM_SPEC_TYPE(pspec) (G_TYPE_FROM_INSTANCE (pspec))
91 * G_PARAM_SPEC_TYPE_NAME:
92 * @pspec: a valid #GParamSpec
94 * Retrieves the #GType name of this @pspec.
96 #define G_PARAM_SPEC_TYPE_NAME(pspec) (g_type_name (G_PARAM_SPEC_TYPE (pspec)))
98 * G_PARAM_SPEC_VALUE_TYPE:
99 * @pspec: a valid #GParamSpec
101 * Retrieves the #GType to initialize a #GValue for this parameter.
103 #define G_PARAM_SPEC_VALUE_TYPE(pspec) (G_PARAM_SPEC (pspec)->value_type)
105 * G_VALUE_HOLDS_PARAM:
106 * @value: a valid #GValue structure
108 * Checks whether the given #GValue can hold values derived from type %G_TYPE_PARAM.
110 * Returns: %TRUE on success.
112 #define G_VALUE_HOLDS_PARAM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM))
118 * @G_PARAM_READABLE: the parameter is readable
119 * @G_PARAM_WRITABLE: the parameter is writable
120 * @G_PARAM_READWRITE: alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE
121 * @G_PARAM_CONSTRUCT: the parameter will be set upon object construction
122 * @G_PARAM_CONSTRUCT_ONLY: the parameter can only be set upon object construction
123 * @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert())
124 * strict validation is not required
125 * @G_PARAM_STATIC_NAME: the string used as name when constructing the
126 * parameter is guaranteed to remain valid and
127 * unmodified for the lifetime of the parameter.
129 * @G_PARAM_STATIC_NICK: the string used as nick when constructing the
130 * parameter is guaranteed to remain valid and
131 * unmmodified for the lifetime of the parameter.
133 * @G_PARAM_STATIC_BLURB: the string used as blurb when constructing the
134 * parameter is guaranteed to remain valid and
135 * unmodified for the lifetime of the parameter.
137 * @G_PARAM_EXPLICIT_NOTIFY: calls to g_object_set_property() for this
138 * property will not automatically result in a "notify" signal being
139 * emitted: the implementation must call g_object_notify() themselves
140 * in case the property actually changes. Since: 2.42.
141 * @G_PARAM_PRIVATE: internal
142 * @G_PARAM_DEPRECATED: the parameter is deprecated and will be removed
143 * in a future version. A warning will be generated if it is used
144 * while running with G_ENABLE_DIAGNOSTIC=1.
147 * Through the #GParamFlags flag values, certain aspects of parameters
148 * can be configured. See also #G_PARAM_STATIC_STRINGS.
152 G_PARAM_READABLE = 1 << 0,
153 G_PARAM_WRITABLE = 1 << 1,
154 G_PARAM_READWRITE = (G_PARAM_READABLE | G_PARAM_WRITABLE),
155 G_PARAM_CONSTRUCT = 1 << 2,
156 G_PARAM_CONSTRUCT_ONLY = 1 << 3,
157 G_PARAM_LAX_VALIDATION = 1 << 4,
158 G_PARAM_STATIC_NAME = 1 << 5,
159 #ifndef G_DISABLE_DEPRECATED
160 G_PARAM_PRIVATE = G_PARAM_STATIC_NAME,
162 G_PARAM_STATIC_NICK = 1 << 6,
163 G_PARAM_STATIC_BLURB = 1 << 7,
164 /* User defined flags go here */
165 G_PARAM_EXPLICIT_NOTIFY = 1 << 30,
166 G_PARAM_DEPRECATED = 1 << 31
170 * G_PARAM_STATIC_STRINGS:
172 * #GParamFlags value alias for %G_PARAM_STATIC_NAME | %G_PARAM_STATIC_NICK | %G_PARAM_STATIC_BLURB.
176 #define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
177 /* bits in the range 0xffffff00 are reserved for 3rd party usage */
181 * Mask containing the bits of #GParamSpec.flags which are reserved for GLib.
183 #define G_PARAM_MASK (0x000000ff)
185 * G_PARAM_USER_SHIFT:
187 * Minimum shift count to be used for user defined flags, to be stored in
188 * #GParamSpec.flags. The maximum allowed is 10.
190 #define G_PARAM_USER_SHIFT (8)
192 /* --- typedefs & structures --- */
193 typedef struct _GParamSpec GParamSpec;
194 typedef struct _GParamSpecClass GParamSpecClass;
195 typedef struct _GParameter GParameter;
196 typedef struct _GParamSpecPool GParamSpecPool;
199 * @g_type_instance: private #GTypeInstance portion
200 * @name: name of this parameter: always an interned string
201 * @flags: #GParamFlags flags for this parameter
202 * @value_type: the #GValue type for this parameter
203 * @owner_type: #GType type that uses (introduces) this parameter
205 * All other fields of the GParamSpec struct are private and
206 * should not be used directly.
210 GTypeInstance g_type_instance;
212 const gchar *name; /* interned string */
215 GType owner_type; /* class or interface using this property */
222 guint param_id; /* sort-criteria */
226 * @g_type_class: the parent class
227 * @value_type: the #GValue type for this parameter
228 * @finalize: The instance finalization function (optional), should chain
229 * up to the finalize method of the parent class.
230 * @value_set_default: Resets a @value to the default value for this type
231 * (recommended, the default is g_value_reset()), see
232 * g_param_value_set_default().
233 * @value_validate: Ensures that the contents of @value comply with the
234 * specifications set out by this type (optional), see
235 * g_param_value_validate().
236 * @values_cmp: Compares @value1 with @value2 according to this type
237 * (recommended, the default is memcmp()), see g_param_values_cmp().
239 * The class structure for the GParamSpec type.
240 * Normally, GParamSpec classes are filled by
241 * g_param_type_register_static().
243 struct _GParamSpecClass
245 GTypeClass g_type_class;
249 void (*finalize) (GParamSpec *pspec);
252 void (*value_set_default) (GParamSpec *pspec,
254 gboolean (*value_validate) (GParamSpec *pspec,
256 gint (*values_cmp) (GParamSpec *pspec,
257 const GValue *value1,
258 const GValue *value2);
264 * @name: the parameter name
265 * @value: the parameter value
267 * The GParameter struct is an auxiliary structure used
268 * to hand parameter name/value pairs to g_object_newv().
270 struct _GParameter /* auxiliary structure for _setv() variants */
277 /* --- prototypes --- */
278 GLIB_AVAILABLE_IN_ALL
279 GParamSpec* g_param_spec_ref (GParamSpec *pspec);
280 GLIB_AVAILABLE_IN_ALL
281 void g_param_spec_unref (GParamSpec *pspec);
282 GLIB_AVAILABLE_IN_ALL
283 void g_param_spec_sink (GParamSpec *pspec);
284 GLIB_AVAILABLE_IN_ALL
285 GParamSpec* g_param_spec_ref_sink (GParamSpec *pspec);
286 GLIB_AVAILABLE_IN_ALL
287 gpointer g_param_spec_get_qdata (GParamSpec *pspec,
289 GLIB_AVAILABLE_IN_ALL
290 void g_param_spec_set_qdata (GParamSpec *pspec,
293 GLIB_AVAILABLE_IN_ALL
294 void g_param_spec_set_qdata_full (GParamSpec *pspec,
297 GDestroyNotify destroy);
298 GLIB_AVAILABLE_IN_ALL
299 gpointer g_param_spec_steal_qdata (GParamSpec *pspec,
301 GLIB_AVAILABLE_IN_ALL
302 GParamSpec* g_param_spec_get_redirect_target (GParamSpec *pspec);
304 GLIB_AVAILABLE_IN_ALL
305 void g_param_value_set_default (GParamSpec *pspec,
307 GLIB_AVAILABLE_IN_ALL
308 gboolean g_param_value_defaults (GParamSpec *pspec,
310 GLIB_AVAILABLE_IN_ALL
311 gboolean g_param_value_validate (GParamSpec *pspec,
313 GLIB_AVAILABLE_IN_ALL
314 gboolean g_param_value_convert (GParamSpec *pspec,
315 const GValue *src_value,
317 gboolean strict_validation);
318 GLIB_AVAILABLE_IN_ALL
319 gint g_param_values_cmp (GParamSpec *pspec,
320 const GValue *value1,
321 const GValue *value2);
322 GLIB_AVAILABLE_IN_ALL
323 const gchar * g_param_spec_get_name (GParamSpec *pspec);
324 GLIB_AVAILABLE_IN_ALL
325 const gchar * g_param_spec_get_nick (GParamSpec *pspec);
326 GLIB_AVAILABLE_IN_ALL
327 const gchar * g_param_spec_get_blurb (GParamSpec *pspec);
328 GLIB_AVAILABLE_IN_ALL
329 void g_value_set_param (GValue *value,
331 GLIB_AVAILABLE_IN_ALL
332 GParamSpec* g_value_get_param (const GValue *value);
333 GLIB_AVAILABLE_IN_ALL
334 GParamSpec* g_value_dup_param (const GValue *value);
337 GLIB_AVAILABLE_IN_ALL
338 void g_value_take_param (GValue *value,
340 GLIB_DEPRECATED_FOR(g_value_take_param)
341 void g_value_set_param_take_ownership (GValue *value,
343 GLIB_AVAILABLE_IN_2_36
344 const GValue * g_param_spec_get_default_value (GParamSpec *param);
346 /* --- convenience functions --- */
347 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
349 * GParamSpecTypeInfo:
350 * @instance_size: Size of the instance (object) structure.
351 * @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 [slice allocator][glib-Memory-Slices] now.
352 * @instance_init: Location of the instance initialization function (optional).
353 * @value_type: The #GType of values conforming to this #GParamSpec
354 * @finalize: The instance finalization function (optional).
355 * @value_set_default: Resets a @value to the default value for @pspec
356 * (recommended, the default is g_value_reset()), see
357 * g_param_value_set_default().
358 * @value_validate: Ensures that the contents of @value comply with the
359 * specifications set out by @pspec (optional), see
360 * g_param_value_validate().
361 * @values_cmp: Compares @value1 with @value2 according to @pspec
362 * (recommended, the default is memcmp()), see g_param_values_cmp().
364 * This structure is used to provide the type system with the information
365 * required to initialize and destruct (finalize) a parameter's class and
367 * The initialized structure is passed to the g_param_type_register_static()
368 * The type system will perform a deep copy of this structure, so its memory
369 * does not need to be persistent across invocation of
370 * g_param_type_register_static().
372 struct _GParamSpecTypeInfo
374 /* type system portion */
375 guint16 instance_size; /* obligatory */
376 guint16 n_preallocs; /* optional */
377 void (*instance_init) (GParamSpec *pspec); /* optional */
380 GType value_type; /* obligatory */
381 void (*finalize) (GParamSpec *pspec); /* optional */
382 void (*value_set_default) (GParamSpec *pspec, /* recommended */
384 gboolean (*value_validate) (GParamSpec *pspec, /* optional */
386 gint (*values_cmp) (GParamSpec *pspec, /* recommended */
387 const GValue *value1,
388 const GValue *value2);
390 GLIB_AVAILABLE_IN_ALL
391 GType g_param_type_register_static (const gchar *name,
392 const GParamSpecTypeInfo *pspec_info);
394 /* For registering builting types */
395 GType _g_param_type_register_static_constant (const gchar *name,
396 const GParamSpecTypeInfo *pspec_info,
400 /* --- protected --- */
401 GLIB_AVAILABLE_IN_ALL
402 gpointer g_param_spec_internal (GType param_type,
407 GLIB_AVAILABLE_IN_ALL
408 GParamSpecPool* g_param_spec_pool_new (gboolean type_prefixing);
409 GLIB_AVAILABLE_IN_ALL
410 void g_param_spec_pool_insert (GParamSpecPool *pool,
413 GLIB_AVAILABLE_IN_ALL
414 void g_param_spec_pool_remove (GParamSpecPool *pool,
416 GLIB_AVAILABLE_IN_ALL
417 GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool,
418 const gchar *param_name,
420 gboolean walk_ancestors);
421 GLIB_AVAILABLE_IN_ALL
422 GList* g_param_spec_pool_list_owned (GParamSpecPool *pool,
424 GLIB_AVAILABLE_IN_ALL
425 GParamSpec** g_param_spec_pool_list (GParamSpecPool *pool,
432 * gboolean value_validate (GParamSpec *pspec,
434 * modify value contents in the least destructive way, so
435 * that it complies with pspec's requirements (i.e.
436 * according to minimum/maximum ranges etc...). return
437 * whether modification was necessary.
439 * gint values_cmp (GParamSpec *pspec,
440 * const GValue *value1,
441 * const GValue *value2):
442 * return value1 - value2, i.e. (-1) if value1 < value2,
443 * (+1) if value1 > value2, and (0) otherwise (equality)
448 #endif /* __G_PARAM_H__ */