Blame gobject/genums.h

Packit ae235b
/* GObject - GLib Type, Object, Parameter and Signal Library
Packit ae235b
 * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
#ifndef __G_ENUMS_H__
Packit ae235b
#define __G_ENUMS_H__
Packit ae235b
Packit ae235b
#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
Packit ae235b
#error "Only <glib-object.h> can be included directly."
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#include <gobject/gtype.h>
Packit ae235b
Packit ae235b
G_BEGIN_DECLS
Packit ae235b
Packit ae235b
/* --- type macros --- */
Packit ae235b
/**
Packit ae235b
 * G_TYPE_IS_ENUM:
Packit ae235b
 * @type: a #GType ID.
Packit ae235b
 * 
Packit ae235b
 * Checks whether @type "is a" %G_TYPE_ENUM.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if @type "is a" %G_TYPE_ENUM.
Packit ae235b
 */
Packit ae235b
#define G_TYPE_IS_ENUM(type)	       (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM)
Packit ae235b
/**
Packit ae235b
 * G_ENUM_CLASS:
Packit ae235b
 * @class: a valid #GEnumClass
Packit ae235b
 * 
Packit ae235b
 * Casts a derived #GEnumClass structure into a #GEnumClass structure.
Packit ae235b
 */
Packit ae235b
#define G_ENUM_CLASS(class)	       (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_ENUM, GEnumClass))
Packit ae235b
/**
Packit ae235b
 * G_IS_ENUM_CLASS:
Packit ae235b
 * @class: a #GEnumClass
Packit ae235b
 * 
Packit ae235b
 * Checks whether @class "is a" valid #GEnumClass structure of type %G_TYPE_ENUM
Packit ae235b
 * or derived.
Packit ae235b
 */
Packit ae235b
#define G_IS_ENUM_CLASS(class)	       (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_ENUM))
Packit ae235b
/**
Packit ae235b
 * G_ENUM_CLASS_TYPE:
Packit ae235b
 * @class: a #GEnumClass
Packit ae235b
 * 
Packit ae235b
 * Get the type identifier from a given #GEnumClass structure.
Packit ae235b
 *
Packit ae235b
 * Returns: the #GType
Packit ae235b
 */
Packit ae235b
#define G_ENUM_CLASS_TYPE(class)       (G_TYPE_FROM_CLASS (class))
Packit ae235b
/**
Packit ae235b
 * G_ENUM_CLASS_TYPE_NAME:
Packit ae235b
 * @class: a #GEnumClass
Packit ae235b
 * 
Packit ae235b
 * Get the static type name from a given #GEnumClass structure.
Packit ae235b
 *
Packit ae235b
 * Returns: the type name.
Packit ae235b
 */
Packit ae235b
#define G_ENUM_CLASS_TYPE_NAME(class)  (g_type_name (G_ENUM_CLASS_TYPE (class)))
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * G_TYPE_IS_FLAGS:
Packit ae235b
 * @type: a #GType ID.
Packit ae235b
 *
Packit ae235b
 * Checks whether @type "is a" %G_TYPE_FLAGS. 
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if @type "is a" %G_TYPE_FLAGS.
Packit ae235b
 */
Packit ae235b
#define G_TYPE_IS_FLAGS(type)	       (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS)
Packit ae235b
/**
Packit ae235b
 * G_FLAGS_CLASS:
Packit ae235b
 * @class: a valid #GFlagsClass
Packit ae235b
 * 
Packit ae235b
 * Casts a derived #GFlagsClass structure into a #GFlagsClass structure.
Packit ae235b
 */
Packit ae235b
#define G_FLAGS_CLASS(class)	       (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_FLAGS, GFlagsClass))
Packit ae235b
/**
Packit ae235b
 * G_IS_FLAGS_CLASS:
Packit ae235b
 * @class: a #GFlagsClass
Packit ae235b
 * 
Packit ae235b
 * Checks whether @class "is a" valid #GFlagsClass structure of type %G_TYPE_FLAGS
Packit ae235b
 * or derived.
Packit ae235b
 */
