mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-21 19:54:51 +02:00
[girepository] Move GIEnumInfo out of ginfo.ch
This commit is contained in:
parent
dab5e1ddaf
commit
bbc69cefaa
@ -3,6 +3,7 @@ girepo_HEADERS = \
|
|||||||
giarginfo.h \
|
giarginfo.h \
|
||||||
gibaseinfo.h \
|
gibaseinfo.h \
|
||||||
gicallableinfo.h \
|
gicallableinfo.h \
|
||||||
|
gienuminfo.h \
|
||||||
gierrordomaininfo.h \
|
gierrordomaininfo.h \
|
||||||
gifunctioninfo.h \
|
gifunctioninfo.h \
|
||||||
girepository.h \
|
girepository.h \
|
||||||
@ -20,6 +21,7 @@ libgirepository_1_0_la_SOURCES = \
|
|||||||
giarginfo.c \
|
giarginfo.c \
|
||||||
gibaseinfo.c \
|
gibaseinfo.c \
|
||||||
gicallableinfo.c \
|
gicallableinfo.c \
|
||||||
|
gienuminfo.c \
|
||||||
gierrordomaininfo.c \
|
gierrordomaininfo.c \
|
||||||
gifunctioninfo.c \
|
gifunctioninfo.c \
|
||||||
ginfo.c \
|
ginfo.c \
|
||||||
|
136
gienuminfo.c
Normal file
136
gienuminfo.c
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
/* GObject introspection: Enum 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:gienuminfo
|
||||||
|
* @Short_description: Structs representing an enumeration and its values
|
||||||
|
* @Title: GIEnumInfo
|
||||||
|
*
|
||||||
|
* A GIEnumInfo represents an enumeration and a GIValueInfo struct represents a value
|
||||||
|
* of an enumeration. The GIEnumInfo contains a set of values and a type
|
||||||
|
* The GIValueInfo is fetched by calling g_enum_info_get_value() on a #GIEnumInfo.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_enum_info_get_n_values:
|
||||||
|
* @info: a #GIEnumInfo
|
||||||
|
*
|
||||||
|
* Obtain the number of values this enumeration contains.
|
||||||
|
*
|
||||||
|
* Returns: the number of enumeration values
|
||||||
|
*/
|
||||||
|
gint
|
||||||
|
g_enum_info_get_n_values (GIEnumInfo *info)
|
||||||
|
{
|
||||||
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
||||||
|
EnumBlob *blob;
|
||||||
|
|
||||||
|
g_return_val_if_fail (info != NULL, 0);
|
||||||
|
g_return_val_if_fail (GI_IS_ENUM_INFO (info), 0);
|
||||||
|
|
||||||
|
blob = (EnumBlob *)&rinfo->typelib->data[rinfo->offset];
|
||||||
|
|
||||||
|
return blob->n_values;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_enum_info_get_value:
|
||||||
|
* @info: a #GIEnumInfo
|
||||||
|
* @n: index of value to fetch
|
||||||
|
*
|
||||||
|
* Obtain a value for this enumeration.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): the enumeration value or %NULL if type tag is wrong,
|
||||||
|
* free the struct with g_base_info_unref() when done.
|
||||||
|
*/
|
||||||
|
GIValueInfo *
|
||||||
|
g_enum_info_get_value (GIEnumInfo *info,
|
||||||
|
gint n)
|
||||||
|
{
|
||||||
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
||||||
|
Header *header;
|
||||||
|
gint offset;
|
||||||
|
|
||||||
|
g_return_val_if_fail (info != NULL, NULL);
|
||||||
|
g_return_val_if_fail (GI_IS_ENUM_INFO (info), NULL);
|
||||||
|
|
||||||
|
header = (Header *)rinfo->typelib->data;
|
||||||
|
offset = rinfo->offset + header->enum_blob_size
|
||||||
|
+ n * header->value_blob_size;
|
||||||
|
|
||||||
|
return (GIValueInfo *) g_info_new (GI_INFO_TYPE_VALUE, (GIBaseInfo*)info, rinfo->typelib, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_enum_info_get_storage_type:
|
||||||
|
* @info: a #GIEnumInfo
|
||||||
|
*
|
||||||
|
* Obtain the tag of the type used for the enum in the C ABI. This will
|
||||||
|
* will be a signed or unsigned integral type.
|
||||||
|
|
||||||
|
* Note that in the current implementation the width of the type is
|
||||||
|
* computed correctly, but the signed or unsigned nature of the type
|
||||||
|
* may not match the sign of the type used by the C compiler.
|
||||||
|
*
|
||||||
|
* Return Value: the storage type for the enumeration
|
||||||
|
*/
|
||||||
|
GITypeTag
|
||||||
|
g_enum_info_get_storage_type (GIEnumInfo *info)
|
||||||
|
{
|
||||||
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
||||||
|
EnumBlob *blob;
|
||||||
|
|
||||||
|
g_return_val_if_fail (info != NULL, GI_TYPE_TAG_BOOLEAN);
|
||||||
|
g_return_val_if_fail (GI_IS_ENUM_INFO (info), GI_TYPE_TAG_BOOLEAN);
|
||||||
|
|
||||||
|
blob = (EnumBlob *)&rinfo->typelib->data[rinfo->offset];
|
||||||
|
|
||||||
|
return blob->storage_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_value_info_get_value:
|
||||||
|
* @info: a #GIValueInfo
|
||||||
|
*
|
||||||
|
* Obtain the enumeration value of the #GIValueInfo.
|
||||||
|
*
|
||||||
|
* Returns: the enumeration value
|
||||||
|
*/
|
||||||
|
glong
|
||||||
|
g_value_info_get_value (GIValueInfo *info)
|
||||||
|
{
|
||||||
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
||||||
|
ValueBlob *blob;
|
||||||
|
|
||||||
|
g_return_val_if_fail (info != NULL, -1);
|
||||||
|
g_return_val_if_fail (GI_IS_VALUE_INFO (info), -1);
|
||||||
|
|
||||||
|
blob = (ValueBlob *)&rinfo->typelib->data[rinfo->offset];
|
||||||
|
|
||||||
|
return (glong)blob->value;
|
||||||
|
}
|
||||||
|
|
51
gienuminfo.h
Normal file
51
gienuminfo.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* GObject introspection: Enum and Enum values
|
||||||
|
*
|
||||||
|
* 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 __GIENUMINFO_H__
|
||||||
|
#define __GIENUMINFO_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_ENUM_INFO(info) \
|
||||||
|
((g_base_info_get_type((GIBaseInfo*)info) == GI_INFO_TYPE_ENUM) || \
|
||||||
|
(g_base_info_get_type((GIBaseInfo*)info) == GI_INFO_TYPE_FLAGS))
|
||||||
|
|
||||||
|
#define GI_IS_VALUE_INFO(info) \
|
||||||
|
(g_base_info_get_type((GIBaseInfo*)info) == GI_INFO_TYPE_VALUE)
|
||||||
|
|
||||||
|
gint g_enum_info_get_n_values (GIEnumInfo *info);
|
||||||
|
GIValueInfo * g_enum_info_get_value (GIEnumInfo *info,
|
||||||
|
gint n);
|
||||||
|
GITypeTag g_enum_info_get_storage_type (GIEnumInfo *info);
|
||||||
|
|
||||||
|
glong g_value_info_get_value (GIValueInfo *info);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __GIENUMINFO_H__ */
|
||||||
|
|
112
ginfo.c
112
ginfo.c
@ -28,118 +28,6 @@
|
|||||||
#include "gitypelib-internal.h"
|
#include "gitypelib-internal.h"
|
||||||
#include "girepository-private.h"
|
#include "girepository-private.h"
|
||||||
|
|
||||||
|
|
||||||
/* GIEnumInfo and GIValueInfo functions */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SECTION:gienuminfo
|
|
||||||
* @Short_description: Structs representing an enumeration and its values
|
|
||||||
* @Title: GIEnumInfo
|
|
||||||
*
|
|
||||||
* A GIEnumInfo represents an enumeration and a GIValueInfo struct represents a value
|
|
||||||
* of an enumeration. The GIEnumInfo contains a set of values and a type
|
|
||||||
* The GIValueInfo is fetched by calling g_enum_info_get_value() on a #GIEnumInfo.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* g_enum_info_get_n_values:
|
|
||||||
* @info: a #GIEnumInfo
|
|
||||||
*
|
|
||||||
* Obtain the number of values this enumeration contains.
|
|
||||||
*
|
|
||||||
* Returns: the number of enumeration values
|
|
||||||
*/
|
|
||||||
gint
|
|
||||||
g_enum_info_get_n_values (GIEnumInfo *info)
|
|
||||||
{
|
|
||||||
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
||||||
EnumBlob *blob;
|
|
||||||
|
|
||||||
g_return_val_if_fail (info != NULL, 0);
|
|
||||||
g_return_val_if_fail (GI_IS_ENUM_INFO (info), 0);
|
|
||||||
|
|
||||||
blob = (EnumBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
||||||
|
|
||||||
return blob->n_values;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* g_enum_info_get_value:
|
|
||||||
* @info: a #GIEnumInfo
|
|
||||||
* @n: index of value to fetch
|
|
||||||
*
|
|
||||||
* Obtain a value for this enumeration.
|
|
||||||
*
|
|
||||||
* Returns: (transfer full): the enumeration value or %NULL if type tag is wrong,
|
|
||||||
* free the struct with g_base_info_unref() when done.
|
|
||||||
*/
|
|
||||||
GIValueInfo *
|
|
||||||
g_enum_info_get_value (GIEnumInfo *info,
|
|
||||||
gint n)
|
|
||||||
{
|
|
||||||
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
||||||
Header *header;
|
|
||||||
gint offset;
|
|
||||||
|
|
||||||
g_return_val_if_fail (info != NULL, NULL);
|
|
||||||
g_return_val_if_fail (GI_IS_ENUM_INFO (info), NULL);
|
|
||||||
|
|
||||||
header = (Header *)rinfo->typelib->data;
|
|
||||||
offset = rinfo->offset + header->enum_blob_size
|
|
||||||
+ n * header->value_blob_size;
|
|
||||||
|
|
||||||
return (GIValueInfo *) g_info_new (GI_INFO_TYPE_VALUE, (GIBaseInfo*)info, rinfo->typelib, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* g_enum_info_get_storage_type:
|
|
||||||
* @info: a #GIEnumInfo
|
|
||||||
*
|
|
||||||
* Obtain the tag of the type used for the enum in the C ABI. This will
|
|
||||||
* will be a signed or unsigned integral type.
|
|
||||||
|
|
||||||
* Note that in the current implementation the width of the type is
|
|
||||||
* computed correctly, but the signed or unsigned nature of the type
|
|
||||||
* may not match the sign of the type used by the C compiler.
|
|
||||||
*
|
|
||||||
* Return Value: the storage type for the enumeration
|
|
||||||
*/
|
|
||||||
GITypeTag
|
|
||||||
g_enum_info_get_storage_type (GIEnumInfo *info)
|
|
||||||
{
|
|
||||||
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
||||||
EnumBlob *blob;
|
|
||||||
|
|
||||||
g_return_val_if_fail (info != NULL, GI_TYPE_TAG_BOOLEAN);
|
|
||||||
g_return_val_if_fail (GI_IS_ENUM_INFO (info), GI_TYPE_TAG_BOOLEAN);
|
|
||||||
|
|
||||||
blob = (EnumBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
||||||
|
|
||||||
return blob->storage_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* g_value_info_get_value:
|
|
||||||
* @info: a #GIValueInfo
|
|
||||||
*
|
|
||||||
* Obtain the enumeration value of the #GIValueInfo.
|
|
||||||
*
|
|
||||||
* Returns: the enumeration value
|
|
||||||
*/
|
|
||||||
glong
|
|
||||||
g_value_info_get_value (GIValueInfo *info)
|
|
||||||
{
|
|
||||||
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
||||||
ValueBlob *blob;
|
|
||||||
|
|
||||||
g_return_val_if_fail (info != NULL, -1);
|
|
||||||
g_return_val_if_fail (GI_IS_VALUE_INFO (info), -1);
|
|
||||||
|
|
||||||
blob = (ValueBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
||||||
|
|
||||||
return (glong)blob->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* GIFieldInfo functions */
|
/* GIFieldInfo functions */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <giarginfo.h>
|
#include <giarginfo.h>
|
||||||
#include <gibaseinfo.h>
|
#include <gibaseinfo.h>
|
||||||
#include <gicallableinfo.h>
|
#include <gicallableinfo.h>
|
||||||
|
#include <gienuminfo.h>
|
||||||
#include <gierrordomaininfo.h>
|
#include <gierrordomaininfo.h>
|
||||||
#include <gifunctioninfo.h>
|
#include <gifunctioninfo.h>
|
||||||
#include <gitypeinfo.h>
|
#include <gitypeinfo.h>
|
||||||
@ -149,13 +150,6 @@ void gi_cclosure_marshal_generic (GClosure *closure,
|
|||||||
gpointer invocation_hint,
|
gpointer invocation_hint,
|
||||||
gpointer marshal_data);
|
gpointer marshal_data);
|
||||||
|
|
||||||
/* GIValueInfo */
|
|
||||||
|
|
||||||
#define GI_IS_VALUE_INFO(info) \
|
|
||||||
(g_base_info_get_type((GIBaseInfo*)info) == GI_INFO_TYPE_VALUE)
|
|
||||||
|
|
||||||
glong g_value_info_get_value (GIValueInfo *info);
|
|
||||||
|
|
||||||
|
|
||||||
/* GIFieldInfo */
|
/* GIFieldInfo */
|
||||||
|
|
||||||
@ -227,17 +221,6 @@ const gchar * g_registered_type_info_get_type_name (GIRegisteredTypeInf
|
|||||||
const gchar * g_registered_type_info_get_type_init (GIRegisteredTypeInfo *info);
|
const gchar * g_registered_type_info_get_type_init (GIRegisteredTypeInfo *info);
|
||||||
GType g_registered_type_info_get_g_type (GIRegisteredTypeInfo *info);
|
GType g_registered_type_info_get_g_type (GIRegisteredTypeInfo *info);
|
||||||
|
|
||||||
/* GIEnumInfo */
|
|
||||||
|
|
||||||
#define GI_IS_ENUM_INFO(info) \
|
|
||||||
((g_base_info_get_type((GIBaseInfo*)info) == GI_INFO_TYPE_ENUM) || \
|
|
||||||
(g_base_info_get_type((GIBaseInfo*)info) == GI_INFO_TYPE_FLAGS))
|
|
||||||
|
|
||||||
gint g_enum_info_get_n_values (GIEnumInfo *info);
|
|
||||||
GIValueInfo * g_enum_info_get_value (GIEnumInfo *info,
|
|
||||||
gint n);
|
|
||||||
GITypeTag g_enum_info_get_storage_type (GIEnumInfo *info);
|
|
||||||
|
|
||||||
/* GIObjectInfo */
|
/* GIObjectInfo */
|
||||||
|
|
||||||
#define GI_IS_OBJECT_INFO(info) \
|
#define GI_IS_OBJECT_INFO(info) \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user