changed prototype of g_boxed_type_register_static() to contain an optional
[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
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32
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_PARAM_SPEC_VALUE_TYPE(pspec)  (G_PARAM_SPEC (pspec)->value_type)
41 #define G_VALUE_HOLDS_PARAM(value)      (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_PARAM))
42        
43
44 /* --- flags --- */
45 typedef enum
46 {
47   G_PARAM_READABLE            = 1 << 0,
48   G_PARAM_WRITABLE            = 1 << 1,
49   G_PARAM_CONSTRUCT           = 1 << 2,
50   G_PARAM_CONSTRUCT_ONLY      = 1 << 3,
51   G_PARAM_LAX_VALIDATION      = 1 << 4,
52   G_PARAM_PRIVATE             = 1 << 5
53 } GParamFlags;
54 #define G_PARAM_READWRITE       (G_PARAM_READABLE | G_PARAM_WRITABLE)
55 #define G_PARAM_MASK            (0x000000ff)
56 /* bits in the range 0xffffff00 are reserved for 3rd party usage */
57 #define G_PARAM_USER_SHIFT      (8)
58
59
60 /* --- typedefs & structures --- */
61 typedef struct _GParamSpec      GParamSpec;
62 typedef struct _GParamSpecClass GParamSpecClass;
63 typedef struct _GParamSpecPool  GParamSpecPool;
64 struct _GParamSpec
65 {
66   GTypeInstance  g_type_instance;
67
68   gchar         *name;
69   gchar         *nick;
70   gchar         *blurb;
71   GParamFlags    flags;
72   GType          value_type;
73
74   /*< private >*/
75   GType          owner_type;
76   GData         *qdata;
77   guint          ref_count;
78 };
79 struct _GParamSpecClass
80 {
81   GTypeClass      g_type_class;
82
83   GType           value_type;
84
85   void          (*finalize)             (GParamSpec   *pspec);
86
87   /* GParam methods */
88   void          (*value_set_default)    (GParamSpec   *pspec,
89                                          GValue       *value);
90   gboolean      (*value_validate)       (GParamSpec   *pspec,
91                                          GValue       *value);
92   gint          (*values_cmp)           (GParamSpec   *pspec,
93                                          const GValue *value1,
94                                          const GValue *value2);
95 };
96
97
98 /* --- prototypes --- */
99 GParamSpec*     g_param_spec_ref                (GParamSpec    *pspec);
100 void            g_param_spec_unref              (GParamSpec    *pspec);
101 void            g_param_spec_sink               (GParamSpec    *pspec);
102 gpointer        g_param_spec_get_qdata          (GParamSpec    *pspec,
103                                                  GQuark         quark);
104 void            g_param_spec_set_qdata          (GParamSpec    *pspec,
105                                                  GQuark         quark,
106                                                  gpointer       data);
107 void            g_param_spec_set_qdata_full     (GParamSpec    *pspec,
108                                                  GQuark         quark,
109                                                  gpointer       data,
110                                                  GDestroyNotify destroy);
111 gpointer        g_param_spec_steal_qdata        (GParamSpec    *pspec,
112                                                  GQuark         quark);
113 void            g_param_value_set_default       (GParamSpec    *pspec,
114                                                  GValue        *value);
115 gboolean        g_param_value_defaults          (GParamSpec    *pspec,
116                                                  GValue        *value);
117 gboolean        g_param_value_validate          (GParamSpec    *pspec,
118                                                  GValue        *value);
119 gboolean        g_param_value_convert           (GParamSpec    *dest_value_spec,
120                                                  const GValue  *src_value,
121                                                  GValue        *dest_value,
122                                                  gboolean       strict_validation);
123 gint            g_param_values_cmp              (GParamSpec    *pspec,
124                                                  const GValue  *value1,
125                                                  const GValue  *value2);
126 void            g_value_set_param               (GValue        *value,
127                                                  GParamSpec    *param);
128 GParamSpec*     g_value_get_param               (const GValue  *value);
129 GParamSpec*     g_value_dup_param               (const GValue  *value);
130
131
132 /* --- convenience functions --- */
133 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
134 struct _GParamSpecTypeInfo
135 {
136   /* type system portion */
137   guint16         instance_size;                               /* obligatory */
138   guint16         n_preallocs;                                 /* optional */
139   void          (*instance_init)        (GParamSpec   *pspec); /* optional */
140
141   /* class portion */
142   GType           value_type;                                  /* obligatory */
143   void          (*finalize)             (GParamSpec   *pspec); /* optional */
144   void          (*value_set_default)    (GParamSpec   *pspec,  /* recommended */
145                                          GValue       *value);
146   gboolean      (*value_validate)       (GParamSpec   *pspec,  /* optional */
147                                          GValue       *value);
148   gint          (*values_cmp)           (GParamSpec   *pspec,  /* recommended */
149                                          const GValue *value1,
150                                          const GValue *value2);
151 };
152 GType   g_param_type_register_static    (const gchar              *name,
153                                          const GParamSpecTypeInfo *pspec_info);
154
155
156 /* --- protected --- */
157 gpointer        g_param_spec_internal           (GType          param_type,
158                                                  const gchar   *name,
159                                                  const gchar   *nick,
160                                                  const gchar   *blurb,
161                                                  GParamFlags    flags);
162 GParamSpecPool* g_param_spec_pool_new           (gboolean       type_prefixing);
163 void            g_param_spec_pool_insert        (GParamSpecPool *pool,
164                                                  GParamSpec     *pspec,
165                                                  GType           owner_type);
166 void            g_param_spec_pool_remove        (GParamSpecPool *pool,
167                                                  GParamSpec     *pspec);
168 GParamSpec*     g_param_spec_pool_lookup        (GParamSpecPool *pool,
169                                                  const gchar    *param_name,
170                                                  GType           owner_type,
171                                                  gboolean        walk_ancestors);
172
173
174 /* contracts:
175  *
176  * gboolean value_validate (GParamSpec *pspec,
177  *                          GValue     *value):
178  *      modify value contents in the least destructive way, so
179  *      that it complies with pspec's requirements (i.e.
180  *      according to minimum/maximum ranges etc...). return
181  *      whether modification was necessary.
182  *
183  * gint values_cmp (GParamSpec   *pspec,
184  *                  const GValue *value1,
185  *                  const GValue *value2):
186  *      return value1 - value2, i.e. <0 if value1 < value2,
187  *      >0 if value1 > value2, and 0 otherwise (they are equal)
188  */
189
190 #ifdef __cplusplus
191 }
192 #endif /* __cplusplus */
193
194 #endif /* __G_PARAM_H__ */