Packit ae235b
#define G_IS_FLAGS_CLASS(class)        (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_FLAGS))
Packit ae235b
/**
Packit ae235b
 * G_FLAGS_CLASS_TYPE:
Packit ae235b
 * @class: a #GFlagsClass
Packit ae235b
 * 
Packit ae235b
 * Get the type identifier from a given #GFlagsClass structure.
Packit ae235b
 *
Packit ae235b
 * Returns: the #GType
Packit ae235b
 */
Packit ae235b
#define G_FLAGS_CLASS_TYPE(class)      (G_TYPE_FROM_CLASS (class))
Packit ae235b
/**
Packit ae235b
 * G_FLAGS_CLASS_TYPE_NAME:
Packit ae235b
 * @class: a #GFlagsClass
Packit ae235b
 * 
Packit ae235b
 * Get the static type name from a given #GFlagsClass structure.
Packit ae235b
 *
Packit ae235b
 * Returns: the type name.
Packit ae235b
 */
Packit ae235b
#define G_FLAGS_CLASS_TYPE_NAME(class) (g_type_name (G_FLAGS_CLASS_TYPE (class)))
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * G_VALUE_HOLDS_ENUM:
Packit ae235b
 * @value: a valid #GValue structure
Packit ae235b
 * 
Packit ae235b
 * Checks whether the given #GValue can hold values derived from type %G_TYPE_ENUM.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE on success.
Packit ae235b
 */
Packit ae235b
#define G_VALUE_HOLDS_ENUM(value)      (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_ENUM))
Packit ae235b
/**
Packit ae235b
 * G_VALUE_HOLDS_FLAGS:
Packit ae235b
 * @value: a valid #GValue structure
Packit ae235b
 * 
Packit ae235b
 * Checks whether the given #GValue can hold values derived from type %G_TYPE_FLAGS.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE on success.
Packit ae235b
 */
Packit ae235b
#define G_VALUE_HOLDS_FLAGS(value)     (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLAGS))
Packit ae235b
Packit ae235b
Packit ae235b
/* --- enum/flag values & classes --- */
Packit ae235b
typedef struct _GEnumClass  GEnumClass;
Packit ae235b
typedef struct _GFlagsClass GFlagsClass;
Packit ae235b
typedef struct _GEnumValue  GEnumValue;
Packit ae235b
typedef struct _GFlagsValue GFlagsValue;
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GEnumClass:
Packit ae235b
 * @g_type_class: the parent class
Packit ae235b
 * @minimum: the smallest possible value.
Packit ae235b
 * @maximum: the largest possible value.
Packit ae235b
 * @n_values: the number of possible values.
Packit ae235b
 * @values: an array of #GEnumValue structs describing the 
Packit ae235b
 *  individual values.
Packit ae235b
 * 
Packit ae235b
 * The class of an enumeration type holds information about its 
Packit ae235b
 * possible values.
Packit ae235b
 */
Packit ae235b
struct	_GEnumClass
Packit ae235b
{
Packit ae235b
  GTypeClass  g_type_class;
Packit ae235b
Packit ae235b
  /*< public >*/  
Packit ae235b
  gint	      minimum;
Packit ae235b
  gint	      maximum;
Packit ae235b
  guint	      n_values;
Packit ae235b
  GEnumValue *values;
Packit ae235b
};
Packit ae235b
/**
Packit ae235b
 * GFlagsClass:
Packit ae235b
 * @g_type_class: the parent class
Packit ae235b
 * @mask: a mask covering all possible values.
Packit ae235b
 * @n_values: the number of possible values.
Packit ae235b
 * @values: an array of #GFlagsValue structs describing the 
Packit ae235b
 *  individual values.
Packit ae235b
 * 
Packit ae235b
 * The class of a flags type holds information about its 
Packit ae235b
 * possible values.
Packit ae235b
 */
