1 /* 2 * Distributed under the Boost Software License, Version 1.0. 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 * http://www.boost.org/LICENSE_1_0.txt) 5 */ 6 module gobject.genums; 7 8 import gobject.gtype; 9 import gobject.gvalue; 10 11 import glib; 12 13 // /* --- type macros --- */ 14 // /** 15 // * G_TYPE_IS_ENUM: 16 // * @type: a #GType ID. 17 // * 18 // * Checks whether @type "is a" %G_TYPE_ENUM. 19 // * 20 // * Returns: %TRUE if @type "is a" %G_TYPE_ENUM. 21 // */ 22 // #define G_TYPE_IS_ENUM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM) 23 // /** 24 // * G_ENUM_CLASS: 25 // * @class: a valid #GEnumClass 26 // * 27 // * Casts a derived #GEnumClass structure into a #GEnumClass structure. 28 // */ 29 // #define G_ENUM_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_ENUM, GEnumClass)) 30 // /** 31 // * G_IS_ENUM_CLASS: 32 // * @class: a #GEnumClass 33 // * 34 // * Checks whether @class "is a" valid #GEnumClass structure of type %G_TYPE_ENUM 35 // * or derived. 36 // */ 37 // #define G_IS_ENUM_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_ENUM)) 38 // /** 39 // * G_ENUM_CLASS_TYPE: 40 // * @class: a #GEnumClass 41 // * 42 // * Get the type identifier from a given #GEnumClass structure. 43 // * 44 // * Returns: the #GType 45 // */ 46 // #define G_ENUM_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class)) 47 // /** 48 // * G_ENUM_CLASS_TYPE_NAME: 49 // * @class: a #GEnumClass 50 // * 51 // * Get the static type name from a given #GEnumClass structure. 52 // * 53 // * Returns: the type name. 54 // */ 55 // #define G_ENUM_CLASS_TYPE_NAME(class) (g_type_name (G_ENUM_CLASS_TYPE (class))) 56 // 57 // 58 // /** 59 // * G_TYPE_IS_FLAGS: 60 // * @type: a #GType ID. 61 // * 62 // * Checks whether @type "is a" %G_TYPE_FLAGS. 63 // * 64 // * Returns: %TRUE if @type "is a" %G_TYPE_FLAGS. 65 // */ 66 // #define G_TYPE_IS_FLAGS(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS) 67 // /** 68 // * G_FLAGS_CLASS: 69 // * @class: a valid #GFlagsClass 70 // * 71 // * Casts a derived #GFlagsClass structure into a #GFlagsClass structure. 72 // */ 73 // #define G_FLAGS_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_FLAGS, GFlagsClass)) 74 // /** 75 // * G_IS_FLAGS_CLASS: 76 // * @class: a #GFlagsClass 77 // * 78 // * Checks whether @class "is a" valid #GFlagsClass structure of type %G_TYPE_FLAGS 79 // * or derived. 80 // */ 81 // #define G_IS_FLAGS_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_FLAGS)) 82 // /** 83 // * G_FLAGS_CLASS_TYPE: 84 // * @class: a #GFlagsClass 85 // * 86 // * Get the type identifier from a given #GFlagsClass structure. 87 // * 88 // * Returns: the #GType 89 // */ 90 // #define G_FLAGS_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class)) 91 // /** 92 // * G_FLAGS_CLASS_TYPE_NAME: 93 // * @class: a #GFlagsClass 94 // * 95 // * Get the static type name from a given #GFlagsClass structure. 96 // * 97 // * Returns: the type name. 98 // */ 99 // #define G_FLAGS_CLASS_TYPE_NAME(class) (g_type_name (G_FLAGS_CLASS_TYPE (class))) 100 // 101 // 102 // /** 103 // * G_VALUE_HOLDS_ENUM: 104 // * @value: a valid #GValue structure 105 // * 106 // * Checks whether the given #GValue can hold values derived from type %G_TYPE_ENUM. 107 // * 108 // * Returns: %TRUE on success. 109 // */ 110 // #define G_VALUE_HOLDS_ENUM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ENUM)) 111 // /** 112 // * G_VALUE_HOLDS_FLAGS: 113 // * @value: a valid #GValue structure 114 // * 115 // * Checks whether the given #GValue can hold values derived from type %G_TYPE_FLAGS. 116 // * 117 // * Returns: %TRUE on success. 118 // */ 119 // #define G_VALUE_HOLDS_FLAGS(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLAGS)) 120 121 122 123 struct GEnumClass 124 { 125 GTypeClass g_type_class; 126 127 /*< public >*/ 128 gint minimum; 129 gint maximum; 130 guint n_values; 131 GEnumValue *values; 132 } 133 134 struct GFlagsClass 135 { 136 GTypeClass g_type_class; 137 138 /*< public >*/ 139 guint mask; 140 guint n_values; 141 GFlagsValue *values; 142 } 143 144 struct GEnumValue 145 { 146 gint value; 147 const(gchar) *value_name; 148 const(gchar) *value_nick; 149 } 150 151 struct GFlagsValue 152 { 153 guint value; 154 const(gchar) *value_name; 155 const(gchar) *value_nick; 156 } 157 158 159 160 GEnumValue* g_enum_get_value (GEnumClass *enum_class, 161 gint value); 162 163 GEnumValue* g_enum_get_value_by_name (GEnumClass *enum_class, 164 const(gchar) *name); 165 166 GEnumValue* g_enum_get_value_by_nick (GEnumClass *enum_class, 167 const(gchar) *nick); 168 169 GFlagsValue* g_flags_get_first_value (GFlagsClass *flags_class, 170 guint value); 171 172 GFlagsValue* g_flags_get_value_by_name (GFlagsClass *flags_class, 173 const(gchar) *name); 174 175 GFlagsValue* g_flags_get_value_by_nick (GFlagsClass *flags_class, 176 const(gchar) *nick); 177 178 void g_value_set_enum (GValue *value, 179 gint v_enum); 180 181 gint g_value_get_enum (const(GValue) *value); 182 183 void g_value_set_flags (GValue *value, 184 guint v_flags); 185 186 guint g_value_get_flags (const(GValue) *value); 187 188 189 190 191 GType g_enum_register_static (const(gchar) *name, 192 const(GEnumValue) *const_static_values); 193 194 GType g_flags_register_static (const(gchar) *name, 195 const(GFlagsValue) *const_static_values); 196 /* functions to complete the type information 197 * for enums/flags implemented by plugins 198 */ 199 200 void g_enum_complete_type_info (GType g_enum_type, 201 GTypeInfo *info, 202 const(GEnumValue) *const_values); 203 204 void g_flags_complete_type_info (GType g_flags_type, 205 GTypeInfo *info, 206 const(GFlagsValue) *const_values); 207