[gobject-introspection] [girepository] Move GITypeInfo out of ginfo.ch
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] [girepository] Move GITypeInfo out of ginfo.ch
- Date: Sun, 6 Jun 2010 16:38:06 +0000 (UTC)
commit 161ebdd7a903a868f15adbe1c551a913d2e0e8a2
Author: Johan Dahlin <johan gnome org>
Date: Sun Jun 6 12:58:13 2010 -0300
[girepository] Move GITypeInfo out of ginfo.ch
girepository/Makefile.am | 2 +
girepository/ginfo.c | 378 ----------------------------------------
girepository/girepository.h | 24 +---
girepository/gitypeinfo.c | 403 +++++++++++++++++++++++++++++++++++++++++++
girepository/gitypeinfo.h | 57 ++++++
5 files changed, 463 insertions(+), 401 deletions(-)
---
diff --git a/girepository/Makefile.am b/girepository/Makefile.am
index 07d70d0..260d05d 100644
--- a/girepository/Makefile.am
+++ b/girepository/Makefile.am
@@ -6,6 +6,7 @@ girepo_HEADERS = \
gifunctioninfo.h \
girepository.h \
girffi.h \
+ gitypeinfo.h \
gitypelib.h \
gitypes.h
@@ -27,6 +28,7 @@ libgirepository_1_0_la_SOURCES = \
girffi.h \
girffi-private.h \
glib-compat.h \
+ gitypeinfo.c \
gitypelib.c \
gitypelib-internal.h
diff --git a/girepository/ginfo.c b/girepository/ginfo.c
index 3b55b80..47cbd00 100644
--- a/girepository/ginfo.c
+++ b/girepository/ginfo.c
@@ -29,384 +29,6 @@
#include "girepository-private.h"
-/* GITypeInfo functions */
-
-/**
- * SECTION:gitypeinfo
- * @Short_description: Struct representing a type
- * @Title: GITypeInfo
- *
- * GITypeInfo represents a type. You can retrieve a type info from
- * an argument (see #GIArgInfo), a functions return value (see #GIFunctionInfo),
- * a field (see #GIFieldInfo), a property (see #GIPropertyInfo), a constant
- * (see #GIConstantInfo) or for a union discriminator (see #GIUnionInfo).
- *
- * A type can either be a of a basic type which is a standard C primitive
- * type or an interface type. For interface types you need to call
- * g_type_info_get_interface() to get a reference to the base info for that
- * interface.
- *
- */
-
-/**
- * g_type_info_is_pointer:
- * @info: a #GITypeInfo
- *
- * Obtain if the type is passed as a reference.
- *
- * Returns: %TRUE if it is a pointer
- */
-gboolean
-g_type_info_is_pointer (GITypeInfo *info)
-{
- GIRealInfo *rinfo = (GIRealInfo *)info;
- SimpleTypeBlob *type;
-
- g_return_val_if_fail (info != NULL, FALSE);
- g_return_val_if_fail (GI_IS_TYPE_INFO (info), FALSE);
-
- type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (type->flags.reserved == 0 && type->flags.reserved2 == 0)
- return type->flags.pointer;
- else
- {
- InterfaceTypeBlob *iface = (InterfaceTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- return iface->pointer;
- }
-}
-
-/**
- * g_type_info_get_tag:
- * @info: a #GITypeInfo
- *
- * Obtain the type tag for the type. See #GITypeTag for a list
- * of type tags.
- *
- * Returns: the type tag
- */
-GITypeTag
-g_type_info_get_tag (GITypeInfo *info)
-{
- GIRealInfo *rinfo = (GIRealInfo *)info;
- SimpleTypeBlob *type;
-
- g_return_val_if_fail (info != NULL, GI_TYPE_TAG_BOOLEAN);
- g_return_val_if_fail (GI_IS_TYPE_INFO (info), GI_TYPE_TAG_BOOLEAN);
-
- type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (rinfo->type_is_embedded)
- return GI_TYPE_TAG_INTERFACE;
- else if (type->flags.reserved == 0 && type->flags.reserved2 == 0)
- return type->flags.tag;
- else
- {
- InterfaceTypeBlob *iface = (InterfaceTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- return iface->tag;
- }
-}
-
-/**
- * g_type_info_get_param_type:
- * @info: a #GITypeInfo
- * @n: index of the parameter
- *
- * Obtain the parameter type @n.
- *
- * Returns: the param type info
- */
-GITypeInfo *
-g_type_info_get_param_type (GITypeInfo *info,
- gint n)
-{
- GIRealInfo *rinfo = (GIRealInfo *)info;
- SimpleTypeBlob *type;
-
- g_return_val_if_fail (info != NULL, NULL);
- g_return_val_if_fail (GI_IS_TYPE_INFO (info), NULL);
-
- type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
- {
- ParamTypeBlob *param = (ParamTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- switch (param->tag)
- {
- case GI_TYPE_TAG_ARRAY:
- case GI_TYPE_TAG_GLIST:
- case GI_TYPE_TAG_GSLIST:
- case GI_TYPE_TAG_GHASH:
- return _g_type_info_new ((GIBaseInfo*)info, rinfo->typelib,
- rinfo->offset + sizeof (ParamTypeBlob)
- + sizeof (SimpleTypeBlob) * n);
- break;
- default:
- break;
- }
- }
-
- return NULL;
-}
-
-/**
- * g_type_info_get_interface:
- * @info: a #GITypeInfo
- *
- * For types which have #GI_TYPE_TAG_INTERFACE such as GObjects and boxed values,
- * this function returns full information about the referenced type. You can then
- * inspect the type of the returned #GIBaseInfo to further query whether it is
- * a concrete GObject, a GInterface, a structure, etc. using g_base_info_get_type().
- *
- * Returns: (transfer full): the #GIBaseInfo, or %NULL. Free it with
- * g_base_info_unref() when done.
- */
-GIBaseInfo *
-g_type_info_get_interface (GITypeInfo *info)
-{
- GIRealInfo *rinfo = (GIRealInfo *)info;
-
- g_return_val_if_fail (info != NULL, NULL);
- g_return_val_if_fail (GI_IS_TYPE_INFO (info), NULL);
-
- /* For embedded types, the given offset is a pointer to the actual blob,
- * after the end of the field. In that case we know it's a "subclass" of
- * CommonBlob, so use that to determine the info type.
- */
- if (rinfo->type_is_embedded)
- {
- CommonBlob *common = (CommonBlob *)&rinfo->typelib->data[rinfo->offset];
- GIInfoType info_type;
-
- switch (common->blob_type)
- {
- case BLOB_TYPE_CALLBACK:
- info_type = GI_INFO_TYPE_CALLBACK;
- break;
- default:
- g_assert_not_reached ();
- return NULL;
- }
- return (GIBaseInfo *) g_info_new (info_type, (GIBaseInfo*)info, rinfo->typelib,
- rinfo->offset);
- }
- else
- {
- SimpleTypeBlob *type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
- if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
- {
- InterfaceTypeBlob *blob = (InterfaceTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (blob->tag == GI_TYPE_TAG_INTERFACE)
- return _g_info_from_entry (rinfo->repository, rinfo->typelib, blob->interface);
- }
- }
-
- return NULL;
-}
-
-/**
- * g_type_info_get_array_length:
- * @info: a #GITypeInfo
- *
- * Obtain the array length of the type. The type tag must be a
- * #GI_TYPE_TAG_ARRAY or -1 will returned.
- *
- * Returns: the array length, or -1 if the type is not an array
- */
-gint
-g_type_info_get_array_length (GITypeInfo *info)
-{
- GIRealInfo *rinfo = (GIRealInfo *)info;
- SimpleTypeBlob *type;
-
- g_return_val_if_fail (info != NULL, -1);
- g_return_val_if_fail (GI_IS_TYPE_INFO (info), -1);
-
- type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
- {
- ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (blob->tag == GI_TYPE_TAG_ARRAY)
- {
- if (blob->has_length)
- return blob->dimensions.length;
- }
- }
-
- return -1;
-}
-
-/**
- * g_type_info_get_array_fixed_size:
- * @info: a #GITypeInfo
- *
- * Obtain the fixed array size of the type. The type tag must be a
- * #GI_TYPE_TAG_ARRAY or -1 will returned.
- *
- * Returns: the size or -1 if it's not an array
- */
-gint
-g_type_info_get_array_fixed_size (GITypeInfo *info)
-{
- GIRealInfo *rinfo = (GIRealInfo *)info;
- SimpleTypeBlob *type;
-
- g_return_val_if_fail (info != NULL, 0);
- g_return_val_if_fail (GI_IS_TYPE_INFO (info), 0);
-
- type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
- {
- ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (blob->tag == GI_TYPE_TAG_ARRAY)
- {
- if (blob->has_size)
- return blob->dimensions.size;
- }
- }
-
- return -1;
-}
-
-/**
- * g_type_info_is_zero_terminated:
- * @info: a #GITypeInfo
- *
- * Obtain if the last element of the array is %NULL. The type tag must be a
- * #GI_TYPE_TAG_ARRAY or %FALSE will returned.
- *
- * Returns: %TRUE if zero terminated
- */
-gboolean
-g_type_info_is_zero_terminated (GITypeInfo *info)
-{
- GIRealInfo *rinfo = (GIRealInfo *)info;
- SimpleTypeBlob *type;
-
- g_return_val_if_fail (info != NULL, FALSE);
- g_return_val_if_fail (GI_IS_TYPE_INFO (info), FALSE);
-
- type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
- {
- ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (blob->tag == GI_TYPE_TAG_ARRAY)
- return blob->zero_terminated;
- }
-
- return FALSE;
-}
-
-/**
- * g_type_info_get_array_type:
- * @info: a #GITypeInfo
- *
- * Obtain the array type for this type. See #GIArrayType for a list of
- * possible values. If the type tag of this type is not array, -1 will be
- * returned.
- *
- * Returns: the array type or -1
- */
-GIArrayType
-g_type_info_get_array_type (GITypeInfo *info)
-{
- GIRealInfo *rinfo = (GIRealInfo *)info;
- SimpleTypeBlob *type;
-
- g_return_val_if_fail (info != NULL, -1);
- g_return_val_if_fail (GI_IS_TYPE_INFO (info), -1);
-
- type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
- {
- ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
- g_return_val_if_fail (blob->tag == GI_TYPE_TAG_ARRAY, -1);
-
- return blob->array_type;
- }
-
- return -1;
-}
-
-/**
- * g_type_info_get_n_error_domains:
- * @info: a #GITypeInfo
- *
- * Obtain the number of error domains for this type. The type tag
- * must be a #GI_TYPE_TAG_ERROR or -1 will be returned.
- *
- * Returns: number of error domains or -1
- */
-gint
-g_type_info_get_n_error_domains (GITypeInfo *info)
-{
- GIRealInfo *rinfo = (GIRealInfo *)info;
- SimpleTypeBlob *type;
-
- g_return_val_if_fail (info != NULL, 0);
- g_return_val_if_fail (GI_IS_TYPE_INFO (info), 0);
-
- type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
- {
- ErrorTypeBlob *blob = (ErrorTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (blob->tag == GI_TYPE_TAG_ERROR)
- return blob->n_domains;
- }
-
- return 0;
-}
-
-/**
- * g_type_info_get_error_domain:
- * @info: a #GITypeInfo
- * @n: index of error domain
- *
- * Obtain the error domains at index @n for this type. The type tag
- * must be a #GI_TYPE_TAG_ERROR or -1 will be returned.
- *
- * Returns: (transfer full): the error domain or %NULL if type tag is wrong,
- * free the struct with g_base_info_unref() when done.
- */
-GIErrorDomainInfo *
-g_type_info_get_error_domain (GITypeInfo *info,
- gint n)
-{
- GIRealInfo *rinfo = (GIRealInfo *)info;
- SimpleTypeBlob *type;
-
- g_return_val_if_fail (info != NULL, NULL);
- g_return_val_if_fail (GI_IS_TYPE_INFO (info), NULL);
-
- type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
- {
- ErrorTypeBlob *blob = (ErrorTypeBlob *)&rinfo->typelib->data[rinfo->offset];
-
- if (blob->tag == GI_TYPE_TAG_ERROR)
- return (GIErrorDomainInfo *) _g_info_from_entry (rinfo->repository,
- rinfo->typelib,
- blob->domains[n]);
- }
-
- return NULL;
-}
-
-
/* GIErrorDomainInfo functions */
/**
diff --git a/girepository/girepository.h b/girepository/girepository.h
index e064719..30a2fde 100644
--- a/girepository/girepository.h
+++ b/girepository/girepository.h
@@ -30,6 +30,7 @@
#include <gibaseinfo.h>
#include <gicallableinfo.h>
#include <gifunctioninfo.h>
+#include <gitypeinfo.h>
#include <gitypelib.h>
#include <gitypes.h>
@@ -147,29 +148,6 @@ void gi_cclosure_marshal_generic (GClosure *closure,
gpointer invocation_hint,
gpointer marshal_data);
-/* GITypeInfo */
-
-#define GI_IS_TYPE_INFO(info) \
- (g_base_info_get_type((GIBaseInfo*)info) == GI_INFO_TYPE_TYPE)
-
-#define G_TYPE_TAG_IS_BASIC(tag) (tag < GI_TYPE_TAG_ARRAY)
-
-const gchar* g_type_tag_to_string (GITypeTag type);
-
-gboolean g_type_info_is_pointer (GITypeInfo *info);
-GITypeTag g_type_info_get_tag (GITypeInfo *info);
-GITypeInfo * g_type_info_get_param_type (GITypeInfo *info,
- gint n);
-GIBaseInfo * g_type_info_get_interface (GITypeInfo *info);
-gint g_type_info_get_array_length (GITypeInfo *info);
-gint g_type_info_get_array_fixed_size(GITypeInfo *info);
-gboolean g_type_info_is_zero_terminated (GITypeInfo *info);
-GIArrayType g_type_info_get_array_type (GITypeInfo *info);
-
-gint g_type_info_get_n_error_domains (GITypeInfo *info);
-GIErrorDomainInfo *g_type_info_get_error_domain (GITypeInfo *info,
- gint n);
-
/* GIErrorDomainInfo */
#define GI_IS_ERROR_DOMAIN_INFO(info) \
diff --git a/girepository/gitypeinfo.c b/girepository/gitypeinfo.c
new file mode 100644
index 0000000..68c3dc1
--- /dev/null
+++ b/girepository/gitypeinfo.c
@@ -0,0 +1,403 @@
+/* GObject introspection: Type implementation
+ *
+ * Copyright (C) 2005 Matthias Clasen
+ * Copyright (C) 2008,2009 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.
+ */
+
+#include <glib.h>
+
+#include <girepository.h>
+#include "girepository-private.h"
+#include "gitypelib-internal.h"
+
+/**
+ * SECTION:gitypeinfo
+ * @Short_description: Struct representing a type
+ * @Title: GITypeInfo
+ *
+ * GITypeInfo represents a type. You can retrieve a type info from
+ * an argument (see #GIArgInfo), a functions return value (see #GIFunctionInfo),
+ * a field (see #GIFieldInfo), a property (see #GIPropertyInfo), a constant
+ * (see #GIConstantInfo) or for a union discriminator (see #GIUnionInfo).
+ *
+ * A type can either be a of a basic type which is a standard C primitive
+ * type or an interface type. For interface types you need to call
+ * g_type_info_get_interface() to get a reference to the base info for that
+ * interface.
+ *
+ */
+
+/**
+ * g_type_info_is_pointer:
+ * @info: a #GITypeInfo
+ *
+ * Obtain if the type is passed as a reference.
+ *
+ * Returns: %TRUE if it is a pointer
+ */
+gboolean
+g_type_info_is_pointer (GITypeInfo *info)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ SimpleTypeBlob *type;
+
+ g_return_val_if_fail (info != NULL, FALSE);
+ g_return_val_if_fail (GI_IS_TYPE_INFO (info), FALSE);
+
+ type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (type->flags.reserved == 0 && type->flags.reserved2 == 0)
+ return type->flags.pointer;
+ else
+ {
+ InterfaceTypeBlob *iface = (InterfaceTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ return iface->pointer;
+ }
+}
+
+/**
+ * g_type_info_get_tag:
+ * @info: a #GITypeInfo
+ *
+ * Obtain the type tag for the type. See #GITypeTag for a list
+ * of type tags.
+ *
+ * Returns: the type tag
+ */
+GITypeTag
+g_type_info_get_tag (GITypeInfo *info)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ SimpleTypeBlob *type;
+
+ g_return_val_if_fail (info != NULL, GI_TYPE_TAG_BOOLEAN);
+ g_return_val_if_fail (GI_IS_TYPE_INFO (info), GI_TYPE_TAG_BOOLEAN);
+
+ type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (rinfo->type_is_embedded)
+ return GI_TYPE_TAG_INTERFACE;
+ else if (type->flags.reserved == 0 && type->flags.reserved2 == 0)
+ return type->flags.tag;
+ else
+ {
+ InterfaceTypeBlob *iface = (InterfaceTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ return iface->tag;
+ }
+}
+
+/**
+ * g_type_info_get_param_type:
+ * @info: a #GITypeInfo
+ * @n: index of the parameter
+ *
+ * Obtain the parameter type @n.
+ *
+ * Returns: the param type info
+ */
+GITypeInfo *
+g_type_info_get_param_type (GITypeInfo *info,
+ gint n)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ SimpleTypeBlob *type;
+
+ g_return_val_if_fail (info != NULL, NULL);
+ g_return_val_if_fail (GI_IS_TYPE_INFO (info), NULL);
+
+ type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
+ {
+ ParamTypeBlob *param = (ParamTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ switch (param->tag)
+ {
+ case GI_TYPE_TAG_ARRAY:
+ case GI_TYPE_TAG_GLIST:
+ case GI_TYPE_TAG_GSLIST:
+ case GI_TYPE_TAG_GHASH:
+ return _g_type_info_new ((GIBaseInfo*)info, rinfo->typelib,
+ rinfo->offset + sizeof (ParamTypeBlob)
+ + sizeof (SimpleTypeBlob) * n);
+ break;
+ default:
+ break;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * g_type_info_get_interface:
+ * @info: a #GITypeInfo
+ *
+ * For types which have #GI_TYPE_TAG_INTERFACE such as GObjects and boxed values,
+ * this function returns full information about the referenced type. You can then
+ * inspect the type of the returned #GIBaseInfo to further query whether it is
+ * a concrete GObject, a GInterface, a structure, etc. using g_base_info_get_type().
+ *
+ * Returns: (transfer full): the #GIBaseInfo, or %NULL. Free it with
+ * g_base_info_unref() when done.
+ */
+GIBaseInfo *
+g_type_info_get_interface (GITypeInfo *info)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+
+ g_return_val_if_fail (info != NULL, NULL);
+ g_return_val_if_fail (GI_IS_TYPE_INFO (info), NULL);
+
+ /* For embedded types, the given offset is a pointer to the actual blob,
+ * after the end of the field. In that case we know it's a "subclass" of
+ * CommonBlob, so use that to determine the info type.
+ */
+ if (rinfo->type_is_embedded)
+ {
+ CommonBlob *common = (CommonBlob *)&rinfo->typelib->data[rinfo->offset];
+ GIInfoType info_type;
+
+ switch (common->blob_type)
+ {
+ case BLOB_TYPE_CALLBACK:
+ info_type = GI_INFO_TYPE_CALLBACK;
+ break;
+ default:
+ g_assert_not_reached ();
+ return NULL;
+ }
+ return (GIBaseInfo *) g_info_new (info_type, (GIBaseInfo*)info, rinfo->typelib,
+ rinfo->offset);
+ }
+ else
+ {
+ SimpleTypeBlob *type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+ if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
+ {
+ InterfaceTypeBlob *blob = (InterfaceTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (blob->tag == GI_TYPE_TAG_INTERFACE)
+ return _g_info_from_entry (rinfo->repository, rinfo->typelib, blob->interface);
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * g_type_info_get_array_length:
+ * @info: a #GITypeInfo
+ *
+ * Obtain the array length of the type. The type tag must be a
+ * #GI_TYPE_TAG_ARRAY or -1 will returned.
+ *
+ * Returns: the array length, or -1 if the type is not an array
+ */
+gint
+g_type_info_get_array_length (GITypeInfo *info)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ SimpleTypeBlob *type;
+
+ g_return_val_if_fail (info != NULL, -1);
+ g_return_val_if_fail (GI_IS_TYPE_INFO (info), -1);
+
+ type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
+ {
+ ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (blob->tag == GI_TYPE_TAG_ARRAY)
+ {
+ if (blob->has_length)
+ return blob->dimensions.length;
+ }
+ }
+
+ return -1;
+}
+
+/**
+ * g_type_info_get_array_fixed_size:
+ * @info: a #GITypeInfo
+ *
+ * Obtain the fixed array size of the type. The type tag must be a
+ * #GI_TYPE_TAG_ARRAY or -1 will returned.
+ *
+ * Returns: the size or -1 if it's not an array
+ */
+gint
+g_type_info_get_array_fixed_size (GITypeInfo *info)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ SimpleTypeBlob *type;
+
+ g_return_val_if_fail (info != NULL, 0);
+ g_return_val_if_fail (GI_IS_TYPE_INFO (info), 0);
+
+ type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
+ {
+ ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (blob->tag == GI_TYPE_TAG_ARRAY)
+ {
+ if (blob->has_size)
+ return blob->dimensions.size;
+ }
+ }
+
+ return -1;
+}
+
+/**
+ * g_type_info_is_zero_terminated:
+ * @info: a #GITypeInfo
+ *
+ * Obtain if the last element of the array is %NULL. The type tag must be a
+ * #GI_TYPE_TAG_ARRAY or %FALSE will returned.
+ *
+ * Returns: %TRUE if zero terminated
+ */
+gboolean
+g_type_info_is_zero_terminated (GITypeInfo *info)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ SimpleTypeBlob *type;
+
+ g_return_val_if_fail (info != NULL, FALSE);
+ g_return_val_if_fail (GI_IS_TYPE_INFO (info), FALSE);
+
+ type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
+ {
+ ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (blob->tag == GI_TYPE_TAG_ARRAY)
+ return blob->zero_terminated;
+ }
+
+ return FALSE;
+}
+
+/**
+ * g_type_info_get_array_type:
+ * @info: a #GITypeInfo
+ *
+ * Obtain the array type for this type. See #GIArrayType for a list of
+ * possible values. If the type tag of this type is not array, -1 will be
+ * returned.
+ *
+ * Returns: the array type or -1
+ */
+GIArrayType
+g_type_info_get_array_type (GITypeInfo *info)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ SimpleTypeBlob *type;
+
+ g_return_val_if_fail (info != NULL, -1);
+ g_return_val_if_fail (GI_IS_TYPE_INFO (info), -1);
+
+ type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
+ {
+ ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+ g_return_val_if_fail (blob->tag == GI_TYPE_TAG_ARRAY, -1);
+
+ return blob->array_type;
+ }
+
+ return -1;
+}
+
+/**
+ * g_type_info_get_n_error_domains:
+ * @info: a #GITypeInfo
+ *
+ * Obtain the number of error domains for this type. The type tag
+ * must be a #GI_TYPE_TAG_ERROR or -1 will be returned.
+ *
+ * Returns: number of error domains or -1
+ */
+gint
+g_type_info_get_n_error_domains (GITypeInfo *info)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ SimpleTypeBlob *type;
+
+ g_return_val_if_fail (info != NULL, 0);
+ g_return_val_if_fail (GI_IS_TYPE_INFO (info), 0);
+
+ type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
+ {
+ ErrorTypeBlob *blob = (ErrorTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (blob->tag == GI_TYPE_TAG_ERROR)
+ return blob->n_domains;
+ }
+
+ return 0;
+}
+
+/**
+ * g_type_info_get_error_domain:
+ * @info: a #GITypeInfo
+ * @n: index of error domain
+ *
+ * Obtain the error domains at index @n for this type. The type tag
+ * must be a #GI_TYPE_TAG_ERROR or -1 will be returned.
+ *
+ * Returns: (transfer full): the error domain or %NULL if type tag is wrong,
+ * free the struct with g_base_info_unref() when done.
+ */
+GIErrorDomainInfo *
+g_type_info_get_error_domain (GITypeInfo *info,
+ gint n)
+{
+ GIRealInfo *rinfo = (GIRealInfo *)info;
+ SimpleTypeBlob *type;
+
+ g_return_val_if_fail (info != NULL, NULL);
+ g_return_val_if_fail (GI_IS_TYPE_INFO (info), NULL);
+
+ type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
+ {
+ ErrorTypeBlob *blob = (ErrorTypeBlob *)&rinfo->typelib->data[rinfo->offset];
+
+ if (blob->tag == GI_TYPE_TAG_ERROR)
+ return (GIErrorDomainInfo *) _g_info_from_entry (rinfo->repository,
+ rinfo->typelib,
+ blob->domains[n]);
+ }
+
+ return NULL;
+}
+
+
diff --git a/girepository/gitypeinfo.h b/girepository/gitypeinfo.h
new file mode 100644
index 0000000..4d33d31
--- /dev/null
+++ b/girepository/gitypeinfo.h
@@ -0,0 +1,57 @@
+/* GObject introspection: Type
+ *
+ * Copyright (C) 2005 Matthias Clasen
+ * Copyright (C) 2008,2009 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 __GITYPEINFO_H__
+#define __GITYPEINFO_H__
+
+#if !defined (__GIREPOSITORY_H_INSIDE__) && !defined (GI_COMPILATION)
+#error "Only <girepository.h> can be included directly."
+#endif
+
+#include <gitypes.h>
+
+G_BEGIN_DECLS
+
+#define GI_IS_TYPE_INFO(info) \
+ (g_base_info_get_type((GIBaseInfo*)info) == GI_INFO_TYPE_TYPE)
+
+#define G_TYPE_TAG_IS_BASIC(tag) (tag < GI_TYPE_TAG_ARRAY)
+
+const gchar* g_type_tag_to_string (GITypeTag type);
+
+gboolean g_type_info_is_pointer (GITypeInfo *info);
+GITypeTag g_type_info_get_tag (GITypeInfo *info);
+GITypeInfo * g_type_info_get_param_type (GITypeInfo *info,
+ gint n);
+GIBaseInfo * g_type_info_get_interface (GITypeInfo *info);
+gint g_type_info_get_array_length (GITypeInfo *info);
+gint g_type_info_get_array_fixed_size(GITypeInfo *info);
+gboolean g_type_info_is_zero_terminated (GITypeInfo *info);
+GIArrayType g_type_info_get_array_type (GITypeInfo *info);
+
+gint g_type_info_get_n_error_domains (GITypeInfo *info);
+GIErrorDomainInfo *g_type_info_get_error_domain (GITypeInfo *info,
+ gint n);
+G_END_DECLS
+
+
+#endif /* __GITYPEINFO_H__ */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]