add API for chaining: g_signal_chain_from_overridden() and
[platform/upstream/glib.git] / gobject / gparam.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3  *
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.
8  *
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.
13  *
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.
18  *
19  * gparam.h: GParamSpec base class implementation
20  */
21 #ifndef __G_PARAM_H__
22 #define __G_PARAM_H__
23
24
25 #include        <gobject/gvalue.h>
26
27 G_BEGIN_DECLS
28
29 /* --- standard type macros --- */
30 #define G_TYPE_IS_PARAM(type)           (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
31 #define G_PARAM_SPEC(pspec)             (G_TYPE_CHECK_INSTANCE_CAST ((pspec), G_TYPE_PARAM, GParamSpec))
32 #define G_IS_PARAM_SPEC(pspec)          (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), G_TYPE_PARAM))
33 #define G_PARAM_SPEC_CLASS(pclass)      (G_TYPE_CHECK_CLASS_CAST ((pclass), G_TYPE_PARAM, GParamSpecClass))
34 #define G_IS_PARAM_SPEC_CLASS(pclass)   (G_TYPE_CHECK_CLASS_TYPE ((pclass), G_TYPE_PARAM))
35 #define G_PARAM_SPEC_GET_CLASS(pspec)   (G_TYPE_INSTANCE_GET_CLASS ((pspec), G_TYPE_PARAM, GParamSpecClass))
36
37
38 /* --- convenience macros --- */
39 #define G_PARAM_SPEC_TYPE(pspec)        (G_TYPE_FROM_INSTANCE (pspec))
40 #define G_PARAM_SPEC_TYPE_NAME(pspec)   (g_type_name (G_PARAM_SPEC_TYPE (pspec)))
41 #define G_PARAM_SPEC_VALUE_TYPE(pspec)  (G_PARAM_SPEC (pspec)->value_type)
42 #define G_VALUE_HOLDS_PARAM(value)      (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM))
43        
44
45 /* --- flags --- */
46 typedef enum
47 {
48   G_PARAM_READABLE            = 1 << 0,
49   G_PARAM_WRITABLE            = 1 << 1,
50   G_PARAM_CONSTRUCT           = 1 << 2,
51   G_PARAM_CONSTRUCT_ONLY      = 1 << 3,
52   G_PARAM_LAX_VALIDATION      = 1 << 4,
53   G_PARAM_PRIVATE             = 1 << 5
54 } GParamFlags;
55 #define G_PARAM_READWRITE       (G_PARAM_READABLE | G_PARAM_WRITABLE)
56 #define G_PARAM_MASK            (0x000000ff)
57 /* bits in the range 0xffffff00 are reserved for 3rd party usage */
58 #define G_PARAM_USER_SHIFT      (8)
59
60
61 /* --- typedefs & structures --- */
62 typedef struct _GParamSpec      GParamSpec;
63 typedef struct _GParamSpecClass GParamSpecClass;
64 typedef struct _GParameter      GParameter;
65 typedef struct _GParamSpecPool  GParamSpecPool;
66 struct _GParamSpec
67 {
68   GTypeInstance  g_type_instance;
69
70   gchar         *name;
71   GParamFlags    flags;
72   GType          value_type;
73   GType          owner_type;    /* class using this property */
74
75   /*< private >*/
76   gchar         *_nick;
77   gchar         *_blurb;
78   GData         *qdata;
79   guint          ref_count;
80   guint          param_id;      /* sort-criteria */
81 };
82 struct _GParamSpecClass
83 {
84   GTypeClass      g_type_class;
85
86   GType           value_type;
87
88   void          (*finalize)             (GParamSpec   *pspec);
89
90   /* GParam methods */
91   void          (*value_set_default)    (GParamSpec   *pspec,
92                                          GValue       *value);
93   gboolean      (*value_validate)       (GParamSpec   *pspec,
94                                          GValue       *value);
95   gint          (*values_cmp)           (GParamSpec   *pspec,
96                                          const GValue *value1,
97                                          const GValue *value2);
98 };
99 struct _GParameter /* auxillary structure for _setv() variants */
100 {
101   const gchar *name;
102   GValue       value;
103 };
104
105
106 /* --- prototypes --- */
107 GParamSpec*     g_param_spec_ref                (GParamSpec    *pspec);
108 void            g_param_spec_unref              (GParamSpec    *pspec);
109 void            g_param_spec_sink               (GParamSpec    *pspec);
110 gpointer        g_param_spec_get_qdata          (GParamSpec    *pspec,
111                                                  GQuark         quark);
112 void            g_param_spec_set_qdata          (GParamSpec    *pspec,
113                                                  GQuark         quark,
114                                                  gpointer       data);
115 void            g_param_spec_set_qdata_full     (GParamSpec    *pspec,
116                                                  GQuark         quark,
117                                                  gpointer       data,
118                                                  GDestroyNotify destroy);
119 gpointer        g_param_spec_steal_qdata        (GParamSpec    *pspec,
120                                                  GQuark         quark);
121 void            g_param_value_set_default       (GParamSpec    *pspec,
122                                                  GValue        *value);
123 gboolean        g_param_value_defaults          (GParamSpec    *pspec,
124                                                  GValue        *value);
125 gboolean        g_param_value_validate          (GParamSpec    *pspec,
126                                                  GValue        *value);
127 gboolean        g_param_value_convert           (GParamSpec    *pspec,
128                                                  const GValue  *src_value,
129                                                  GValue        *dest_value,
130                                                  gboolean       strict_validation);
131 gint            g_param_values_cmp              (GParamSpec    *pspec,
132                                                  const GValue  *value1,
133                                                  const GValue  *value2);
134 G_CONST_RETURN gchar*   g_param_spec_get_name   (GParamSpec    *pspec);
135 G_CONST_RETURN gchar*   g_param_spec_get_nick   (GParamSpec    *pspec);
136 G_CONST_RETURN gchar*   g_param_spec_get_blurb  (GParamSpec    *pspec);
137 void            g_value_set_param               (GValue        *value,
138                                                  GParamSpec    *param);
139 GParamSpec*     g_value_get_param               (const GValue  *value);
140 GParamSpec*     g_value_dup_param               (const GValue  *value);
141
142
143 /* --- convenience functions --- */
144 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
145 struct _GParamSpecTypeInfo
146 {
147   /* type system portion */
148   guint16         instance_size;                               /* obligatory */
149   guint16         n_preallocs;                                 /* optional */
150   void          (*instance_init)        (GParamSpec   *pspec); /* optional */
151
152   /* class portion */
153   GType           value_type;                                  /* obligatory */
154   void          (*finalize)             (GParamSpec   *pspec); /* optional */
155   void          (*value_set_default)    (GParamSpec   *pspec,  /* recommended */
156                                          GValue       *value);
157   gboolean      (*value_validate)       (GParamSpec   *pspec,  /* optional */
158                                          GValue       *value);
159   gint          (*values_cmp)           (GParamSpec   *pspec,  /* recommended */
160                                          const GValue *value1,
161                                          const GValue *value2);
162 };
163 GType   g_param_type_register_static    (const gchar              *name,
164                                          const GParamSpecTypeInfo *pspec_info);
165
166
167 /* --- protected --- */
168 gpointer        g_param_spec_internal           (GType          param_type,
169                                                  const gchar   *name,
170                                                  const gchar   *nick,
171                                                  const gchar   *blurb,
172                                                  GParamFlags    flags);
173 GParamSpecPool* g_param_spec_pool_new           (gboolean       type_prefixing);
174 void            g_param_spec_pool_insert        (GParamSpecPool *pool,
175                                                  GParamSpec     *pspec,
176                                                  GType           owner_type);
177 void            g_param_spec_pool_remove        (GParamSpecPool *pool,
178                                                  GParamSpec     *pspec);
179 GParamSpec*     g_param_spec_pool_lookup        (GParamSpecPool *pool,
180                                                  const gchar    *param_name,
181                                                  GType           owner_type,
182                                                  gboolean        walk_ancestors);
183 GList*          g_param_spec_pool_list_owned    (GParamSpecPool *pool,
184                                                  GType           owner_type);
185 GParamSpec**    g_param_spec_pool_list          (GParamSpecPool *pool,
186                                                  GType           owner_type,
187                                                  guint          *n_pspecs_p);
188
189
190
191 /* contracts:
192  *
193  * gboolean value_validate (GParamSpec *pspec,
194  *                          GValue     *value):
195  *      modify value contents in the least destructive way, so
196  *      that it complies with pspec's requirements (i.e.
197  *      according to minimum/maximum ranges etc...). return
198  *      whether modification was necessary.
199  *
200  * gint values_cmp (GParamSpec   *pspec,
201  *                  const GValue *value1,
202  *                  const GValue *value2):
203  *      return value1 - value2, i.e. (-1) if value1 < value2,
204  *      (+1) if value1 > value2, and (0) otherwise (equality)
205  */
206
207 G_END_DECLS
208
209 #endif /* __G_PARAM_H__ */