[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: flags object from strings



muppet <scott asofyet org> writes:
>
> The big question is, what kind of syntax would you expect for this?

Perhaps a "new" method.

  my $f = Glib::ParamFlags->new (['readable']);

Some code below.  It runs, but dunno if I understand the subtleties of
classname to gtype conversion.  (Getting back G_TYPE_FLAGS depends on
your previously posted change too, otherwise Glib::Flags is
"unregistered".)

>      my $num = 0;
...
>      return bless \$num, $type;

That's what I broke out as a workaround starting object :-)

  my $empty_events = bless (do{my $zero=0; \$zero}, 'Gtk2::Gdk::EventMask');

-- 
"They say he carved it himself, from a bigger spoon."


--- GType.xs	03 May 2008 09:54:33 +1000	1.86
+++ GType.xs	03 May 2008 10:05:26 +1000	
@@ -2684,6 +2684,34 @@
 =cut
 
 =for apidoc
+Create a new flags object with given bits.  This is for use from a
+subclass, it's not possible to create a C<Glib::Flags> object as such.
+For example,
+
+    my $f1 = Glib::ParamFlags->new ('readable');
+    my $f2 = Glib::ParamFlags->new (['readable','writable']);
+
+An object like this can then be used with the overloaded operators.
+=cut
+SV *
+new (const char *class, SV *a)
+    PREINIT:
+	GType gtype;
+    CODE:
+	gtype = gperl_fundamental_type_from_package (class);
+        if (! gtype) {
+		croak ("package %s is not registered with the GLib type system",
+		       class);
+        }
+        if (gtype == G_TYPE_FLAGS) {
+		croak ("cannot create Glib::Flags (only subclasses)");
+        }
+        RETVAL = gperl_convert_back_flags
+        		(gtype, gperl_convert_flags (gtype, a));
+    OUTPUT:
+        RETVAL
+
+=for apidoc
 =for arg b (SV*)
 =for arg swap (integer)
 =cut
use strict;
use warnings;
use Glib;

my $f = Glib::ParamFlags->new (['readable']);
print $f,"\n";
use Data::Dumper;
print Dumper($f);

my $g = Glib::ParamFlags->new ($f + 'writable');
print $g,"\n";
print Dumper($g);

# this is an error
my $h = Glib::Flags->new (['readable']);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]