[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: enum/flags list_values values
- From: Torsten Schoenfeld <kaffeetisch gmx de>
- To: gtk-perl-list gnome org
- Subject: Re: enum/flags list_values values
- Date: Wed, 16 Jan 2008 19:30:55 +0100
On Sat, 2008-01-05 at 07:44 +1100, Kevin Ryde wrote:
> Is Glib::Type->list_values meant to give back the values from the enum
> and flags entries, as well as the names? (There's no significance in
> the order of the returned list or anything, is there.)
While the values do seem to be returned in order, I still think it makes
sense to include the actual value in the hash. So here's the same patch
with a test. muppet, what do you think?
--
Bye,
-Torsten
Index: GType.xs
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/GType.xs,v
retrieving revision 1.84
diff -u -d -p -r1.84 GType.xs
--- GType.xs 9 Jan 2008 06:10:34 -0000 1.84
+++ GType.xs 16 Jan 2008 18:27:53 -0000
@@ -2566,7 +2566,12 @@ hasn't been registered with the bindings
this function will croak.
Returns the values as a list of hashes, one hash for each value, containing
-that value's name and nickname.
+the value, name and nickname, eg. for Glib::SignalFlags
+
+ { value => 8,
+ name => 'G_SIGNAL_NO_RECURSE',
+ nick => 'no-recurse'
+ }
=cut
void
@@ -2581,15 +2586,15 @@ list_values (class, const char * package
croak ("%s is not registered with either GPerl or GLib",
package);
/*
- * unfortunately, GFlagsValue and GEnumValue different structures
- * that happen to have identical definitions, so even though it
- * is very inviting to use the same code for them, it's not
- * technically a good idea.
+ * GFlagsValue and GEnumValue are nearly the same, but differ in
+ * that GFlagsValue is a guint for the value, but GEnumValue is gint
+ * (and some enums do indeed use negatives, eg. GtkResponseType).
*/
if (G_TYPE_IS_ENUM (type)) {
GEnumValue * v = gperl_type_enum_get_values (type);
for ( ; v && v->value_nick && v->value_name ; v++) {
HV * hv = newHV ();
+ hv_store (hv, "value",5, newSViv (v->value), 0);
hv_store (hv, "nick", 4, newSVpv (v->value_nick, 0), 0);
hv_store (hv, "name", 4, newSVpv (v->value_name, 0), 0);
XPUSHs (sv_2mortal (newRV_noinc ((SV*)hv)));
@@ -2598,6 +2603,7 @@ list_values (class, const char * package
GFlagsValue * v = gperl_type_flags_get_values (type);
for ( ; v && v->value_nick && v->value_name ; v++) {
HV * hv = newHV ();
+ hv_store (hv, "value",5, newSVuv (v->value), 0);
hv_store (hv, "nick", 4, newSVpv (v->value_nick, 0), 0);
hv_store (hv, "name", 4, newSVpv (v->value_name, 0), 0);
XPUSHs (sv_2mortal (newRV_noinc ((SV*)hv)));
Index: t/c.t
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/t/c.t,v
retrieving revision 1.7
diff -u -d -p -r1.7 c.t
--- t/c.t 5 Oct 2005 19:03:39 -0000 1.7
+++ t/c.t 16 Jan 2008 18:27:53 -0000
@@ -11,7 +11,7 @@ use warnings;
#########################
-use Test::More tests => 14;
+use Test::More tests => 15;
BEGIN { use_ok('Glib') };
#########################
@@ -70,6 +70,41 @@ eval {
};
ok ($@, 'failed register_flag with undef');
+my @actual_values = Glib::Type->list_values ('TestEnum');
+my @expected_values = (
+ {
+ value => 1,
+ name => 'value-one',
+ nick => 'value-one',
+ },
+ {
+ value => 2,
+ name => 'value-two',
+ nick => 'value-two',
+ },
+ {
+ value => 3,
+ name => 'value-three',
+ nick => 'value-three',
+ },
+ {
+ value => 42,
+ name => 'value-four',
+ nick => 'value-four',
+ },
+ {
+ value => 5,
+ name => 'value-five',
+ nick => 'value-five',
+ },
+ {
+ value => 6,
+ name => 'value-six',
+ nick => 'value-six',
+ },
+);
+is_deeply (\ actual_values, \ expected_values, 'list_interfaces');
+
package Tester;
use Test::More;
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]