100%
[platform/upstream/glib.git] / docs / reference / gobject / tmpl / gparamspec.sgml
1 <!-- ##### SECTION Title ##### -->
2 GParamSpec
3
4 <!-- ##### SECTION Short_Description ##### -->
5 Metadata for parameter specifications
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 #GParamSpec is an object structure that encapsulates the metadata
10 required to specify parameters, such as e.g. #GObject properties.
11 </para>
12
13 <!-- ##### SECTION See_Also ##### -->
14 <para>
15 g_object_class_install_property(), g_object_set(), g_object_get(),
16 g_object_set_property(), g_object_get_property(), g_value_register_transform_func()
17 </para>
18
19 <!-- ##### MACRO G_TYPE_IS_PARAM ##### -->
20 <para>
21 Returns whether @type "is a" %G_TYPE_PARAM.
22 </para>
23
24 @type: a #GType ID
25
26
27 <!-- ##### MACRO G_PARAM_SPEC ##### -->
28 <para>
29 Casts a derived #GParamSpec object (e.g. of type #GParamSpecInt) into
30 a #GParamSpec object.
31 </para>
32
33 @pspec: a valid #GParamSpec
34
35
36 <!-- ##### MACRO G_IS_PARAM_SPEC ##### -->
37 <para>
38 Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM
39 or derived.
40 </para>
41
42 @pspec: a #GParamSpec
43
44
45 <!-- ##### MACRO G_PARAM_SPEC_CLASS ##### -->
46 <para>
47 Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure.
48 </para>
49
50 @pclass: a valid #GParamSpecClass
51
52
53 <!-- ##### MACRO G_IS_PARAM_SPEC_CLASS ##### -->
54 <para>
55 Checks whether @pclass "is a" valid #GParamSpecClass structure of type 
56 %G_TYPE_PARAM or derived.
57 </para>
58
59 @pclass: a #GParamSpecClass
60
61
62 <!-- ##### MACRO G_PARAM_SPEC_GET_CLASS ##### -->
63 <para>
64 Retrieves the #GParamSpecClass of a #GParamSpec.
65 </para>
66
67 @pspec: a valid #GParamSpec
68
69
70 <!-- ##### MACRO G_PARAM_SPEC_TYPE ##### -->
71 <para>
72 Retrieves the #GType of this @pspec.
73 </para>
74
75 @pspec: a valid #GParamSpec
76
77
78 <!-- ##### MACRO G_PARAM_SPEC_TYPE_NAME ##### -->
79 <para>
80 Retrieves the #GType name of this @pspec.
81 </para>
82
83 @pspec: a valid #GParamSpec
84
85
86 <!-- ##### MACRO G_PARAM_SPEC_VALUE_TYPE ##### -->
87 <para>
88 Retrieves the #GType to initialize a #GValue for this parameter.
89 </para>
90
91 @pspec: a valid #GParamSpec
92
93
94 <!-- ##### STRUCT GParamSpec ##### -->
95 <para>
96 All fields of the <structname>GParamSpec</structname> struct are private and
97 should not be used directly, except for the following:
98 </para>
99
100 @g_type_instance: private #GTypeInstance portion
101 @name:            name of this parameter
102 @flags:           #GParamFlags flags for this parameter
103 @value_type:      the #GValue type for this parameter
104 @owner_type:      #GType type that uses (introduces) this paremeter
105
106 <!-- ##### STRUCT GParamSpecClass ##### -->
107 <para>
108 The class structure for the <structname>GParamSpec</structname> type.
109 Normally, <structname>GParamSpec</structname> classes are filled by
110 g_param_type_register_static().
111 </para>
112
113 @g_type_class: the parent class
114 @value_type: the #GValue type for this parameter
115 @finalize: The instance finalization function (optional), should chain 
116   up to the finalize method of the parent class.
117 @value_set_default: Resets a @value to the default value for this type
118   (recommended, the default is g_value_reset()), see 
119   g_param_value_set_default().
120 @value_validate: Ensures that the contents of @value comply with the 
121   specifications set out by this type (optional), see 
122   g_param_value_set_validate().
123 @values_cmp: Compares @value1 with @value2 according to this type
124   (recommended, the default is memcmp()), see g_param_values_cmp().
125
126 <!-- ##### ENUM GParamFlags ##### -->
127 <para>
128 Through the #GParamFlags flag values, certain aspects of parameters
129 can be configured.
130 </para>
131
132 @G_PARAM_READABLE:       the parameter is readable
133 @G_PARAM_WRITABLE:       the parameter is writable
134 @G_PARAM_CONSTRUCT:      the parameter will be set upon object construction
135 @G_PARAM_CONSTRUCT_ONLY: the parameter will only be set upon object construction
136 @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert())
137                          strict validation is not required
138 @G_PARAM_PRIVATE: 
139
140 <!-- ##### MACRO G_PARAM_READWRITE ##### -->
141 <para>
142 #GParamFlags value alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE.
143 </para>
144
145
146
147 <!-- ##### MACRO G_PARAM_MASK ##### -->
148 <para>
149 Mask containing the bits of #GParamSpec.flags which are reserved for GLib.
150 </para>
151
152
153
154 <!-- ##### MACRO G_PARAM_USER_SHIFT ##### -->
155 <para>
156 Minimum shift count to be used for user defined flags, to be stored in
157 #GParamSpec.flags.
158 </para>
159
160
161
162 <!-- ##### FUNCTION g_param_spec_ref ##### -->
163 <para>
164 Increments the reference count of @pspec.
165 </para>
166
167 @pspec:   a valid #GParamSpec
168 @Returns: the #GParamSpec that was passed into this function
169
170
171 <!-- ##### FUNCTION g_param_spec_unref ##### -->
172 <para>
173 Decrements the reference count of a @pspec.
174 </para>
175
176 @pspec: a valid #GParamSpec
177
178
179 <!-- ##### FUNCTION g_param_spec_sink ##### -->
180 <para>
181 The initial reference count of a newly created #GParamSpec is 1, even 
182 though no one has explicitly called g_param_spec_ref() on it yet. So the 
183 initial reference count is flagged as "floating", until someone calls 
184 <literal>g_param_spec_ref (@pspec); g_param_spec_sink (@pspec);</literal>
185 in sequence on it, taking over the initial reference count (thus
186 ending up with a @pspec that has a reference count of 1 still, but is
187 not flagged "floating" anymore).
188 </para>
189
190 @pspec: a valid #GParamSpec
191
192
193 <!-- ##### FUNCTION g_param_value_set_default ##### -->
194 <para>
195 Sets @value to its default value as specified in @pspec.
196 </para>
197
198 @pspec: a valid #GParamSpec
199 @value: a #GValue of correct type for @pspec
200
201
202 <!-- ##### FUNCTION g_param_value_defaults ##### -->
203 <para>
204 Checks whether @value contains the default value as specified in @pspec.
205 </para>
206
207 @pspec:   a valid #GParamSpec
208 @value:   a #GValue of correct type for @pspec
209 @Returns: whether @value contains the canonical defualt for this @pspec
210
211
212 <!-- ##### FUNCTION g_param_value_validate ##### -->
213 <para>
214 Ensures that the contents of @value comply with the specifications
215 set out by @pspec. For example, a #GParamSpecInt might require
216 that integers stored in @value may not be smaller than -42 and not be
217 greater than +42. If @value contains an integer outside of this range,
218 it is modified accordingly, so the resulting value will fit into the
219 range -42 .. +42.
220 </para>
221
222 @pspec:   a valid #GParamSpec
223 @value:   a #GValue of correct type for @pspec
224 @Returns: whether modifying @value was necessary to ensure validity
225
226
227 <!-- ##### FUNCTION g_param_value_convert ##### -->
228 <para>
229 Transforms @src_value into @dest_value if possible, and then validates 
230 @dest_value, in order for it to conform to @pspec.
231 If @strict_validation is %TRUE this function will only succeed if
232 the transformed @dest_value complied to @pspec without modifications.
233
234 See also g_value_type_transformable(), g_value_transform() and
235 g_param_value_validate().
236 </para>
237
238 @pspec:             a valid #GParamSpec
239 @src_value:         souce #GValue
240 @dest_value:        destination #GValue of correct type for @pspec
241 @strict_validation: %TRUE requires @dest_value to conform to @pspec without modifications
242 @Returns:           %TRUE if transformation and validation were successfull,
243                     %FALSE otherwise and @dest_value is left untouched.
244
245
246 <!-- ##### FUNCTION g_param_values_cmp ##### -->
247 <para>
248 Compares @value1 with @value2 according to @pspec, and return -1, 0 or +1,
249 if @value1 is found to be less than, equal to or greater than @value2, 
250 respectively.
251 </para>
252
253 @pspec:   a valid #GParamSpec
254 @value1:  a #GValue of correct type for @pspec
255 @value2:  a #GValue of correct type for @pspec
256 @Returns: -1, 0 or +1, for a less than, equal to or greater than result
257
258
259 <!-- ##### FUNCTION g_param_spec_get_name ##### -->
260 <para>
261 Returns the name of a #GParamSpec.
262 </para>
263
264 @pspec: a valid #GParamSpec
265 @Returns: the name of @pspec.
266
267
268 <!-- ##### FUNCTION g_param_spec_get_nick ##### -->
269 <para>
270 Returns the nickname of a #GParamSpec.
271 </para>
272
273 @pspec: a valid #GParamSpec
274 @Returns: the nickname of @pspec.
275
276
277 <!-- ##### FUNCTION g_param_spec_get_blurb ##### -->
278 <para>
279 Returns the short description of a #GParamSpec.
280 </para>
281
282 @pspec: a valid #GParamSpec
283 @Returns: the short description of @pspec.
284
285
286 <!-- ##### FUNCTION g_param_spec_get_qdata ##### -->
287 <para>
288 Gets back user data pointers stored via g_param_spec_set_qdata().
289 </para>
290
291 @pspec: a valid #GParamSpec
292 @quark: a #GQuark, naming the user data pointer
293 @Returns: the user data pointer set, or %NULL
294
295
296 <!-- ##### FUNCTION g_param_spec_set_qdata ##### -->
297 <para>
298 Sets an opaque, named pointer on a #GParamSpec. The name is specified 
299 through a #GQuark (retrieved e.g. via g_quark_from_static_string()), and 
300 the pointer can be gotten back from the @pspec with g_param_spec_get_qdata().
301 Setting a previously set user data pointer, overrides (frees)
302 the old pointer set, using #NULL as pointer essentially
303 removes the data stored.
304 </para>
305
306 @pspec: the #GParamSpec to set store a user data pointer
307 @quark: a #GQuark, naming the user data pointer
308 @data: an opaque user data pointer
309
310
311 <!-- ##### FUNCTION g_param_spec_set_qdata_full ##### -->
312 <para>
313 This function works like g_param_spec_set_qdata(), but in addition, 
314 a <literal>void (*destroy) (gpointer)</literal> function may be 
315 specified which is called with @data as argument when the @pspec is 
316 finalized, or the data is being overwritten by a call to 
317 g_param_spec_set_qdata() with the same @quark.
318 </para>
319
320 @pspec:   the #GParamSpec to set store a user data pointer
321 @quark:   a #GQuark, naming the user data pointer
322 @data:    an opaque user data pointer
323 @destroy: function to invoke with @data as argument, when @data needs to
324           be freed
325
326
327 <!-- ##### FUNCTION g_param_spec_steal_qdata ##### -->
328 <para>
329 Gets back user data pointers stored via g_param_spec_set_qdata() and 
330 removes the @data from @pspec without invoking it's destroy() function 
331 (if any was set).
332 Usually, calling this function is only required to update
333 user data pointers with a destroy notifier.
334 </para>
335
336 @pspec: the #GParamSpec to get a stored user data pointer from
337 @quark: a #GQuark, naming the user data pointer
338 @Returns: the user data pointer set, or %NULL
339
340
341 <!-- ##### FUNCTION g_param_spec_get_redirect_target ##### -->
342 <para>
343 If the paramspec redirects operations to another paramspec,
344 returns that paramspec. Redirect is used typically for
345 providing a new implementation of a property in a derived
346 type while perserving all the properties from the parent
347 type. Redirection is established by creating a property
348 of type #GParamSpecOverride. See g_object_override_property()
349 for an example of the use of this capability.
350 </para>
351
352 @pspec: a #GParamSpec
353 @Returns: paramspec to which requests on this paramspec should
354   be redirected, or %NULL if none.
355 @Since: 2.4
356
357
358 <!-- ##### FUNCTION g_param_spec_internal ##### -->
359 <para>
360 Creates a new #GParamSpec instance.
361 </para>
362 <para>
363 A property name consists of segments consisting of ASCII letters and
364 digits, separated by either the '-' or '_' character. The first
365 character of a property name must be a letter. Names which violate these
366 rules lead to undefined behaviour. 
367 </para>
368 <para>
369 When creating and looking up a #GParamSpec, either separator can be used, 
370 but they cannot be mixed. Using '-' is considerably more efficient and in 
371 fact required when using property names as detail strings for signals.
372 </para>
373
374 @param_type: the #GType for the property; must be derived from #G_TYPE_PARAM
375 @name: the canonical name of the property
376 @nick: the nickname of the property
377 @blurb: a short description of the property
378 @flags: a combination of #GParamFlags
379 @Returns: a newly allocated #GParamSpec instance
380
381
382 <!-- ##### STRUCT GParamSpecTypeInfo ##### -->
383 <para>
384 This structure is used to provide the type system with the information
385 required to initialize and destruct (finalize) a parameter's class and
386 instances thereof.
387 The initialized structure is passed to the g_param_type_register_static() 
388 The type system will perform a deep copy of this structure, so it's memory 
389 does not need to be persistent across invocation of 
390 g_param_type_register_static().
391 </para>
392
393 @instance_size: Size of the instance (object) structure.
394 @n_preallocs: Number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching).
395 @instance_init: Location of the instance initialization function (optional).
396 @value_type: The #GType of values conforming to this #GParamSpec
397 @finalize: The instance finalization function (optional).
398 @value_set_default: Resets a @value to the default value for @pspec 
399   (recommended, the default is g_value_reset()), see 
400   g_param_value_set_default().
401 @value_validate: Ensures that the contents of @value comply with the 
402   specifications set out by @pspec (optional), see 
403   g_param_value_set_validate().
404 @values_cmp: Compares @value1 with @value2 according to @pspec 
405   (recommended, the default is memcmp()), see g_param_values_cmp().
406
407 <!-- ##### FUNCTION g_param_type_register_static ##### -->
408 <para>
409 Registers @name as the name of a new static type derived from
410 #G_TYPE_PARAM. The type system uses the information contained in the
411 #GParamSpecTypeInfo structure pointed to by @info to manage the #GParamSpec 
412 type and its instances. 
413 </para>
414
415 @name: 0-terminated string used as the name of the new #GParamSpec type.
416 @pspec_info: The #GParamSpecTypeInfo for this #GParamSpec type.
417 @Returns: The new type identifier.
418
419
420 <!-- ##### STRUCT GParamSpecPool ##### -->
421 <para>
422 A #GParamSpecPool maintains a collection of #GParamSpec<!-- -->s which can be
423 quickly accessed by owner and name. The implementation of the #GObject property
424 system uses such a pool to store the #GParamSpecs of the properties all object
425 types. 
426 </para>
427
428
429 <!-- ##### FUNCTION g_param_spec_pool_new ##### -->
430 <para>
431 Creates a new #GParamSpecPool.
432 </para>
433 <para>
434 If @type_prefixing is %TRUE, lookups in the newly created pool will
435 allow to specify the owner as a colon-separated prefix of the property name, 
436 like "GtkContainer:border-width". This feature is deprecated, so you should 
437 always set @type_prefixing to %FALSE.
438 </para>
439
440 @type_prefixing: Whether the pool will support type-prefixed property names.
441 @Returns: a newly allocated #GParamSpecPool.
442
443
444 <!-- ##### FUNCTION g_param_spec_pool_insert ##### -->
445 <para>
446 Inserts a #GParamSpec in the pool.
447 </para>
448
449 @pool: a #GParamSpecPool.
450 @pspec: the #GParamSpec to insert
451 @owner_type: a #GType identifying the owner of @pspec
452
453
454 <!-- ##### FUNCTION g_param_spec_pool_remove ##### -->
455 <para>
456 Removes a #GParamSpec from the pool.
457 </para>
458
459 @pool: a #GParamSpecPool
460 @pspec: the #GParamSpec to remove
461
462
463 <!-- ##### FUNCTION g_param_spec_pool_lookup ##### -->
464 <para>
465 Looks up a #GParamSpec in the pool.
466 </para>
467
468 @pool: a #GParamSpecPool
469 @param_name: the name to look for
470 @owner_type: the owner to look for
471 @walk_ancestors: If %TRUE, also try to find a #GParamSpec with @param_name 
472   owned by an ancestor of @owner_type.
473 @Returns: The found #GParamSpec, or %NULL if no matching #GParamSpec was found.
474
475
476 <!-- ##### FUNCTION g_param_spec_pool_list ##### -->
477 <para>
478 Gets an array of all #GParamSpec<!-- -->s owned by @owner_type in the pool. 
479 </para>
480
481 @pool: a #GParamSpecPool
482 @owner_type: the owner to look for
483 @n_pspecs_p: return location for the length of the returned array
484 @Returns: a newly allocated array containing pointers to all 
485   #GParamSpec<!-- -->s owned by @owner_type in the pool
486
487
488 <!-- ##### FUNCTION g_param_spec_pool_list_owned ##### -->
489 <para>
490 Gets an #GList of all #GParamSpec<!-- -->s owned by @owner_type in the pool. 
491 </para>
492
493 @pool: a #GParamSpecPool
494 @owner_type: the owner to look for
495 @Returns: a #GList of all #GParamSpec<!-- -->s owned by @owner_type in 
496   the pool#GParamSpec<!-- -->s.
497
498