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