1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997, 1998, 1999, 2000 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
25 #include <gobject/gvalue.h>
30 #endif /* __cplusplus */
33 /* --- type macros --- */
34 #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
35 #define G_PARAM_SPEC_TYPE(pspec) (G_TYPE_FROM_INSTANCE (pspec))
36 #define G_PARAM_SPEC_TYPE_NAME(pspec) (g_type_name (G_PARAM_SPEC_TYPE (pspec)))
37 #define G_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM, GParamSpec))
38 #define G_IS_PARAM_SPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM))
39 #define G_PARAM_SPEC_GET_CLASS(pspec) (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass))
40 #define G_IS_PARAM_VALUE(pspec, value) (g_type_is_a (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (pspec))) /* FIXME */
41 #define G_PARAM_SPEC_VALUE_TYPE(pspec) (G_PARAM_SPEC_GET_CLASS (pspec)->value_type)
47 G_PARAM_READABLE = 1 << 0,
48 G_PARAM_WRITABLE = 1 << 1,
49 G_PARAM_MASK = 0x000f,
50 /* bits in the range 0xfff0 are reserved for 3rd party usage */
51 G_PARAM_USER_MASK = 0xfff0
55 /* --- typedefs & structures --- */
56 typedef struct _GParamSpecClass GParamSpecClass;
57 typedef struct _GParamSpec GParamSpec;
58 struct _GParamSpecClass
60 GTypeClass g_type_class;
64 void (*finalize) (GParamSpec *pspec);
67 void (*value_set_default) (GParamSpec *pspec,
69 gboolean (*value_validate) (GParamSpec *pspec,
71 gint (*values_cmp) (GParamSpec *pspec,
73 const GValue *value2);
77 GTypeInstance g_instance;
91 /* --- prototypes --- */
92 GParamSpec* g_param_spec_ref (GParamSpec *pspec);
93 void g_param_spec_unref (GParamSpec *pspec);
94 gpointer g_param_spec_get_qdata (GParamSpec *pspec,
96 void g_param_spec_set_qdata (GParamSpec *pspec,
99 void g_param_spec_set_qdata_full (GParamSpec *pspec,
102 GDestroyNotify destroy);
103 gpointer g_param_spec_steal_qdata (GParamSpec *pspec,
105 void g_param_value_set_default (GParamSpec *pspec,
107 gboolean g_param_value_defaults (GParamSpec *pspec,
109 gboolean g_param_value_validate (GParamSpec *pspec,
111 gint g_param_values_cmp (GParamSpec *pspec,
112 const GValue *value1,
113 const GValue *value2);
116 /* --- private --- */
117 gpointer g_param_spec_internal (GType param_type,
122 GHashTable* g_param_spec_hash_table_new (void);
123 void g_param_spec_hash_table_insert (GHashTable *hash_table,
126 void g_param_spec_hash_table_remove (GHashTable *hash_table,
128 GParamSpec* g_param_spec_hash_table_lookup (GHashTable *hash_table,
129 const gchar *param_name,
131 gboolean try_ancestors,
132 const gchar **trailer);
139 * class functions may not evaluate param->pspec directly,
140 * instead, pspec will be passed as argument if required.
142 * void param_init (GParam *param, GParamSpec *pspec):
143 * initialize param's value to default if pspec is given,
144 * and to zero-equivalent (a value that doesn't need to be
145 * free()ed later on) otherwise.
147 * void param_free_value (GParam *param):
148 * free param's value if required, zero-reinitialization
149 * of the value is not required. (this class function
150 * may be NULL for param types that don't need to free
151 * values, such as ints or floats).
153 * gboolean param_validate (GParam *param, GParamSpec *pspec):
154 * modify param's value in the least destructive way, so
155 * that it complies with pspec's requirements (i.e.
156 * according to minimum/maximum ranges etc...). return
157 * whether modification was necessary.
159 * gint param_values_cmp (GParam *param1, GParam *param2, GParamSpec*):
160 * return param1 - param2, i.e. <0 if param1 < param2,
161 * >0 if param1 > param2, and 0 if they are equal
162 * (passing pspec is optional, but recommended)
164 * void param_copy_value (GParam *param_src, GParam *param_dest):
165 * copy value from param_src to param_dest, param_dest is
166 * already free()d and zero-initialized, so its value can
167 * simply be overwritten. (may be NULL for memcpy)
169 * gchar* param_collect_value ():
170 * class function may be NULL.
172 * gchar* param_lcopy_value ():
173 * class function may be NULL.
179 #endif /* __cplusplus */
181 #endif /* __G_PARAM_H__ */