mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 23:46:17 +01:00
09f8e937f2
Fri Jun 23 17:20:26 2000 Tim Janik <timj@gtk.org> * glib.h: define gstring in terms of gchar*. this typedef reflects the type name of the primitive G_TYPE_STRING in the gobject module. Sat Jun 24 23:03:04 2000 Tim Janik <timj@gtk.org> * gtype.[hc]: provide G_TYPE_CHAR, G_TYPE_UCHAR, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_UINT, G_TYPE_LONG, G_TYPE_ULONG, G_TYPE_FLOAT, G_TYPE_DOUBLE and G_TYPE_STRING fundamental types. added a GTypeValueTable* pointer to GTypeInfo structure for types to implement GValue handling functions. GTypeValueTable contains the following members: value_init(): initialize a GValue structure. value_free(): free GValue structure contents (optional). value_copy(): copy one GValue contents to another GValue structure of collect_type: varargs collection type for the first variable argument to be collected by collect_value(). collect_value(): variable arguments collection function (optional). lcopy_type: varargs collection type for the first variable argument to be location copyied by lcopy_value(). lcopy_value(): variable arguments location copy function (optional). g_type_value_table_peek(): new function to retrive the GTypeValueTable* for a type node. ValueTables get inherited from parent types, unless overridden through the GTypeInfo structure. internally, GTypeValueTable support means an added overhead of one pointer per static or used dynamic type node. g_type_add_class_cache_func(): provide a cache_func/data pair to be called prior to a type nodes last_unref() function, this can be used to prevent premature class destruction. multiple installed cache_func() will be chained upon last_unref() untill one of them returns TRUE. the cache_func()s have to check the type id passed in to figure whether they actually wants to cache the class of this type (since any types are routed through the cache_func() chain). g_type_remove_class_cache_func(): remove a previously installed cache_func/data pair. the cache maintained by this function has to be clear when calling g_type_remove_class_cache_func() to avoid leaks. g_type_class_unref_uncached(): class unref function for cache_func() implementations, unreferences a class omitting the cache chain (and therefore unref->cache->unref->... loops). * gvaluetypes.[hc]: provide the value setters/getters for the primitive fundamental types boolean, char, uchar, int, uint, long, ulong, float, double and string. * gvalue.[hc]: provide G_TYPE_IS_VALUE() in terms of whether a GTypeValueTable is provided for this type. removed g_value_init_default(), g_value_validate(), g_value_defaults(), g_value_set_default() and g_values_cmp() as these are supplied by the GParamSpec API now. moved g_values_exchange() into the "implementation details" section, since it just provides the underlying functionality for g_value_convert(). * gvaluecollector.h: renamed the varargs value container from GParamCValue to GTypeCValue as the value collection methods are supplied by the type system now. G_PARAM_COLLECT_VALUE() and G_PARAM_LCOPY_VALUE() got renamed to G_VALUE_COLLECT() and G_VALUE_LCOPY() and operate without a GParamSpec structure now. * genums.h: macros cleanups/fixes. * genum.c: provide G_TYPE_ENUM and G_TYPE_FLAGS type and assorted g_value_{s|g}et_{enum|flags}() implementations. * gobject.[hc]: provide G_IS_VALUE_OBJECT(), G_TYPE_OBJECT ValueTable methods and g_value_{s|g}et_object(). * gparam.[hc]: reduced class to value_set_default(), value_validate() and values_cmp(). also parameters now need to fill in a GType value_type; field to indicate the GValue type they are handling. provide g_param_value_set_default(), g_param_value_defaults(), g_param_value_validate() and g_param_values_cmp(). * gparamspecs.[hc]: got rid of the g_value_* functions and the G_IS_VALUE_* macros. adapted param spec implementations according to the GParamSpecClass changes.
353 lines
14 KiB
C
353 lines
14 KiB
C
/* GObject - GLib Type, Object, Parameter and Signal Library
|
|
* Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General
|
|
* Public License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
#ifndef __G_TYPE_H__
|
|
#define __G_TYPE_H__
|
|
|
|
extern const char *g_log_domain_gobject;
|
|
#include <glib.h>
|
|
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
/* Basic Type Macros
|
|
*/
|
|
#define G_TYPE_FUNDAMENTAL(type) ((type) & 0xff)
|
|
#define G_TYPE_FUNDAMENTAL_MAX (0xff)
|
|
#define G_TYPE_DERIVE_ID(ptype, branch_seqno) (G_TYPE_FUNDAMENTAL (ptype) | ((branch_seqno) << 8))
|
|
#define G_TYPE_BRANCH_SEQNO(type) ((type) >> 8)
|
|
#define G_TYPE_FUNDAMENTAL_LAST ((GType) _g_type_fundamental_last)
|
|
|
|
|
|
/* predefined fundamental and derived types
|
|
*/
|
|
typedef enum /*< skip >*/
|
|
{
|
|
/* standard types, introduced by g_type_init() */
|
|
G_TYPE_INVALID,
|
|
G_TYPE_NONE,
|
|
G_TYPE_INTERFACE,
|
|
|
|
/* GLib type ids */
|
|
G_TYPE_CHAR,
|
|
G_TYPE_UCHAR,
|
|
G_TYPE_BOOLEAN,
|
|
G_TYPE_INT,
|
|
G_TYPE_UINT,
|
|
G_TYPE_LONG,
|
|
G_TYPE_ULONG,
|
|
G_TYPE_ENUM,
|
|
G_TYPE_FLAGS,
|
|
G_TYPE_FLOAT,
|
|
G_TYPE_DOUBLE,
|
|
G_TYPE_STRING,
|
|
G_TYPE_PARAM,
|
|
G_TYPE_OBJECT,
|
|
|
|
/* the following reserved ids should vanish soon */
|
|
G_TYPE_GTK_BOXED,
|
|
G_TYPE_GTK_POINTER,
|
|
G_TYPE_GTK_SIGNAL,
|
|
|
|
/* reserved fundamental type ids,
|
|
* mail gtk-devel-list@redhat.com for reservations
|
|
*/
|
|
G_TYPE_BSE_PROCEDURE,
|
|
G_TYPE_BSE_TIME,
|
|
G_TYPE_BSE_NOTE,
|
|
G_TYPE_BSE_DOTS,
|
|
G_TYPE_GLE_GOBJECT,
|
|
|
|
G_TYPE_LAST_RESERVED_FUNDAMENTAL,
|
|
|
|
/* derived type ids */
|
|
/* FIXME: G_TYPE_PARAM_INTERFACE */
|
|
G_TYPE_PARAM_CHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 1),
|
|
G_TYPE_PARAM_UCHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 2),
|
|
G_TYPE_PARAM_BOOLEAN = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 3),
|
|
G_TYPE_PARAM_INT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 4),
|
|
G_TYPE_PARAM_UINT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 5),
|
|
G_TYPE_PARAM_LONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 6),
|
|
G_TYPE_PARAM_ULONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 7),
|
|
G_TYPE_PARAM_ENUM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 8),
|
|
G_TYPE_PARAM_FLAGS = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 9),
|
|
G_TYPE_PARAM_FLOAT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 10),
|
|
G_TYPE_PARAM_DOUBLE = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 11),
|
|
G_TYPE_PARAM_STRING = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 12),
|
|
/* FIXME: G_TYPE_PARAM_PARAM */
|
|
G_TYPE_PARAM_OBJECT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 13)
|
|
} GTypeFundamentals;
|
|
|
|
|
|
/* Type Checking Macros
|
|
*/
|
|
#define G_TYPE_IS_INTERFACE(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE)
|
|
#define G_TYPE_IS_CLASSED(type) (g_type_check_flags ((type), G_TYPE_FLAG_CLASSED))
|
|
#define G_TYPE_IS_INSTANTIATABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))
|
|
#define G_TYPE_IS_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DERIVABLE))
|
|
#define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE))
|
|
#define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
|
|
|
|
|
|
/* Typedefs
|
|
*/
|
|
typedef guint32 GType;
|
|
typedef struct _GValue GValue;
|
|
typedef union _GTypeCValue GTypeCValue;
|
|
typedef struct _GTypePlugin GTypePlugin;
|
|
typedef struct _GTypePluginVTable GTypePluginVTable;
|
|
typedef struct _GTypeClass GTypeClass;
|
|
typedef struct _GTypeInterface GTypeInterface;
|
|
typedef struct _GTypeInstance GTypeInstance;
|
|
typedef struct _GTypeInfo GTypeInfo;
|
|
typedef struct _GTypeFundamentalInfo GTypeFundamentalInfo;
|
|
typedef struct _GInterfaceInfo GInterfaceInfo;
|
|
typedef struct _GTypeValueTable GTypeValueTable;
|
|
|
|
|
|
/* Basic Type Structures
|
|
*/
|
|
struct _GTypeClass
|
|
{
|
|
/*< private >*/
|
|
GType g_type;
|
|
};
|
|
struct _GTypeInstance
|
|
{
|
|
/*< private >*/
|
|
GTypeClass *g_class;
|
|
};
|
|
struct _GTypeInterface
|
|
{
|
|
/*< private >*/
|
|
GType g_type; /* iface type */
|
|
GType g_instance_type;
|
|
};
|
|
|
|
|
|
/* Casts, Checks And Convenience Macros For Structured Types
|
|
*/
|
|
#define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type))
|
|
#define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type))
|
|
#define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type)))
|
|
#define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type)))
|
|
#define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), c_type))
|
|
#define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class))
|
|
#define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type)
|
|
#define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type)
|
|
|
|
|
|
/* --- prototypes --- */
|
|
void g_type_init (void);
|
|
gchar* g_type_name (GType type);
|
|
GQuark g_type_qname (GType type);
|
|
GType g_type_from_name (const gchar *name);
|
|
GType g_type_parent (GType type);
|
|
GType g_type_next_base (GType type,
|
|
GType base_type);
|
|
gboolean g_type_is_a (GType type,
|
|
GType is_a_type);
|
|
gboolean g_type_conforms_to (GType type,
|
|
GType iface_type);
|
|
guint g_type_fundamental_branch_last (GType type);
|
|
gpointer g_type_class_ref (GType type);
|
|
gpointer g_type_class_peek (GType type);
|
|
void g_type_class_unref (gpointer g_class);
|
|
gpointer g_type_class_peek_parent (gpointer g_class);
|
|
gpointer g_type_interface_peek (gpointer instance_class,
|
|
GType iface_type);
|
|
/* g_free() the returned arrays */
|
|
GType* g_type_children (GType type,
|
|
guint *n_children);
|
|
GType* g_type_interfaces (GType type,
|
|
guint *n_interfaces);
|
|
/* per-type _static_ data */
|
|
void g_type_set_qdata (GType type,
|
|
GQuark quark,
|
|
gpointer data);
|
|
gpointer g_type_get_qdata (GType type,
|
|
GQuark quark);
|
|
|
|
|
|
/* --- type registration --- */
|
|
typedef void (*GBaseInitFunc) (gpointer g_class);
|
|
typedef void (*GBaseFinalizeFunc) (gpointer g_class);
|
|
typedef void (*GClassInitFunc) (gpointer g_class,
|
|
gpointer class_data);
|
|
typedef void (*GClassFinalizeFunc) (gpointer g_class,
|
|
gpointer class_data);
|
|
typedef void (*GInstanceInitFunc) (GTypeInstance *instance,
|
|
gpointer g_class);
|
|
typedef void (*GInterfaceInitFunc) (gpointer g_iface,
|
|
gpointer iface_data);
|
|
typedef void (*GInterfaceFinalizeFunc) (gpointer g_iface,
|
|
gpointer iface_data);
|
|
typedef void (*GTypePluginRef) (GTypePlugin *plugin);
|
|
typedef void (*GTypePluginUnRef) (GTypePlugin *plugin);
|
|
typedef void (*GTypePluginFillTypeInfo) (GTypePlugin *plugin,
|
|
GType g_type,
|
|
GTypeInfo *info,
|
|
GTypeValueTable *value_table);
|
|
typedef void (*GTypePluginFillInterfaceInfo) (GTypePlugin *plugin,
|
|
GType interface_type,
|
|
GType instance_type,
|
|
GInterfaceInfo *info);
|
|
typedef gboolean (*GTypeClassCacheFunc) (gpointer cache_data,
|
|
GTypeClass *g_class);
|
|
struct _GTypePlugin
|
|
{
|
|
GTypePluginVTable *vtable;
|
|
};
|
|
struct _GTypePluginVTable
|
|
{
|
|
GTypePluginRef plugin_ref;
|
|
GTypePluginUnRef plugin_unref;
|
|
GTypePluginFillTypeInfo complete_type_info;
|
|
GTypePluginFillInterfaceInfo complete_interface_info;
|
|
};
|
|
typedef enum /*< skip >*/
|
|
{
|
|
G_TYPE_FLAG_CLASSED = (1 << 0),
|
|
G_TYPE_FLAG_INSTANTIATABLE = (1 << 1),
|
|
G_TYPE_FLAG_DERIVABLE = (1 << 2),
|
|
G_TYPE_FLAG_DEEP_DERIVABLE = (1 << 3)
|
|
} GTypeFlags;
|
|
struct _GTypeInfo
|
|
{
|
|
/* interface types, classed types, instantiated types */
|
|
guint16 class_size;
|
|
|
|
GBaseInitFunc base_init;
|
|
GBaseFinalizeFunc base_finalize;
|
|
|
|
/* classed types, instantiated types */
|
|
GClassInitFunc class_init;
|
|
GClassFinalizeFunc class_finalize;
|
|
gconstpointer class_data;
|
|
|
|
/* instantiated types */
|
|
guint16 instance_size;
|
|
guint16 n_preallocs;
|
|
GInstanceInitFunc instance_init;
|
|
|
|
/* value handling */
|
|
const GTypeValueTable *value_table;
|
|
};
|
|
struct _GTypeFundamentalInfo
|
|
{
|
|
GTypeFlags type_flags;
|
|
};
|
|
struct _GInterfaceInfo
|
|
{
|
|
GInterfaceInitFunc interface_init;
|
|
GInterfaceFinalizeFunc interface_finalize;
|
|
gpointer interface_data;
|
|
};
|
|
struct _GTypeValueTable
|
|
{
|
|
void (*value_init) (GValue *value);
|
|
void (*value_free) (GValue *value);
|
|
void (*value_copy) (const GValue *src_value,
|
|
GValue *dest_value);
|
|
/* varargs functionality (optional) */
|
|
guint collect_type;
|
|
gchar* (*collect_value) (GValue *value,
|
|
guint nth_value,
|
|
GType *collect_type,
|
|
GTypeCValue *collect_value);
|
|
guint lcopy_type;
|
|
gchar* (*lcopy_value) (const GValue *value,
|
|
guint nth_value,
|
|
GType *collect_type,
|
|
GTypeCValue *collect_value);
|
|
};
|
|
GType g_type_register_static (GType parent_type,
|
|
const gchar *type_name,
|
|
const GTypeInfo *info);
|
|
GType g_type_register_dynamic (GType parent_type,
|
|
const gchar *type_name,
|
|
GTypePlugin *plugin);
|
|
GType g_type_register_fundamental (GType type_id,
|
|
const gchar *type_name,
|
|
const GTypeInfo *info,
|
|
const GTypeFundamentalInfo *finfo);
|
|
void g_type_add_interface_static (GType instance_type,
|
|
GType interface_type,
|
|
GInterfaceInfo *info);
|
|
void g_type_add_interface_dynamic (GType instance_type,
|
|
GType interface_type,
|
|
GTypePlugin *plugin);
|
|
|
|
|
|
/* --- implementation details --- */
|
|
gboolean g_type_class_is_a (GTypeClass *g_class,
|
|
GType is_a_type);
|
|
GTypeClass* g_type_check_class_cast (GTypeClass *g_class,
|
|
GType is_a_type);
|
|
GTypeInstance* g_type_check_instance_cast (GTypeInstance *instance,
|
|
GType iface_type);
|
|
gboolean g_type_instance_conforms_to (GTypeInstance *instance,
|
|
GType iface_type);
|
|
gboolean g_type_check_flags (GType type,
|
|
GTypeFlags flags);
|
|
gboolean g_type_is_dynamic (GType type,
|
|
GTypeFlags flags);
|
|
GTypeInstance* g_type_create_instance (GType type);
|
|
void g_type_free_instance (GTypeInstance *instance);
|
|
GTypeValueTable* g_type_value_table_peek (GType type);
|
|
void g_type_add_class_cache_func (gpointer cache_data,
|
|
GTypeClassCacheFunc cache_func);
|
|
void g_type_remove_class_cache_func (gpointer cache_data,
|
|
GTypeClassCacheFunc cache_func);
|
|
void g_type_class_unref_uncached (gpointer g_class);
|
|
|
|
|
|
#ifndef G_DISABLE_CAST_CHECKS
|
|
# define _G_TYPE_CIC(ip, gt, ct) \
|
|
((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
|
|
# define _G_TYPE_CCC(cp, gt, ct) \
|
|
((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
|
|
#else /* G_DISABLE_CAST_CHECKS */
|
|
# define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip)
|
|
# define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp)
|
|
#endif /* G_DISABLE_CAST_CHECKS */
|
|
#define _G_TYPE_IGC(ip, ct) ((ct*) (((GTypeInstance*) ip)->g_class))
|
|
#define _G_TYPE_CIT(ip, gt) (g_type_instance_conforms_to ((GTypeInstance*) ip, gt))
|
|
#define _G_TYPE_CCT(cp, gt) (g_type_class_is_a ((GTypeClass*) cp, gt))
|
|
|
|
#ifdef G_OS_WIN32
|
|
# ifdef GMODULE_COMPILATION
|
|
# define GTYPE_C_VAR __declspec(dllexport)
|
|
# else /* !GLIB_COMPILATION */
|
|
# define GTYPE_C_VAR extern __declspec(dllimport)
|
|
# endif /* !GLIB_COMPILATION */
|
|
#else /* !G_OS_WIN32 */
|
|
# define GTYPE_C_VAR extern
|
|
#endif /* !G_OS_WIN32 */
|
|
|
|
GTYPE_C_VAR GType _g_type_fundamental_last;
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif /* __cplusplus */
|
|
|
|
#endif /* __G_TYPE_H__ */
|