added newly added gobject/ headers.
[platform/upstream/glib.git] / gobject / gparam.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1997, 1998, 1999, 2000 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_IS_PARAM_VALUE(pspec, value)  (g_type_is_a (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (pspec))) /* FIXME */
41 #define G_PARAM_SPEC_VALUE_TYPE(pspec)  (G_PARAM_SPEC_GET_CLASS (pspec)->value_type)
42
43
44 /* --- flags --- */
45 typedef enum
46 {
47   G_PARAM_READABLE            = 1 << 0,
48   G_PARAM_WRITABLE            = 1 << 1,
49   G_PARAM_MASK                = 0x000f,
50   /* bits in the range 0xfff0 are reserved for 3rd party usage */
51   G_PARAM_USER_MASK           = 0xfff0
52 } GParamFlags;
53
54
55 /* --- typedefs & structures --- */
56 typedef struct _GParamSpecClass GParamSpecClass;
57 typedef struct _GParamSpec      GParamSpec;
58 struct _GParamSpecClass
59 {
60   GTypeClass      g_type_class;
61
62   GType           value_type;
63
64   void          (*finalize)             (GParamSpec   *pspec);
65
66   /* GParam methods */
67   void          (*value_set_default)    (GParamSpec   *pspec,
68                                          GValue       *value);
69   gboolean      (*value_validate)       (GParamSpec   *pspec,
70                                          GValue       *value);
71   gint          (*values_cmp)           (GParamSpec   *pspec,
72                                          const GValue *value1,
73                                          const GValue *value2);
74 };
75 struct _GParamSpec
76 {
77   GTypeInstance  g_instance;
78
79   gchar         *name;
80   gchar         *nick;
81   gchar         *blurb;
82   GParamFlags    flags;
83
84   /*< private >*/
85   GType          owner_type;
86   GData         *qdata;
87   guint          ref_count;
88 };
89
90
91 /* --- prototypes --- */
92 GParamSpec*     g_param_spec_ref                (GParamSpec    *pspec);
93 void            g_param_spec_unref              (GParamSpec    *pspec);
94 gpointer        g_param_spec_get_qdata          (GParamSpec    *pspec,
95                                                  GQuark         quark);
96 void            g_param_spec_set_qdata          (GParamSpec    *pspec,
97                                                  GQuark         quark,
98                                                  gpointer       data);
99 void            g_param_spec_set_qdata_full     (GParamSpec    *pspec,
100                                                  GQuark         quark,
101                                                  gpointer       data,
102                                                  GDestroyNotify destroy);
103 gpointer        g_param_spec_steal_qdata        (GParamSpec    *pspec,
104                                                  GQuark         quark);
105 void            g_param_value_set_default       (GParamSpec    *pspec,
106                                                  GValue        *value);
107 gboolean        g_param_value_defaults          (GParamSpec    *pspec,
108                                                  GValue        *value);
109 gboolean        g_param_value_validate          (GParamSpec    *pspec,
110                                                  GValue        *value);
111 gint            g_param_values_cmp              (GParamSpec    *pspec,
112                                                  const GValue  *value1,
113                                                  const GValue  *value2);
114
115
116 /* --- convenience functions --- */
117 typedef struct _GParamSpecTypeInfo GParamSpecTypeInfo;
118 struct _GParamSpecTypeInfo
119 {
120   /* type system portion */
121   guint16         instance_size;                               /* obligatory */
122   guint16         n_preallocs;                                 /* optional */
123   void          (*instance_init)        (GParamSpec   *pspec); /* optional */
124
125   /* class portion */
126   GType           value_type;                                  /* obligatory */
127   void          (*finalize)             (GParamSpec   *pspec); /* optional */
128   void          (*value_set_default)    (GParamSpec   *pspec,  /* recommended */
129                                          GValue       *value);
130   gboolean      (*value_validate)       (GParamSpec   *pspec,  /* optional */
131                                          GValue       *value);
132   gint          (*values_cmp)           (GParamSpec   *pspec,  /* recommended */
133                                          const GValue *value1,
134                                          const GValue *value2);
135 };
136 GType   g_param_type_register_static    (const gchar              *name,
137                                          const GParamSpecTypeInfo *pspec_info);
138
139
140 /* --- private --- */
141 gpointer        g_param_spec_internal           (GType          param_type,
142                                                  const gchar   *name,
143                                                  const gchar   *nick,
144                                                  const gchar   *blurb,
145                                                  GParamFlags    flags);
146 GHashTable*     g_param_spec_hash_table_new     (void);
147 void            g_param_spec_hash_table_insert  (GHashTable    *hash_table,
148                                                  GParamSpec    *pspec,
149                                                  GType          owner_type);
150 void            g_param_spec_hash_table_remove  (GHashTable    *hash_table,
151                                                  GParamSpec    *pspec);
152 GParamSpec*     g_param_spec_hash_table_lookup  (GHashTable    *hash_table,
153                                                  const gchar   *param_name,
154                                                  GType          owner_type,
155                                                  gboolean       try_ancestors,
156                                                  const gchar  **trailer);
157
158
159 /* contracts:
160  *
161  * gboolean value_validate (GParamSpec *pspec,
162  *                          GValue     *value):
163  *      modify value contents in the least destructive way, so
164  *      that it complies with pspec's requirements (i.e.
165  *      according to minimum/maximum ranges etc...). return
166  *      whether modification was necessary.
167  *
168  * gint values_cmp (GParamSpec   *pspec,
169  *                  const GValue *value1,
170  *                  const GValue *value2):
171  *      return value1 - value2, i.e. <0 if value1 < value2,
172  *      >0 if value1 > value2, and 0 otherwise (they are equal)
173  */
174
175 #ifdef __cplusplus
176 }
177 #endif /* __cplusplus */
178
179 #endif /* __G_PARAM_H__ */