gconvert: add note to avoid transliteration
[glib.git] / gobject / gparam.h
blob68793d18a3ec2f3887d883b763e7ed7ac3e0abf1
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
19 #ifndef __G_PARAM_H__
20 #define __G_PARAM_H__
22 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
23 #error "Only <glib-object.h> can be included directly."
24 #endif
26 #include <gobject/gvalue.h>
28 G_BEGIN_DECLS
30 /* --- standard type macros --- */
31 /**
32 * G_TYPE_IS_PARAM:
33 * @type: a #GType ID
35 * Checks whether @type "is a" %G_TYPE_PARAM.
37 #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
38 /**
39 * G_PARAM_SPEC:
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))
46 /**
47 * G_IS_PARAM_SPEC:
48 * @pspec: a #GParamSpec
50 * Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM
51 * or derived.
53 #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM))
54 /**
55 * G_PARAM_SPEC_CLASS:
56 * @pclass: a valid #GParamSpecClass
58 * Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure.
60 #define G_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_CAST ((pclass), G_TYPE_PARAM, GParamSpecClass))
61 /**
62 * G_IS_PARAM_SPEC_CLASS:
63 * @pclass: a #GParamSpecClass
65 * Checks whether @pclass "is a" valid #GParamSpecClass structure of type
66 * %G_TYPE_PARAM or derived.
68 #define G_IS_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_TYPE ((pclass), G_TYPE_PARAM))
69 /**
70 * G_PARAM_SPEC_GET_CLASS:
71 * @pspec: a valid #GParamSpec
73 * Retrieves the #GParamSpecClass of a #GParamSpec.
75 #define G_PARAM_SPEC_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass))
78 /* --- convenience macros --- */
79 /**
80 * G_PARAM_SPEC_TYPE:
81 * @pspec: a valid #GParamSpec
83 * Retrieves the #GType of this @pspec.
85 #define G_PARAM_SPEC_TYPE(pspec) (G_TYPE_FROM_INSTANCE (pspec))
86 /**
87 * G_PARAM_SPEC_TYPE_NAME:
88 * @pspec: a valid #GParamSpec
90 * Retrieves the #GType name of this @pspec.
92 #define G_PARAM_SPEC_TYPE_NAME(pspec) (g_type_name (G_PARAM_SPEC_TYPE (pspec)))
93 /**
94 * G_PARAM_SPEC_VALUE_TYPE:
95 * @pspec: a valid #GParamSpec
97 * Retrieves the #GType to initialize a #GValue for this parameter.
99 #define G_PARAM_SPEC_VALUE_TYPE(pspec) (G_PARAM_SPEC (pspec)->value_type)
101 * G_VALUE_HOLDS_PARAM:
102 * @value: a valid #GValue structure
104 * Checks whether the given #GValue can hold values derived from type %G_TYPE_PARAM.
106 * Returns: %TRUE on success.
108 #define G_VALUE_HOLDS_PARAM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM))
111 /* --- flags --- */
113 * GParamFlags:
114 * @G_PARAM_READABLE: the parameter is readable
115 * @G_PARAM_WRITABLE: the parameter is writable
116 * @G_PARAM_CONSTRUCT: the parameter will be set upon object construction
117 * @G_PARAM_CONSTRUCT_ONLY: the parameter will only be set upon object construction
118 * @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert())
119 * strict validation is not required
120 * @G_PARAM_STATIC_NAME: the string used as name when constructing the
121 * parameter is guaranteed to remain valid and
122 * unmodified for the lifetime of the parameter.
123 * Since 2.8
124 * @G_PARAM_STATIC_NICK: the string used as nick when constructing the
125 * parameter is guaranteed to remain valid and
126 * unmmodified for the lifetime of the parameter.
127 * Since 2.8
128 * @G_PARAM_STATIC_BLURB: the string used as blurb when constructing the
129 * parameter is guaranteed to remain valid and
130 * unmodified for the lifetime of the parameter.
131 * Since 2.8
132 * @G_PARAM_PRIVATE: internal
133 * @G_PARAM_DEPRECATED: the parameter is deprecated and will be removed
134 * in a future version. A warning will be generated if it is used
135 * while running with G_ENABLE_DIAGNOSTIC=1.
136 * Since 2.26
138 * Through the #GParamFlags flag values, certain aspects of parameters
139 * can be configured. See also #G_PARAM_READWRITE and #G_PARAM_STATIC_STRINGS.
141 typedef enum
143 G_PARAM_READABLE = 1 << 0,
144 G_PARAM_WRITABLE = 1 << 1,
145 G_PARAM_CONSTRUCT = 1 << 2,
146 G_PARAM_CONSTRUCT_ONLY = 1 << 3,
147 G_PARAM_LAX_VALIDATION = 1 << 4,
148 G_PARAM_STATIC_NAME = 1 << 5,
149 #ifndef G_DISABLE_DEPRECATED
150 G_PARAM_PRIVATE = G_PARAM_STATIC_NAME,
151 #endif
152 G_PARAM_STATIC_NICK = 1 << 6,
153 G_PARAM_STATIC_BLURB = 1 << 7,
154 /* User defined flags go up to 30 */
155 G_PARAM_DEPRECATED = 1 << 31
156 } GParamFlags;
158 * G_PARAM_READWRITE:
160 * #GParamFlags value alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE.
162 #define G_PARAM_READWRITE (G_PARAM_READABLE | G_PARAM_WRITABLE)
164 * G_PARAM_STATIC_STRINGS:
166 * #GParamFlags value alias for %G_PARAM_STATIC_NAME | %G_PARAM_STATIC_NICK | %G_PARAM_STATIC_BLURB.
168 * Since 2.13.0
170 #define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
171 /* bits in the range 0xffffff00 are reserved for 3rd party usage */
173 * G_PARAM_MASK:
175 * Mask containing the bits of #GParamSpec.flags which are reserved for GLib.
177 #define G_PARAM_MASK (0x000000ff)
179 * G_PARAM_USER_SHIFT:
181 * Minimum shift count to be used for user defined flags, to be stored in
182 * #GParamSpec.flags. The maximum allowed is 30 + G_PARAM_USER_SHIFT.
184 #define G_PARAM_USER_SHIFT (8)
186 /* --- typedefs & structures --- */
187 typedef struct _GParamSpec GParamSpec;
188 typedef struct _GParamSpecClass GParamSpecClass;
189 typedef struct _GParameter GParameter;
190 typedef struct _GParamSpecPool GParamSpecPool;
192 * GParamSpec:
193 * @g_type_instance: private #GTypeInstance portion
194 * @name: name of this parameter: always an interned string
195 * @flags: #GParamFlags flags for this parameter
196 * @value_type: the #GValue type for this parameter
197 * @owner_type: #GType type that uses (introduces) this parameter
199 * All other fields of the <structname>GParamSpec</structname> struct are private and
200 * should not be used directly.
202 struct _GParamSpec
204 GTypeInstance g_type_instance;
206 const gchar *name; /* interned string */
207 GParamFlags flags;
208 GType value_type;
209 GType owner_type; /* class or interface using this property */
211 /*< private >*/
212 gchar *_nick;
213 gchar *_blurb;
214 GData *qdata;
215 guint ref_count;
216 guint param_id; /* sort-criteria */
219 * GParamSpecClass:
220 * @g_type_class: the parent class
221 * @value_type: the #GValue type for this parameter
222 * @finalize: The instance finalization function (optional), should chain
223 * up to the finalize method of the parent class.
224 * @value_set_default: Resets a @value to the default value for this type
225 * (recommended, the default is g_value_reset()), see
226 * g_param_value_set_default().
227 * @value_validate: Ensures that the contents of @value comply with the
228 * specifications set out by this type (optional), see
229 * g_param_value_validate().
230 * @values_cmp: Compares @value1 with @value2 according to this type
231 * (recommended, the default is memcmp()), see g_param_values_cmp().
233 * The class structure for the <structname>GParamSpec</structname> type.
234 * Normally, <structname>GParamSpec</structname> classes are filled by
235 * g_param_type_register_static().
237 struct _GParamSpecClass
239 GTypeClass g_type_class;
241 GType value_type;
243 void (*finalize) (GParamSpec *pspec);
245 /* GParam methods */
246 void (*value_set_default) (GParamSpec *pspec,
247 GValue *value);
248 gboolean (*value_validate) (GParamSpec *pspec,
249 GValue *value);
250 gint (*values_cmp) (GParamSpec *pspec,
251 const GValue *value1,
252 const GValue *value2);
253 /*< private >*/
254 gpointer dummy[4];
257 * GParameter:
258 * @name: the parameter name
259 * @value: the parameter value
261 * The <structname>GParameter</structname> struct is an auxiliary structure used
262 * to hand parameter name/value pairs to g_object_newv().
264 struct _GParameter /* auxiliary structure for _setv() variants */
266 const gchar *name;
267 GValue value;
271 /* --- prototypes --- */
272 GLIB_AVAILABLE_IN_ALL
273 GParamSpec* g_param_spec_ref (GParamSpec *pspec);
274 GLIB_AVAILABLE_IN_ALL
275 void g_param_spec_unref (GParamSpec *pspec);
276 GLIB_AVAILABLE_IN_ALL
277 void g_param_spec_sink (GParamSpec *pspec);
278 GLIB_AVAILABLE_IN_ALL
279 GParamSpec* g_param_spec_ref_sink (GParamSpec *pspec);
280 GLIB_AVAILABLE_IN_ALL
281 gpointer g_param_spec_get_qdata (GParamSpec *pspec,
282 GQuark quark);
283 GLIB_AVAILABLE_IN_ALL
284 void g_param_spec_set_qdata (GParamSpec *pspec,
285 GQuark quark,
286 gpointer data);
287 GLIB_AVAILABLE_IN_ALL
288 void g_param_spec_set_qdata_full (GParamSpec *pspec,
289 GQuark quark,
290 gpointer data,
291 GDestroyNotify destroy);
292 GLIB_AVAILABLE_IN_ALL
293 gpointer g_param_spec_steal_qdata (GParamSpec *pspec,
294 GQuark quark);
295 GLIB_AVAILABLE_IN_ALL
296 GParamSpec* g_param_spec_get_redirect_target (GParamSpec *pspec);
298 GLIB_AVAILABLE_IN_ALL
299 void g_param_value_set_default (GParamSpec *pspec,
300 GValue *value);
301 GLIB_AVAILABLE_IN_ALL
302 gboolean g_param_value_defaults (GParamSpec *pspec,
303 GValue *value);
304 GLIB_AVAILABLE_IN_ALL
305 gboolean g_param_value_validate (GParamSpec *pspec,
306 GValue *value);
307 GLIB_AVAILABLE_IN_ALL
308 gboolean g_param_value_convert (GParamSpec *pspec,
309 const GValue *src_value,
310 GValue *dest_value,
311 gboolean strict_validation);
312 GLIB_AVAILABLE_IN_ALL
313 gint g_param_values_cmp (GParamSpec *pspec,
314 const GValue *value1,
315 const GValue *value2);
316 GLIB_AVAILABLE_IN_ALL
317 const gchar * g_param_spec_get_name (GParamSpec *pspec);
318 GLIB_AVAILABLE_IN_ALL
319 const gchar * g_param_spec_get_nick (GParamSpec *pspec);
320 GLIB_AVAILABLE_IN_ALL
321 const gchar * g_param_spec_get_blurb (GParamSpec *pspec);
322 GLIB_AVAILABLE_IN_ALL
323 void g_value_set_param (GValue *value,
324 GParamSpec *param);
325 GLIB_AVAILABLE_IN_ALL
326 GParamSpec* g_value_get_param (const GValue *value);
327 GLIB_AVAILABLE_IN_ALL
328 GParamSpec* g_value_dup_param (const GValue *value);
331 GLIB_AVAILABLE_IN_ALL
332 void g_value_take_param (GValue *value,
333 GParamSpec *param);
334 GLIB_DEPRECATED_FOR(g_value_take_param)
335 void g_value_set_param_take_ownership (GValue *value,
336 GParamSpec *param);
337 GLIB_AVAILABLE_IN_2_36
338 const GValue * g_param_spec_get_default_value (GParamSpec *param);
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
360 * instances thereof.
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 */
373 /* class portion */
374 GType value_type; /* obligatory */
375 void (*finalize) (GParamSpec *pspec); /* optional */
376 void (*value_set_default) (GParamSpec *pspec, /* recommended */
377 GValue *value);
378 gboolean (*value_validate) (GParamSpec *pspec, /* optional */
379 GValue *value);
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,
391 GType opt_type);
394 /* --- protected --- */
395 GLIB_AVAILABLE_IN_ALL
396 gpointer g_param_spec_internal (GType param_type,
397 const gchar *name,
398 const gchar *nick,
399 const gchar *blurb,
400 GParamFlags flags);
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,
405 GParamSpec *pspec,
406 GType owner_type);
407 GLIB_AVAILABLE_IN_ALL
408 void g_param_spec_pool_remove (GParamSpecPool *pool,
409 GParamSpec *pspec);
410 GLIB_AVAILABLE_IN_ALL
411 GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool,
412 const gchar *param_name,
413 GType owner_type,
414 gboolean walk_ancestors);
415 GLIB_AVAILABLE_IN_ALL
416 GList* g_param_spec_pool_list_owned (GParamSpecPool *pool,
417 GType owner_type);
418 GLIB_AVAILABLE_IN_ALL
419 GParamSpec** g_param_spec_pool_list (GParamSpecPool *pool,
420 GType owner_type,
421 guint *n_pspecs_p);
424 /* contracts:
426 * gboolean value_validate (GParamSpec *pspec,
427 * GValue *value):
428 * modify value contents in the least destructive way, so
429 * that it complies with pspec's requirements (i.e.
430 * according to minimum/maximum ranges etc...). return
431 * whether modification was necessary.
433 * gint values_cmp (GParamSpec *pspec,
434 * const GValue *value1,
435 * const GValue *value2):
436 * return value1 - value2, i.e. (-1) if value1 < value2,
437 * (+1) if value1 > value2, and (0) otherwise (equality)
440 G_END_DECLS
442 #endif /* __G_PARAM_H__ */