genums.h

Go to the documentation of this file.
00001 /* GObject - GLib Type, Object, Parameter and Signal Library
00002  * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
00003  * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General
00016  * Public License along with this library; if not, write to the
00017  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00018  * Boston, MA 02111-1307, USA.
00019  */
00020 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
00021 #error "Only <glib-object.h> can be included directly."
00022 #endif
00023 
00024 #ifndef __G_ENUMS_H__
00025 #define __G_ENUMS_H__
00026 
00027 #include <_ansi.h>
00028 #include <gobject/gtype.h>
00029 
00030 G_BEGIN_DECLS
00031 
00032 /* --- type macros --- */
00033 #define G_TYPE_IS_ENUM(type)           (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM)
00034 #define G_ENUM_CLASS(class)            (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_ENUM, GEnumClass))
00035 #define G_IS_ENUM_CLASS(class)         (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_ENUM))
00036 #define G_ENUM_CLASS_TYPE(class)       (G_TYPE_FROM_CLASS (class))
00037 #define G_ENUM_CLASS_TYPE_NAME(class)  (g_type_name (G_ENUM_CLASS_TYPE (class)))
00038 #define G_TYPE_IS_FLAGS(type)          (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS)
00039 #define G_FLAGS_CLASS(class)           (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_FLAGS, GFlagsClass))
00040 #define G_IS_FLAGS_CLASS(class)        (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_FLAGS))
00041 #define G_FLAGS_CLASS_TYPE(class)      (G_TYPE_FROM_CLASS (class))
00042 #define G_FLAGS_CLASS_TYPE_NAME(class) (g_type_name (G_FLAGS_CLASS_TYPE (class)))
00043 #define G_VALUE_HOLDS_ENUM(value)      (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ENUM))
00044 #define G_VALUE_HOLDS_FLAGS(value)     (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLAGS))
00045 
00046 
00047 /* --- enum/flag values & classes --- */
00048 typedef struct _GEnumClass  GEnumClass;
00049 typedef struct _GFlagsClass GFlagsClass;
00050 typedef struct _GEnumValue  GEnumValue;
00051 typedef struct _GFlagsValue GFlagsValue;
00052 struct  _GEnumClass
00053 {
00054   GTypeClass  g_type_class;
00055 
00056   /*< public >*/  
00057   gint        minimum;
00058   gint        maximum;
00059   guint       n_values;
00060   GEnumValue *values;
00061 };
00062 struct  _GFlagsClass
00063 {
00064   GTypeClass   g_type_class;
00065   
00066   /*< public >*/  
00067   guint        mask;
00068   guint        n_values;
00069   GFlagsValue *values;
00070 };
00071 struct _GEnumValue
00072 {
00073   gint   value;
00074   gchar *value_name;
00075   gchar *value_nick;
00076 };
00077 struct _GFlagsValue
00078 {
00079   guint  value;
00080   gchar *value_name;
00081   gchar *value_nick;
00082 };
00083 
00084 
00085 /* --- prototypes --- */
00086 IMPORT_C GEnumValue*    g_enum_get_value                (GEnumClass     *enum_class,
00087                                                  gint            value);
00088 IMPORT_C GEnumValue*    g_enum_get_value_by_name        (GEnumClass     *enum_class,
00089                                                  const gchar    *name);
00090 IMPORT_C GEnumValue*    g_enum_get_value_by_nick        (GEnumClass     *enum_class,
00091                                                  const gchar    *nick);
00092 IMPORT_C GFlagsValue*   g_flags_get_first_value         (GFlagsClass    *flags_class,
00093                                                  guint           value);
00094 IMPORT_C GFlagsValue*   g_flags_get_value_by_name       (GFlagsClass    *flags_class,
00095                                                  const gchar    *name);
00096 IMPORT_C GFlagsValue*   g_flags_get_value_by_nick       (GFlagsClass    *flags_class,
00097                                                  const gchar    *nick);
00098 IMPORT_C void            g_value_set_enum               (GValue         *value,
00099                                                  gint            v_enum);
00100 IMPORT_C gint            g_value_get_enum               (const GValue   *value);
00101 IMPORT_C void            g_value_set_flags              (GValue         *value,
00102                                                  guint           v_flags);
00103 IMPORT_C guint           g_value_get_flags              (const GValue   *value);
00104 
00105 
00106 
00107 /* --- registration functions --- */
00108 /* const_static_values is a NULL terminated array of enum/flags
00109  * values that is taken over!
00110  */
00111 IMPORT_C GType  g_enum_register_static     (const gchar       *name,
00112                                     const GEnumValue  *const_static_values);
00113 IMPORT_C GType  g_flags_register_static    (const gchar       *name,
00114                                     const GFlagsValue *const_static_values);
00115 /* functions to complete the type information
00116  * for enums/flags implemented by plugins
00117  */
00118 IMPORT_C void   g_enum_complete_type_info  (GType              g_enum_type,
00119                                     GTypeInfo         *info,
00120                                     const GEnumValue  *const_values);
00121 IMPORT_C void   g_flags_complete_type_info (GType              g_flags_type,
00122                                     GTypeInfo         *info,
00123                                     const GFlagsValue *const_values);
00124 
00125 G_END_DECLS
00126 
00127 #endif /* __G_ENUMS_H__ */

Copyright © Nokia Corporation 2001-2008
Back to top