Packit ae235b
struct	_GFlagsClass
Packit ae235b
{
Packit ae235b
  GTypeClass   g_type_class;
Packit ae235b
  
Packit ae235b
  /*< public >*/  
Packit ae235b
  guint	       mask;
Packit ae235b
  guint	       n_values;
Packit ae235b
  GFlagsValue *values;
Packit ae235b
};
Packit ae235b
/**
Packit ae235b
 * GEnumValue:
Packit ae235b
 * @value: the enum value
Packit ae235b
 * @value_name: the name of the value
Packit ae235b
 * @value_nick: the nickname of the value
Packit ae235b
 * 
Packit ae235b
 * A structure which contains a single enum value, its name, and its
Packit ae235b
 * nickname.
Packit ae235b
 */
Packit ae235b
struct _GEnumValue
Packit ae235b
{
Packit ae235b
  gint	 value;
Packit ae235b
  const gchar *value_name;
Packit ae235b
  const gchar *value_nick;
Packit ae235b
};
Packit ae235b
/**
Packit ae235b
 * GFlagsValue:
Packit ae235b
 * @value: the flags value
Packit ae235b
 * @value_name: the name of the value
Packit ae235b
 * @value_nick: the nickname of the value
Packit ae235b
 * 
Packit ae235b
 * A structure which contains a single flags value, its name, and its
Packit ae235b
 * nickname.
Packit ae235b
 */
Packit ae235b
struct _GFlagsValue
Packit ae235b
{
Packit ae235b
  guint	 value;
Packit ae235b
  const gchar *value_name;
Packit ae235b
  const gchar *value_nick;
Packit ae235b
};
Packit ae235b
Packit ae235b
Packit ae235b
/* --- prototypes --- */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GEnumValue*	g_enum_get_value		(GEnumClass	*enum_class,
Packit ae235b
						 gint		 value);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GEnumValue*	g_enum_get_value_by_name	(GEnumClass	*enum_class,
Packit ae235b
						 const gchar	*name);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GEnumValue*	g_enum_get_value_by_nick	(GEnumClass	*enum_class,
Packit ae235b
						 const gchar	*nick);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GFlagsValue*	g_flags_get_first_value		(GFlagsClass	*flags_class,
Packit ae235b
						 guint		 value);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GFlagsValue*	g_flags_get_value_by_name	(GFlagsClass	*flags_class,
Packit ae235b
						 const gchar	*name);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GFlagsValue*	g_flags_get_value_by_nick	(GFlagsClass	*flags_class,
Packit ae235b
						 const gchar	*nick);
Packit ae235b
GLIB_AVAILABLE_IN_2_54
Packit ae235b
gchar          *g_enum_to_string                (GType           g_enum_type,
Packit ae235b
                                                 gint            value);
Packit ae235b
GLIB_AVAILABLE_IN_2_54
Packit ae235b
gchar          *g_flags_to_string               (GType           flags_type,
Packit ae235b
                                                 guint           value);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void            g_value_set_enum        	(GValue         *value,
Packit ae235b
						 gint            v_enum);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gint            g_value_get_enum        	(const GValue   *value);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void            g_value_set_flags       	(GValue         *value,
Packit ae235b
						 guint           v_flags);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
guint           g_value_get_flags       	(const GValue   *value);
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
/* --- registration functions --- */
Packit ae235b
/* const_static_values is a NULL terminated array of enum/flags
Packit ae235b
 * values that is taken over!
Packit ae235b
 */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GType	g_enum_register_static	   (const gchar	      *name,
Packit ae235b
				    const GEnumValue  *const_static_values);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GType	g_flags_register_static	   (const gchar	      *name,
Packit ae235b
				    const GFlagsValue *const_static_values);
Packit ae235b
/* functions to complete the type information
Packit ae235b
 * for enums/flags implemented by plugins
Packit ae235b
 */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void	g_enum_complete_type_info  (GType	       g_enum_type,
Packit ae235b
				    GTypeInfo	      *info,
Packit ae235b
				    const GEnumValue  *const_values);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void	g_flags_complete_type_info (GType	       g_flags_type,
Packit ae235b
				    GTypeInfo	      *info,
Packit ae235b
				    const GFlagsValue *const_values);
Packit ae235b
Packit ae235b
G_END_DECLS
Packit ae235b
Packit ae235b
#endif /* __G_ENUMS_H__ */