genums.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __G_ENUMS_H__
  18. #define __G_ENUMS_H__
  19. #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
  20. #error "Only <glib-object.h> can be included directly."
  21. #endif
  22. #include <gobject/gtype.h>
  23. G_BEGIN_DECLS
  24. /* --- type macros --- */
  25. /**
  26. * G_TYPE_IS_ENUM:
  27. * @type: a #GType ID.
  28. *
  29. * Checks whether @type "is a" %G_TYPE_ENUM.
  30. *
  31. * Returns: %TRUE if @type "is a" %G_TYPE_ENUM.
  32. */
  33. #define G_TYPE_IS_ENUM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM)
  34. /**
  35. * G_ENUM_CLASS:
  36. * @class: a valid #GEnumClass
  37. *
  38. * Casts a derived #GEnumClass structure into a #GEnumClass structure.
  39. */
  40. #define G_ENUM_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_ENUM, GEnumClass))
  41. /**
  42. * G_IS_ENUM_CLASS:
  43. * @class: a #GEnumClass
  44. *
  45. * Checks whether @class "is a" valid #GEnumClass structure of type %G_TYPE_ENUM
  46. * or derived.
  47. */
  48. #define G_IS_ENUM_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_ENUM))
  49. /**
  50. * G_ENUM_CLASS_TYPE:
  51. * @class: a #GEnumClass
  52. *
  53. * Get the type identifier from a given #GEnumClass structure.
  54. *
  55. * Returns: the #GType
  56. */
  57. #define G_ENUM_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
  58. /**
  59. * G_ENUM_CLASS_TYPE_NAME:
  60. * @class: a #GEnumClass
  61. *
  62. * Get the static type name from a given #GEnumClass structure.
  63. *
  64. * Returns: the type name.
  65. */
  66. #define G_ENUM_CLASS_TYPE_NAME(class) (g_type_name (G_ENUM_CLASS_TYPE (class)))
  67. /**
  68. * G_TYPE_IS_FLAGS:
  69. * @type: a #GType ID.
  70. *
  71. * Checks whether @type "is a" %G_TYPE_FLAGS.
  72. *
  73. * Returns: %TRUE if @type "is a" %G_TYPE_FLAGS.
  74. */
  75. #define G_TYPE_IS_FLAGS(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS)
  76. /**
  77. * G_FLAGS_CLASS:
  78. * @class: a valid #GFlagsClass
  79. *
  80. * Casts a derived #GFlagsClass structure into a #GFlagsClass structure.
  81. */
  82. #define G_FLAGS_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_FLAGS, GFlagsClass))
  83. /**
  84. * G_IS_FLAGS_CLASS:
  85. * @class: a #GFlagsClass
  86. *
  87. * Checks whether @class "is a" valid #GFlagsClass structure of type %G_TYPE_FLAGS
  88. * or derived.
  89. */
  90. #define G_IS_FLAGS_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_FLAGS))
  91. /**
  92. * G_FLAGS_CLASS_TYPE:
  93. * @class: a #GFlagsClass
  94. *
  95. * Get the type identifier from a given #GFlagsClass structure.
  96. *
  97. * Returns: the #GType
  98. */
  99. #define G_FLAGS_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
  100. /**
  101. * G_FLAGS_CLASS_TYPE_NAME:
  102. * @class: a #GFlagsClass
  103. *
  104. * Get the static type name from a given #GFlagsClass structure.
  105. *
  106. * Returns: the type name.
  107. */
  108. #define G_FLAGS_CLASS_TYPE_NAME(class) (g_type_name (G_FLAGS_CLASS_TYPE (class)))
  109. /**
  110. * G_VALUE_HOLDS_ENUM:
  111. * @value: a valid #GValue structure
  112. *
  113. * Checks whether the given #GValue can hold values derived from type %G_TYPE_ENUM.
  114. *
  115. * Returns: %TRUE on success.
  116. */
  117. #define G_VALUE_HOLDS_ENUM(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ENUM))
  118. /**
  119. * G_VALUE_HOLDS_FLAGS:
  120. * @value: a valid #GValue structure
  121. *
  122. * Checks whether the given #GValue can hold values derived from type %G_TYPE_FLAGS.
  123. *
  124. * Returns: %TRUE on success.
  125. */
  126. #define G_VALUE_HOLDS_FLAGS(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLAGS))
  127. /* --- enum/flag values & classes --- */
  128. typedef struct _GEnumClass GEnumClass;
  129. typedef struct _GFlagsClass GFlagsClass;
  130. typedef struct _GEnumValue GEnumValue;
  131. typedef struct _GFlagsValue GFlagsValue;
  132. /**
  133. * GEnumClass:
  134. * @g_type_class: the parent class
  135. * @minimum: the smallest possible value.
  136. * @maximum: the largest possible value.
  137. * @n_values: the number of possible values.
  138. * @values: an array of #GEnumValue structs describing the
  139. * individual values.
  140. *
  141. * The class of an enumeration type holds information about its
  142. * possible values.
  143. */
  144. struct _GEnumClass
  145. {
  146. GTypeClass g_type_class;
  147. /*< public >*/
  148. gint minimum;
  149. gint maximum;
  150. guint n_values;
  151. GEnumValue *values;
  152. };
  153. /**
  154. * GFlagsClass:
  155. * @g_type_class: the parent class
  156. * @mask: a mask covering all possible values.
  157. * @n_values: the number of possible values.
  158. * @values: an array of #GFlagsValue structs describing the
  159. * individual values.
  160. *
  161. * The class of a flags type holds information about its
  162. * possible values.
  163. */
  164. struct _GFlagsClass
  165. {
  166. GTypeClass g_type_class;
  167. /*< public >*/
  168. guint mask;
  169. guint n_values;
  170. GFlagsValue *values;
  171. };
  172. /**
  173. * GEnumValue:
  174. * @value: the enum value
  175. * @value_name: the name of the value
  176. * @value_nick: the nickname of the value
  177. *
  178. * A structure which contains a single enum value, its name, and its
  179. * nickname.
  180. */
  181. struct _GEnumValue
  182. {
  183. gint value;
  184. const gchar *value_name;
  185. const gchar *value_nick;
  186. };
  187. /**
  188. * GFlagsValue:
  189. * @value: the flags value
  190. * @value_name: the name of the value
  191. * @value_nick: the nickname of the value
  192. *
  193. * A structure which contains a single flags value, its name, and its
  194. * nickname.
  195. */
  196. struct _GFlagsValue
  197. {
  198. guint value;
  199. const gchar *value_name;
  200. const gchar *value_nick;
  201. };
  202. /* --- prototypes --- */
  203. GLIB_AVAILABLE_IN_ALL
  204. GEnumValue* g_enum_get_value (GEnumClass *enum_class,
  205. gint value);
  206. GLIB_AVAILABLE_IN_ALL
  207. GEnumValue* g_enum_get_value_by_name (GEnumClass *enum_class,
  208. const gchar *name);
  209. GLIB_AVAILABLE_IN_ALL
  210. GEnumValue* g_enum_get_value_by_nick (GEnumClass *enum_class,
  211. const gchar *nick);
  212. GLIB_AVAILABLE_IN_ALL
  213. GFlagsValue* g_flags_get_first_value (GFlagsClass *flags_class,
  214. guint value);
  215. GLIB_AVAILABLE_IN_ALL
  216. GFlagsValue* g_flags_get_value_by_name (GFlagsClass *flags_class,
  217. const gchar *name);
  218. GLIB_AVAILABLE_IN_ALL
  219. GFlagsValue* g_flags_get_value_by_nick (GFlagsClass *flags_class,
  220. const gchar *nick);
  221. GLIB_AVAILABLE_IN_ALL
  222. void g_value_set_enum (GValue *value,
  223. gint v_enum);
  224. GLIB_AVAILABLE_IN_ALL
  225. gint g_value_get_enum (const GValue *value);
  226. GLIB_AVAILABLE_IN_ALL
  227. void g_value_set_flags (GValue *value,
  228. guint v_flags);
  229. GLIB_AVAILABLE_IN_ALL
  230. guint g_value_get_flags (const GValue *value);
  231. /* --- registration functions --- */
  232. /* const_static_values is a NULL terminated array of enum/flags
  233. * values that is taken over!
  234. */
  235. GLIB_AVAILABLE_IN_ALL
  236. GType g_enum_register_static (const gchar *name,
  237. const GEnumValue *const_static_values);
  238. GLIB_AVAILABLE_IN_ALL
  239. GType g_flags_register_static (const gchar *name,
  240. const GFlagsValue *const_static_values);
  241. /* functions to complete the type information
  242. * for enums/flags implemented by plugins
  243. */
  244. GLIB_AVAILABLE_IN_ALL
  245. void g_enum_complete_type_info (GType g_enum_type,
  246. GTypeInfo *info,
  247. const GEnumValue *const_values);
  248. GLIB_AVAILABLE_IN_ALL
  249. void g_flags_complete_type_info (GType g_flags_type,
  250. GTypeInfo *info,
  251. const GFlagsValue *const_values);
  252. G_END_DECLS
  253. #endif /* __G_ENUMS_H__ */