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 --- */
33 #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
34 #define G_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM, GParamSpec))
35 #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM))
36 #define G_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_CAST ((pclass), G_TYPE_PARAM, GParamSpecClass))
37 #define G_IS_PARAM_SPEC_CLASS(pclass) (G_TYPE_CHECK_CLASS_TYPE ((pclass), G_TYPE_PARAM))
38 #define G_PARAM_SPEC_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass))
41 /* --- convenience macros --- */
42 #define G_PARAM_SPEC_TYPE(pspec) (G_TYPE_FROM_INSTANCE (pspec))
43 #define G_PARAM_SPEC_TYPE_NAME(pspec) (g_type_name (G_PARAM_SPEC_TYPE (pspec)))
44 #define G_PARAM_SPEC_VALUE_TYPE(pspec) (G_PARAM_SPEC (pspec)->value_type)
45 #define G_VALUE_HOLDS_PARAM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM))
51 G_PARAM_READABLE = 1 << 0,
52 G_PARAM_WRITABLE = 1 << 1,
53 G_PARAM_CONSTRUCT = 1 << 2,
54 G_PARAM_CONSTRUCT_ONLY = 1 << 3,
55 G_PARAM_LAX_VALIDATION = 1 << 4,
56 G_PARAM_STATIC_NAME = 1 << 5,
57 G_PARAM_STATIC_NICK = 1 << 6,
58 G_PARAM_STATIC_BLURB = 1 << 7
60 #define G_PARAM_READWRITE (G_PARAM_READABLE | G_PARAM_WRITABLE)
61 #define G_PARAM_MASK (0x000000ff)
62 /* bits in the range 0xffffff00 are reserved for 3rd party usage */
63 #define G_PARAM_USER_SHIFT (8)
66 /* --- typedefs & structures --- */
67 typedef struct _GParamSpec GParamSpec;
68 typedef struct _GParamSpecClass GParamSpecClass;
69 typedef struct _GParameter GParameter;
70 typedef struct _GParamSpecPool GParamSpecPool;
73 GTypeInstance g_type_instance;
78 GType owner_type; /* class or interface using this property */
85 guint param_id; /* sort-criteria */
87 struct _GParamSpecClass
89 GTypeClass g_type_class;
93 void (*finalize) (GParamSpec *pspec);
96 void (*value_set_default) (GParamSpec *pspec,
98 gboolean (*value_validate) (GParamSpec *pspec,
100 gint (*values_cmp) (GParamSpec *pspec,
101 const GValue *value1,
102 const GValue *value2);
106 struct _GParameter /* auxillary structure for _setv() variants */
113 /* --- prototypes --- */
114 GParamSpec* g_param_spec_ref (GParamSpec *pspec);
115 void g_param_spec_unref (GParamSpec *pspec);
116 void g_param_spec_sink (GParamSpec *pspec);
117 gpointer g_param_spec_get_qdata (GParamSpec *pspec,
119 void g_param_spec_set_qdata (GParamSpec *pspec,
122 void g_param_spec_set_qdata_full (GParamSpec *pspec,
125 GDestroyNotify destroy);
126 gpointer g_param_spec_steal_qdata (GParamSpec *pspec,
128 GParamSpec* g_param_spec_get_redirect_target (GParamSpec *pspec);
130 void g_param_value_set_default (GParamSpec *pspec,
132 gboolean g_param_value_defaults (GParamSpec *pspec,
134 gboolean g_param_value_validate (GParamSpec *pspec,
136 gboolean g_param_value_convert (GParamSpec *pspec,
137 const GValue *src_value,
139 gboolean strict_validation);
140 gint g_param_values_cmp (GParamSpec *pspec,
141 const GValue *value1,
142 const GValue *value2);
143 G_CONST_RETURN gchar* g_param_spec_get_name (GParamSpec *pspec);
144 G_CONST_RETURN gchar* g_param_spec_get_nick (GParamSpec *pspec);
145 G_CONST_RETURN gchar* g_param_spec_get_blurb (GParamSpec *pspec);
146 void g_value_set_param (GValue *value,
148 GParamSpec* g_value_get_param (const GValue *value);
149 GParamSpec* g_value_dup_param (const GValue *value);
152 void g_value_take_param (GValue *value,
154 #ifndef G_DISABLE_DEPRECATED
155 void g_value_set_param_take_ownership (GValue *value,
159 /* --- convenience functions --- */
160 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
161 struct _GParamSpecTypeInfo
163 /* type system portion */
164 guint16 instance_size; /* obligatory */
165 guint16 n_preallocs; /* optional */
166 void (*instance_init) (GParamSpec *pspec); /* optional */
169 GType value_type; /* obligatory */
170 void (*finalize) (GParamSpec *pspec); /* optional */
171 void (*value_set_default) (GParamSpec *pspec, /* recommended */
173 gboolean (*value_validate) (GParamSpec *pspec, /* optional */
175 gint (*values_cmp) (GParamSpec *pspec, /* recommended */
176 const GValue *value1,
177 const GValue *value2);
179 GType g_param_type_register_static (const gchar *name,
180 const GParamSpecTypeInfo *pspec_info);
182 /* For registering builting types */
183 GType _g_param_type_register_static_constant (const gchar *name,
184 const GParamSpecTypeInfo *pspec_info,
188 /* --- protected --- */
189 gpointer g_param_spec_internal (GType param_type,
194 GParamSpecPool* g_param_spec_pool_new (gboolean type_prefixing);
195 void g_param_spec_pool_insert (GParamSpecPool *pool,
198 void g_param_spec_pool_remove (GParamSpecPool *pool,
200 GParamSpec* g_param_spec_pool_lookup (GParamSpecPool *pool,
201 const gchar *param_name,
203 gboolean walk_ancestors);
204 GList* g_param_spec_pool_list_owned (GParamSpecPool *pool,
206 GParamSpec** g_param_spec_pool_list (GParamSpecPool *pool,
214 * gboolean value_validate (GParamSpec *pspec,
216 * modify value contents in the least destructive way, so
217 * that it complies with pspec's requirements (i.e.
218 * according to minimum/maximum ranges etc...). return
219 * whether modification was necessary.
221 * gint values_cmp (GParamSpec *pspec,
222 * const GValue *value1,
223 * const GValue *value2):
224 * return value1 - value2, i.e. (-1) if value1 < value2,
225 * (+1) if value1 > value2, and (0) otherwise (equality)
230 #endif /* __G_PARAM_H__ */