2009年4月17日星期五

[GLib学习]gtype.h文件(未完成)

gtype.h文件

在GLib里,所有的基本类型都被封装成g*的形式,如char封装成gchar,如下是一部分这样的代码:
typedef char gchar;
typedef short gshort;
typedef long glong;
typedef int gint;
typedef gint gboolean;

typedef unsigned char guchar;
typedef unsigned short gushort;
typedef unsigned long gulong;
typedef unsigned int guint;

typedef float gfloat;
typedef double gdouble;
值得注意的是它还把void *和const void *封装成gpointer和gconstpointer,大大方便了编程。
typedef void* gpointer;
typedef const void *gconstpointer;

封装这些类型后,还提供了这些类型的比较的函数指针:
typedef gint (*GCompareFunc) (gconstpointer a,
gconstpointer b);
typedef gint (*GCompareDataFunc) (gconstpointer a,
gconstpointer b,
gpointer user_data);
typedef gboolean (*GEqualFunc) (gconstpointer a,
gconstpointer b);
以下的函数指针未理解功能
typedef void (*GDestroyNotify) (gpointer data);
typedef void (*GFunc) (gpointer data,
gpointer user_data);
typedef guint (*GHashFunc) (gconstpointer key);
typedef void (*GHFunc) (gpointer key,
gpointer value,
gpointer user_data);

GFreeFunc函数指针看上去是用于释放内存的,Glib提供类似的函数g_malloc和g_free来分配和释放数据结构的内存。
typedef void (*GFreeFunc) (gpointer data);
GTranslateFunc函数指针用于将指针转换为字符串(暂时不确定,纯属猜测)
typedef const gchar * (*GTranslateFunc) (const gchar *str,
gpointer data);

没有评论: