2012-02-03 19:42:56 +01:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
* GObject introspection: Enum implementation
|
2010-06-06 18:06:30 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Matthias Clasen
|
|
|
|
* Copyright (C) 2008,2009 Red Hat, Inc.
|
|
|
|
*
|
2023-10-25 18:10:10 +02:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
*
|
2010-06-06 18:06:30 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-07-04 12:27:41 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-06-06 18:06:30 +02:00
|
|
|
#include <glib.h>
|
|
|
|
|
2023-10-25 18:45:42 +02:00
|
|
|
#include <girepository/girepository.h>
|
2023-11-28 18:24:20 +01:00
|
|
|
#include "gibaseinfo-private.h"
|
2010-06-06 18:06:30 +02:00
|
|
|
#include "girepository-private.h"
|
|
|
|
#include "gitypelib-internal.h"
|
2023-10-25 19:11:38 +02:00
|
|
|
#include "gienuminfo.h"
|
2010-06-06 18:06:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gienuminfo
|
2013-10-10 22:21:18 +02:00
|
|
|
* @title: GIEnumInfo
|
|
|
|
* @short_description: Structs representing an enumeration and its values
|
2010-06-06 18:06:30 +02:00
|
|
|
*
|
2022-02-13 15:20:51 +01:00
|
|
|
* A GIEnumInfo represents an enumeration, and a GIValueInfo represents
|
|
|
|
* a value in the enumeration.
|
|
|
|
*
|
|
|
|
* The GIEnumInfo contains a set of values and a type.
|
|
|
|
*
|
2023-11-08 15:17:52 +01:00
|
|
|
* The GIValueInfo is fetched by calling gi_enum_info_get_value() on
|
2022-02-13 15:20:51 +01:00
|
|
|
* a GIEnumInfo.
|
2010-06-06 18:06:30 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_enum_info_get_n_values:
|
2013-10-10 22:21:18 +02:00
|
|
|
* @info: a #GIEnumInfo
|
|
|
|
*
|
|
|
|
* Obtain the number of values this enumeration contains.
|
|
|
|
*
|
|
|
|
* Returns: the number of enumeration values
|
|
|
|
*/
|
2023-12-12 18:44:49 +01:00
|
|
|
guint
|
2023-11-08 15:17:52 +01:00
|
|
|
gi_enum_info_get_n_values (GIEnumInfo *info)
|
2010-06-06 18:06:30 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-14 20:51:57 +01:00
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_enum_info_get_error_domain:
|
2013-02-14 20:51:57 +01:00
|
|
|
* @info: a #GIEnumInfo
|
|
|
|
*
|
|
|
|
* Obtain the string form of the quark for the error domain associated with
|
|
|
|
* this enum, if any.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the string form of the error domain associated
|
|
|
|
* with this enum, or %NULL.
|
2023-11-09 00:24:11 +01:00
|
|
|
* Since: 2.80
|
2013-02-14 20:51:57 +01:00
|
|
|
*/
|
2011-05-19 22:21:13 +02:00
|
|
|
const gchar *
|
2023-11-08 15:17:52 +01:00
|
|
|
gi_enum_info_get_error_domain (GIEnumInfo *info)
|
2011-05-19 22:21:13 +02:00
|
|
|
{
|
|
|
|
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];
|
|
|
|
|
|
|
|
if (blob->error_domain)
|
2023-11-08 15:17:52 +01:00
|
|
|
return gi_typelib_get_string (rinfo->typelib, blob->error_domain);
|
2011-05-19 22:21:13 +02:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-06 18:06:30 +02:00
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_enum_info_get_value:
|
2010-06-06 18:06:30 +02:00
|
|
|
* @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,
|
2023-11-08 15:17:52 +01:00
|
|
|
* free the struct with gi_base_info_unref() when done.
|
2010-06-06 18:06:30 +02:00
|
|
|
*/
|
|
|
|
GIValueInfo *
|
2023-11-08 15:17:52 +01:00
|
|
|
gi_enum_info_get_value (GIEnumInfo *info,
|
2023-12-12 18:44:49 +01:00
|
|
|
guint n)
|
2010-06-06 18:06:30 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
return (GIValueInfo *) gi_info_new (GI_INFO_TYPE_VALUE, (GIBaseInfo*)info, rinfo->typelib, offset);
|
2010-06-06 18:06:30 +02:00
|
|
|
}
|
|
|
|
|
2011-08-13 17:28:30 +02:00
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_enum_info_get_n_methods:
|
2011-08-13 17:28:30 +02:00
|
|
|
* @info: a #GIEnumInfo
|
|
|
|
*
|
|
|
|
* Obtain the number of methods that this enum type has.
|
|
|
|
*
|
|
|
|
* Returns: number of methods
|
2023-11-09 00:24:11 +01:00
|
|
|
* Since: 2.80
|
2011-08-13 17:28:30 +02:00
|
|
|
*/
|
2023-12-12 18:44:49 +01:00
|
|
|
guint
|
2023-11-08 15:17:52 +01:00
|
|
|
gi_enum_info_get_n_methods (GIEnumInfo *info)
|
2011-08-13 17:28:30 +02:00
|
|
|
{
|
|
|
|
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_methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_enum_info_get_method:
|
2011-08-13 17:28:30 +02:00
|
|
|
* @info: a #GIEnumInfo
|
|
|
|
* @n: index of method to get
|
|
|
|
*
|
|
|
|
* Obtain an enum type method at index @n.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the #GIFunctionInfo. Free the struct by calling
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_base_info_unref() when done.
|
2023-11-09 00:24:11 +01:00
|
|
|
* Since: 2.80
|
2011-08-13 17:28:30 +02:00
|
|
|
*/
|
|
|
|
GIFunctionInfo *
|
2023-11-08 15:17:52 +01:00
|
|
|
gi_enum_info_get_method (GIEnumInfo *info,
|
2023-12-12 18:44:49 +01:00
|
|
|
guint n)
|
2011-08-13 17:28:30 +02:00
|
|
|
{
|
|
|
|
gint offset;
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
Header *header;
|
|
|
|
EnumBlob *blob;
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GI_IS_ENUM_INFO (info), NULL);
|
|
|
|
|
|
|
|
header = (Header *)rinfo->typelib->data;
|
|
|
|
blob = (EnumBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
offset = rinfo->offset + header->enum_blob_size
|
|
|
|
+ blob->n_values * header->value_blob_size
|
|
|
|
+ n * header->function_blob_size;
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
return (GIFunctionInfo *) gi_info_new (GI_INFO_TYPE_FUNCTION, (GIBaseInfo*)info,
|
|
|
|
rinfo->typelib, offset);
|
2011-08-13 17:28:30 +02:00
|
|
|
}
|
|
|
|
|
2010-06-06 18:06:30 +02:00
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_enum_info_get_storage_type:
|
2010-06-06 18:06:30 +02:00
|
|
|
* @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.
|
2013-10-10 22:21:18 +02:00
|
|
|
*
|
2010-06-06 18:06:30 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2013-10-10 22:21:18 +02:00
|
|
|
* Returns: the storage type for the enumeration
|
2010-06-06 18:06:30 +02:00
|
|
|
*/
|
|
|
|
GITypeTag
|
2023-11-08 15:17:52 +01:00
|
|
|
gi_enum_info_get_storage_type (GIEnumInfo *info)
|
2010-06-06 18:06:30 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-11-28 18:24:20 +01:00
|
|
|
void
|
|
|
|
gi_enum_info_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GIBaseInfoClass *info_class = g_class;
|
|
|
|
|
|
|
|
info_class->info_type = GI_INFO_TYPE_ENUM;
|
|
|
|
}
|
|
|
|
|
2010-06-06 18:06:30 +02:00
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_value_info_get_value:
|
2010-06-06 18:06:30 +02:00
|
|
|
* @info: a #GIValueInfo
|
|
|
|
*
|
|
|
|
* Obtain the enumeration value of the #GIValueInfo.
|
|
|
|
*
|
2010-09-14 17:59:03 +02:00
|
|
|
* Returns: the enumeration value. This will always be representable
|
|
|
|
* as a 32-bit signed or unsigned value. The use of gint64 as the
|
|
|
|
* return type is to allow both.
|
2010-06-06 18:06:30 +02:00
|
|
|
*/
|
2010-09-14 17:59:03 +02:00
|
|
|
gint64
|
2023-11-08 15:17:52 +01:00
|
|
|
gi_value_info_get_value (GIValueInfo *info)
|
2010-06-06 18:06:30 +02:00
|
|
|
{
|
|
|
|
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];
|
|
|
|
|
2010-09-14 17:59:03 +02:00
|
|
|
if (blob->unsigned_value)
|
|
|
|
return (gint64)(guint32)blob->value;
|
|
|
|
else
|
|
|
|
return (gint64)blob->value;
|
2010-06-06 18:06:30 +02:00
|
|
|
}
|
2023-11-28 18:24:20 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
gi_value_info_class_init (gpointer g_class,
|
|
|
|
gpointer class_data)
|
|
|
|
{
|
|
|
|
GIBaseInfoClass *info_class = g_class;
|
|
|
|
|
|
|
|
info_class->info_type = GI_INFO_TYPE_VALUE;
|
|
|
|
}
|