You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

262 lines
7.3 KiB

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