Include gtypes.h not gobject/gtype.h
[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 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
25 #error "Only <glib-object.h> can be included directly."
26 #endif
27
28 #include        <gobject/gvalue.h>
29
30 G_BEGIN_DECLS
31
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))
39
40
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))
46        
47
48 /* --- flags --- */
49 typedef enum
50 {
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_PRIVATE             = 1 << 5
57 } GParamFlags;
58 #define G_PARAM_READWRITE       (G_PARAM_READABLE | G_PARAM_WRITABLE)
59 #define G_PARAM_MASK            (0x000000ff)
60 /* bits in the range 0xffffff00 are reserved for 3rd party usage */
61 #define G_PARAM_USER_SHIFT      (8)
62
63
64 /* --- typedefs & structures --- */
65 typedef struct _GParamSpec      GParamSpec;
66 typedef struct _GParamSpecClass GParamSpecClass;
67 typedef struct _GParameter      GParameter;
68 typedef struct _GParamSpecPool  GParamSpecPool;
69 struct _GParamSpec
70 {
71   GTypeInstance  g_type_instance;
72
73   gchar         *name;
74   GParamFlags    flags;
75   GType          value_type;
76   GType          owner_type;    /* class using this property */
77
78   /*< private >*/
79   gchar         *_nick;
80   gchar         *_blurb;
81   GData         *qdata;
82   guint          ref_count;
83   guint          param_id;      /* sort-criteria */
84 };
85 struct _GParamSpecClass
86 {
87   GTypeClass      g_type_class;
88
89   GType           value_type;
90
91   void          (*finalize)             (GParamSpec   *pspec);
92
93   /* GParam methods */
94   void          (*value_set_default)    (GParamSpec   *pspec,
95                                          GValue       *value);
96   gboolean      (*value_validate)       (GParamSpec   *pspec,
97                                          GValue       *value);
98   gint          (*values_cmp)           (GParamSpec   *pspec,
99                                          const GValue *value1,
100                                          const GValue *value2);
101 };
102 struct _GParameter /* auxillary structure for _setv() variants */
103 {
104   const gchar *name;
105   GValue       value;
106 };
107
108
109 /* --- prototypes --- */
110 GParamSpec*     g_param_spec_ref                (GParamSpec    *pspec);
111 void            g_param_spec_unref              (GParamSpec    *pspec);
112 void            g_param_spec_sink               (GParamSpec    *pspec);
113 gpointer        g_param_spec_get_qdata          (GParamSpec    *pspec,
114                                                  GQuark         quark);
115 void            g_param_spec_set_qdata          (GParamSpec    *pspec,
116                                                  GQuark         quark,
117                                                  gpointer       data);
118 void            g_param_spec_set_qdata_full     (GParamSpec    *pspec,
119                                                  GQuark         quark,
120                                                  gpointer       data,
121                                                  GDestroyNotify destroy);
122 gpointer        g_param_spec_steal_qdata        (GParamSpec    *pspec,
123                                                  GQuark         quark);
124 void            g_param_value_set_default       (GParamSpec    *pspec,
125                                                  GValue        *value);
126 gboolean        g_param_value_defaults          (GParamSpec    *pspec,
127                                                  GValue        *value);
128 gboolean        g_param_value_validate          (GParamSpec    *pspec,
129                                                  GValue        *value);
130 gboolean        g_param_value_convert           (GParamSpec    *pspec,
131                                                  const GValue  *src_value,
132                                                  GValue        *dest_value,
133                                                  gboolean       strict_validation);
134 gint            g_param_values_cmp              (GParamSpec    *pspec,
135                                                  const GValue  *value1,
136                                                  const GValue  *value2);
137 G_CONST_RETURN gchar*   g_param_spec_get_name   (GParamSpec    *pspec);
138 G_CONST_RETURN gchar*   g_param_spec_get_nick   (GParamSpec    *pspec);
139 G_CONST_RETURN gchar*   g_param_spec_get_blurb  (GParamSpec    *pspec);
140 void            g_value_set_param               (GValue        *value,
141                                                  GParamSpec    *param);
142 GParamSpec*     g_value_get_param               (const GValue  *value);
143 GParamSpec*     g_value_dup_param               (const GValue  *value);
144
145
146 /* --- convenience functions --- */
147 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
148 struct _GParamSpecTypeInfo
149 {
150   /* type system portion */
151   guint16         instance_size;                               /* obligatory */
152   guint16         n_preallocs;                                 /* optional */
153   void          (*instance_init)        (GParamSpec   *pspec); /* optional */
154
155   /* class portion */
156   GType           value_type;                                  /* obligatory */
157   void          (*finalize)             (GParamSpec   *pspec); /* optional */
158   void          (*value_set_default)    (GParamSpec   *pspec,  /* recommended */
159                                          GValue       *value);
160   gboolean      (*value_validate)       (GParamSpec   *pspec,  /* optional */
161                                          GValue       *value);
162   gint          (*values_cmp)           (GParamSpec   *pspec,  /* recommended */
163                                          const GValue *value1,
164                                          const GValue *value2);
165 };
166 GType   g_param_type_register_static    (const gchar              *name,
167                                          const GParamSpecTypeInfo *pspec_info);
168
169
170 /* --- protected --- */
171 gpointer        g_param_spec_internal           (GType          param_type,
172                                                  const gchar   *name,
173                                                  const gchar   *nick,
174                                                  const gchar   *blurb,
175                                                  GParamFlags    flags);
176 GParamSpecPool* g_param_spec_pool_new           (gboolean       type_prefixing);
177 void            g_param_spec_pool_insert        (GParamSpecPool *pool,
178                                                  GParamSpec     *pspec,
179                                                  GType           owner_type);
180 void            g_param_spec_pool_remove        (GParamSpecPool *pool,
181                                                  GParamSpec     *pspec);
182 GParamSpec*     g_param_spec_pool_lookup        (GParamSpecPool *pool,
183                                                  const gchar    *param_name,
184                                                  GType           owner_type,
185                                                  gboolean        walk_ancestors);
186 GList*          g_param_spec_pool_list_owned    (GParamSpecPool *pool,
187                                                  GType           owner_type);
188 GParamSpec**    g_param_spec_pool_list          (GParamSpecPool *pool,
189                                                  GType           owner_type,
190                                                  guint          *n_pspecs_p);
191
192
193
194 /* contracts:
195  *
196  * gboolean value_validate (GParamSpec *pspec,
197  *                          GValue     *value):
198  *      modify value contents in the least destructive way, so
199  *      that it complies with pspec's requirements (i.e.
200  *      according to minimum/maximum ranges etc...). return
201  *      whether modification was necessary.
202  *
203  * gint values_cmp (GParamSpec   *pspec,
204  *                  const GValue *value1,
205  *                  const GValue *value2):
206  *      return value1 - value2, i.e. (-1) if value1 < value2,
207  *      (+1) if value1 > value2, and (0) otherwise (equality)
208  */
209
210 G_END_DECLS
211
212 #endif /* __G_PARAM_H__ */