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."
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)
102 #define G_VALUE_HOLDS_PARAM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM))
108 * @G_PARAM_READABLE: the parameter is readable
109 * @G_PARAM_WRITABLE: the parameter is writable
110 * @G_PARAM_CONSTRUCT: the parameter will be set upon object construction
111 * @G_PARAM_CONSTRUCT_ONLY: the parameter will only be set upon object construction
112 * @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert())
113 * strict validation is not required
114 * @G_PARAM_STATIC_NAME: the string used as name when constructing the
115 * parameter is guaranteed to remain valid and
116 * unmodified for the lifetime of the parameter.
118 * @G_PARAM_STATIC_NICK: the string used as nick when constructing the
119 * parameter is guaranteed to remain valid and
120 * unmmodified for the lifetime of the parameter.
122 * @G_PARAM_STATIC_BLURB: the string used as blurb when constructing the
123 * parameter is guaranteed to remain valid and
124 * unmodified for the lifetime of the parameter.
126 * @G_PARAM_PRIVATE: internal
128 * Through the #GParamFlags flag values, certain aspects of parameters
133 G_PARAM_READABLE = 1 << 0,
134 G_PARAM_WRITABLE = 1 << 1,
135 G_PARAM_CONSTRUCT = 1 << 2,
136 G_PARAM_CONSTRUCT_ONLY = 1 << 3,
137 G_PARAM_LAX_VALIDATION = 1 << 4,
138 G_PARAM_STATIC_NAME = 1 << 5,
139 #ifndef G_DISABLE_DEPRECATED
140 G_PARAM_PRIVATE = G_PARAM_STATIC_NAME,
142 G_PARAM_STATIC_NICK = 1 << 6,
143 G_PARAM_STATIC_BLURB = 1 << 7
148 * #GParamFlags value alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE.
150 #define G_PARAM_READWRITE (G_PARAM_READABLE | G_PARAM_WRITABLE)
152 * G_PARAM_STATIC_STRINGS:
154 * #GParamFlags value alias for %G_PARAM_STATIC_NAME | %G_PARAM_STATIC_NICK | %G_PARAM_STATIC_BLURB.
158 #define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
159 /* bits in the range 0xffffff00 are reserved for 3rd party usage */
163 * Mask containing the bits of #GParamSpec.flags which are reserved for GLib.
165 #define G_PARAM_MASK (0x000000ff)
167 * G_PARAM_USER_SHIFT:
169 * Minimum shift count to be used for user defined flags, to be stored in
172 #define G_PARAM_USER_SHIFT (8)
175 /* --- typedefs & structures --- */
176 typedef struct _GParamSpec GParamSpec;
177 typedef struct _GParamSpecClass GParamSpecClass;
178 typedef struct _GParameter GParameter;
179 typedef struct _GParamSpecPool GParamSpecPool;
182 * @g_type_instance: private #GTypeInstance portion
183 * @name: name of this parameter
184 * @flags: #GParamFlags flags for this parameter
185 * @value_type: the #GValue type for this parameter
186 * @owner_type: #GType type that uses (introduces) this paremeter
188 * All other fields of the <structname>GParamSpec</structname> struct are private and
189 * should not be used directly.
193 GTypeInstance g_type_instance;
198 GType owner_type; /* class or interface using this property */
205 guint param_id; /* sort-criteria */
209 * @g_type_class: the parent class
210 * @value_type: the #GValue type for this parameter
211 * @finalize: The instance finalization function (optional), should chain
212 * up to the finalize method of the parent class.
213 * @value_set_default: Resets a @value to the default value for this type
214 * (recommended, the default is g_value_reset()), see
215 * g_param_value_set_default().
216 * @value_validate: Ensures that the contents of @value comply with the
217 * specifications set out by this type (optional), see
218 * g_param_value_set_validate().
219 * @values_cmp: Compares @value1 with @value2 according to this type
220 * (recommended, the default is memcmp()), see g_param_values_cmp().
222 * The class structure for the <structname>GParamSpec</structname> type.
223 * Normally, <structname>GParamSpec</structname> classes are filled by
224 * g_param_type_register_static().
226 struct _GParamSpecClass
228 GTypeClass g_type_class;
232 void (*finalize) (GParamSpec *pspec);
235 void (*value_set_default) (GParamSpec *pspec,
237 gboolean (*value_validate) (GParamSpec *pspec,
239 gint (*values_cmp) (GParamSpec *pspec,
240 const GValue *value1,
241 const GValue *value2);
245 struct _GParameter /* auxillary structure for _setv() variants */
252 /* --- prototypes --- */
253 GParamSpec* g_param_spec_ref (GParamSpec *pspec);
254 void g_param_spec_unref (GParamSpec *pspec);
255 void g_param_spec_sink (GParamSpec *pspec);
256 GParamSpec* g_param_spec_ref_sink (GParamSpec *pspec);
257 gpointer g_param_spec_get_qdata (GParamSpec *pspec,
259 void g_param_spec_set_qdata (GParamSpec *pspec,
262 void g_param_spec_set_qdata_full (GParamSpec *pspec,
265 GDestroyNotify destroy);
266 gpointer g_param_spec_steal_qdata (GParamSpec *pspec,
268 GParamSpec* g_param_spec_get_redirect_target (GParamSpec *pspec);
270 void g_param_value_set_default (GParamSpec *pspec,
272 gboolean g_param_value_defaults (GParamSpec *pspec,
274 gboolean g_param_value_validate (GParamSpec *pspec,
276 gboolean g_param_value_convert (GParamSpec *pspec,
277 const GValue *src_value,
279 gboolean strict_validation);
280 gint g_param_values_cmp (GParamSpec *pspec,
281 const GValue *value1,
282 const GValue *value2);
283 G_CONST_RETURN gchar* g_param_spec_get_name (GParamSpec *pspec);
284 G_CONST_RETURN gchar* g_param_spec_get_nick (GParamSpec *pspec);
285 G_CONST_RETURN gchar* g_param_spec_get_blurb (GParamSpec *pspec);
286 void g_value_set_param (GValue *value,
288 GParamSpec* g_value_get_param (const GValue *value);
289 GParamSpec* g_value_dup_param (const GValue *value);
292 void g_value_take_param (GValue *value,
294 #ifndef G_DISABLE_DEPRECATED
295 void g_value_set_param_take_ownership (GValue *value,
299 /* --- convenience functions --- */
300 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
302 * GParamSpecTypeInfo:
303 * @instance_size: Size of the instance (object) structure.
304 * @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.
305 * @instance_init: Location of the instance initialization function (optional).
306 * @value_type: The #GType of values conforming to this #GParamSpec
307 * @finalize: The instance finalization function (optional).
308 * @value_set_default: Resets a @value to the default value for @pspec
309 * (recommended, the default is g_value_reset()), see
310 * g_param_value_set_default().
311 * @value_validate: Ensures that the contents of @value comply with the
312 * specifications set out by @pspec (optional), see
313 * g_param_value_set_validate().
314 * @values_cmp: Compares @value1 with @value2 according to @pspec
315 * (recommended, the default is memcmp()), see g_param_values_cmp().
317 * This structure is used to provide the type system with the information
318 * required to initialize and destruct (finalize) a parameter's class and
320 * The initialized structure is passed to the g_param_type_register_static()
321 * The type system will perform a deep copy of this structure, so it's memory
322 * does not need to be persistent across invocation of
323 * g_param_type_register_static().
325 struct _GParamSpecTypeInfo
327 /* type system portion */
328 guint16 instance_size; /* obligatory */
329 guint16 n_preallocs; /* optional */
330 void (*instance_init) (GParamSpec *pspec); /* optional */
333 GType value_type; /* obligatory */
334 void (*finalize) (GParamSpec *pspec); /* optional */
335 void (*value_set_default) (GParamSpec *pspec, /* recommended */
337 gboolean (*value_validate) (GParamSpec *pspec, /* optional */
339 gint (*values_cmp) (GParamSpec *pspec, /* recommended */
340 const GValue *value1,
341 const GValue *value2);
343 GType g_param_type_register_static (const gchar *name,
344 const GParamSpecTypeInfo *pspec_info);
346 /* For registering builting types */
347 GType _g_param_type_register_static_constant (const gchar *name,
348 const GParamSpecTypeInfo *pspec_info,
352 /* --- protected --- */
353 gpointer g_param_spec_internal (GType param_type,
358 GParamSpecPool* g_param_spec_pool_new (gboolean type_prefixing);
359 void g_param_spec_pool_insert (GParamSpecPool *pool,
362 void g_param_spec_pool_remove (GParamSpecPool *pool,
364 GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool,
365 const gchar *param_name,
367 gboolean walk_ancestors);
368 GList* g_param_spec_pool_list_owned (GParamSpecPool *pool,
370 GParamSpec** g_param_spec_pool_list (GParamSpecPool *pool,
378 * gboolean value_validate (GParamSpec *pspec,
380 * modify value contents in the least destructive way, so
381 * that it complies with pspec's requirements (i.e.
382 * according to minimum/maximum ranges etc...). return
383 * whether modification was necessary.
385 * gint values_cmp (GParamSpec *pspec,
386 * const GValue *value1,
387 * const GValue *value2):
388 * return value1 - value2, i.e. (-1) if value1 < value2,
389 * (+1) if value1 > value2, and (0) otherwise (equality)
394 #endif /* __G_PARAM_H__ */