added g_list_nth_prev() which walks ->prev instead of ->next.
[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 _GParamSpecPool  GParamSpecPool;
60 struct _GParamSpec
61 {
62   GTypeInstance  g_type_instance;
63
64   gchar         *name;
65   gchar         *nick;
66   gchar         *blurb;
67   GParamFlags    flags;
68   GType          value_type;
69
70   /*< private >*/
71   GType          owner_type;
72   GData         *qdata;
73   guint          ref_count;
74 };
75 struct _GParamSpecClass
76 {
77   GTypeClass      g_type_class;
78
79   GType           value_type;
80
81   void          (*finalize)             (GParamSpec   *pspec);
82
83   /* GParam methods */
84   void          (*value_set_default)    (GParamSpec   *pspec,
85                                          GValue       *value);
86   gboolean      (*value_validate)       (GParamSpec   *pspec,
87                                          GValue       *value);
88   gint          (*values_cmp)           (GParamSpec   *pspec,
89                                          const GValue *value1,
90                                          const GValue *value2);
91 };
92
93
94 /* --- prototypes --- */
95 GParamSpec*     g_param_spec_ref                (GParamSpec    *pspec);
96 void            g_param_spec_unref              (GParamSpec    *pspec);
97 void            g_param_spec_sink               (GParamSpec    *pspec);
98 gpointer        g_param_spec_get_qdata          (GParamSpec    *pspec,
99                                                  GQuark         quark);
100 void            g_param_spec_set_qdata          (GParamSpec    *pspec,
101                                                  GQuark         quark,
102                                                  gpointer       data);
103 void            g_param_spec_set_qdata_full     (GParamSpec    *pspec,
104                                                  GQuark         quark,
105                                                  gpointer       data,
106                                                  GDestroyNotify destroy);
107 gpointer        g_param_spec_steal_qdata        (GParamSpec    *pspec,
108                                                  GQuark         quark);
109 void            g_param_value_set_default       (GParamSpec    *pspec,
110                                                  GValue        *value);
111 gboolean        g_param_value_defaults          (GParamSpec    *pspec,
112                                                  GValue        *value);
113 gboolean        g_param_value_validate          (GParamSpec    *pspec,
114                                                  GValue        *value);
115 gboolean        g_param_value_convert           (GParamSpec    *dest_value_spec,
116                                                  const GValue  *src_value,
117                                                  GValue        *dest_value,
118                                                  gboolean       strict_validation);
119 gint            g_param_values_cmp              (GParamSpec    *pspec,
120                                                  const GValue  *value1,
121                                                  const GValue  *value2);
122 void            g_value_set_param               (GValue        *value,
123                                                  GParamSpec    *param);
124 GParamSpec*     g_value_get_param               (const GValue  *value);
125 GParamSpec*     g_value_dup_param               (const GValue  *value);
126
127
128 /* --- convenience functions --- */
129 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
130 struct _GParamSpecTypeInfo
131 {
132   /* type system portion */
133   guint16         instance_size;                               /* obligatory */
134   guint16         n_preallocs;                                 /* optional */
135   void          (*instance_init)        (GParamSpec   *pspec); /* optional */
136
137   /* class portion */
138   GType           value_type;                                  /* obligatory */
139   void          (*finalize)             (GParamSpec   *pspec); /* optional */
140   void          (*value_set_default)    (GParamSpec   *pspec,  /* recommended */
141                                          GValue       *value);
142   gboolean      (*value_validate)       (GParamSpec   *pspec,  /* optional */
143                                          GValue       *value);
144   gint          (*values_cmp)           (GParamSpec   *pspec,  /* recommended */
145                                          const GValue *value1,
146                                          const GValue *value2);
147 };
148 GType   g_param_type_register_static    (const gchar              *name,
149                                          const GParamSpecTypeInfo *pspec_info);
150
151
152 /* --- protected --- */
153 gpointer        g_param_spec_internal           (GType          param_type,
154                                                  const gchar   *name,
155                                                  const gchar   *nick,
156                                                  const gchar   *blurb,
157                                                  GParamFlags    flags);
158 GParamSpecPool* g_param_spec_pool_new           (gboolean       type_prefixing);
159 void            g_param_spec_pool_insert        (GParamSpecPool *pool,
160                                                  GParamSpec     *pspec,
161                                                  GType           owner_type);
162 void            g_param_spec_pool_remove        (GParamSpecPool *pool,
163                                                  GParamSpec     *pspec);
164 GParamSpec*     g_param_spec_pool_lookup        (GParamSpecPool *pool,
165                                                  const gchar    *param_name,
166                                                  GType           owner_type,
167                                                  gboolean        walk_ancestors);
168 GList*          g_param_spec_pool_list          (GParamSpecPool *pool,
169                                                  GType           owner_type);
170
171
172
173 /* contracts:
174  *
175  * gboolean value_validate (GParamSpec *pspec,
176  *                          GValue     *value):
177  *      modify value contents in the least destructive way, so
178  *      that it complies with pspec's requirements (i.e.
179  *      according to minimum/maximum ranges etc...). return
180  *      whether modification was necessary.
181  *
182  * gint values_cmp (GParamSpec   *pspec,
183  *                  const GValue *value1,
184  *                  const GValue *value2):
185  *      return value1 - value2, i.e. <0 if value1 < value2,
186  *      >0 if value1 > value2, and 0 otherwise (they are equal)
187  */
188
189 G_END_DECLS
190
191 #endif /* __G_PARAM_H__ */