updated externals
[platform/upstream/glib.git] / gobject / genums.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1998-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 #ifndef __G_ENUMS_H__
20 #define __G_ENUMS_H__
21
22 #include <gobject/gtype.h>
23
24 G_BEGIN_DECLS
25
26 /* --- type macros --- */
27 #define G_TYPE_IS_ENUM(type)           (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM)
28 #define G_ENUM_CLASS(class)            (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_ENUM, GEnumClass))
29 #define G_IS_ENUM_CLASS(class)         (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_ENUM))
30 #define G_ENUM_CLASS_TYPE(class)       (G_TYPE_FROM_CLASS (class))
31 #define G_ENUM_CLASS_TYPE_NAME(class)  (g_type_name (G_ENUM_CLASS_TYPE (class)))
32 #define G_TYPE_IS_FLAGS(type)          (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS)
33 #define G_FLAGS_CLASS(class)           (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_FLAGS, GFlagsClass))
34 #define G_IS_FLAGS_CLASS(class)        (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_FLAGS))
35 #define G_FLAGS_CLASS_TYPE(class)      (G_TYPE_FROM_CLASS (class))
36 #define G_FLAGS_CLASS_TYPE_NAME(class) (g_type_name (G_FLAGS_TYPE (class)))
37 #define G_VALUE_HOLDS_ENUM(value)      (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ENUM))
38 #define G_VALUE_HOLDS_FLAGS(value)     (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLAGS))
39
40
41 /* --- enum/flag values & classes --- */
42 typedef struct _GEnumClass  GEnumClass;
43 typedef struct _GFlagsClass GFlagsClass;
44 typedef struct _GEnumValue  GEnumValue;
45 typedef struct _GFlagsValue GFlagsValue;
46 struct  _GEnumClass
47 {
48   GTypeClass  g_type_class;
49   
50   gint        minimum;
51   gint        maximum;
52   guint       n_values;
53   GEnumValue *values;
54 };
55 struct  _GFlagsClass
56 {
57   GTypeClass   g_type_class;
58   
59   guint        mask;
60   guint        n_values;
61   GFlagsValue *values;
62 };
63 struct _GEnumValue
64 {
65   gint   value;
66   gchar *value_name;
67   gchar *value_nick;
68 };
69 struct _GFlagsValue
70 {
71   guint  value;
72   gchar *value_name;
73   gchar *value_nick;
74 };
75
76
77 /* --- prototypes --- */
78 GEnumValue*     g_enum_get_value                (GEnumClass     *enum_class,
79                                                  gint            value);
80 GEnumValue*     g_enum_get_value_by_name        (GEnumClass     *enum_class,
81                                                  const gchar    *name);
82 GEnumValue*     g_enum_get_value_by_nick        (GEnumClass     *enum_class,
83                                                  const gchar    *nick);
84 GFlagsValue*    g_flags_get_first_value         (GFlagsClass    *flags_class,
85                                                  guint           value);
86 GFlagsValue*    g_flags_get_value_by_name       (GFlagsClass    *flags_class,
87                                                  const gchar    *name);
88 GFlagsValue*    g_flags_get_value_by_nick       (GFlagsClass    *flags_class,
89                                                  const gchar    *nick);
90 void            g_value_set_enum                (GValue         *value,
91                                                  gint            v_enum);
92 gint            g_value_get_enum                (const GValue   *value);
93 void            g_value_set_flags               (GValue         *value,
94                                                  guint           v_flags);
95 guint           g_value_get_flags               (const GValue   *value);
96
97
98
99 /* --- registration functions --- */
100 /* const_static_values is a NULL terminated array of enum/flags
101  * values that is taken over!
102  */
103 GType   g_enum_register_static     (const gchar       *name,
104                                     const GEnumValue  *const_static_values);
105 GType   g_flags_register_static    (const gchar       *name,
106                                     const GFlagsValue *const_static_values);
107 /* functions to complete the type information
108  * for enums/flags implemented by plugins
109  */
110 void    g_enum_complete_type_info  (GType              g_enum_type,
111                                     GTypeInfo         *info,
112                                     const GEnumValue  *const_values);
113 void    g_flags_complete_type_info (GType              g_flags_type,
114                                     GTypeInfo         *info,
115                                     const GFlagsValue *const_values);
116
117 G_END_DECLS
118
119 #endif /* __G_ENUMS_H__ */