GParamSpec further funcs



I was having a nose around some of the Glib::ParamSpec bits and wondered
if g_param_value_set_default() could do the work for
$paramspec->get_default_value.  Or is there some magic in the current
dispatch?  I tried the couple of lines below which seem to work, though
bools may come out different from gperl_sv_from_value().

I also wondered if there'd be some value in g_param_value_validate
and/or g_param_values_cmp.  I was tinkering with some comparing for my
"ConnectProperties".  g_param_values_cmp looks like it respects the
"epsilon" in float and double, though it also looks pretty useless on
boxed types (just a pointer compare).


--- GParamSpec.xs       18 Oct 2005 05:26:09 +1000      1.23
+++ GParamSpec.xs       16 Jun 2008 10:27:37 +1000      
@@ -288,6 +288,73 @@
 
 const gchar* g_param_spec_get_blurb (GParamSpec * pspec)
 
+MODULE = Glib::ParamSpec       PACKAGE = Glib::ParamSpec       PREFIX = g_param_
+
+SV *
+g_param_xxx_get_default_value (GParamSpec * pspec)
+    PREINIT:
+        GValue v = { 0, };
+        GType type;
+    CODE:
+        type = G_PARAM_SPEC_VALUE_TYPE (pspec);
+        g_value_init (&v, type);
+        g_param_value_set_default (pspec, &v);
+        RETVAL = gperl_sv_from_value (&v);
+        g_value_unset (&v);
+    OUTPUT:
+        RETVAL
+
+=for apidoc
+
+=signature bool = $paramspec->value_validate (value)
+
+=signature (bool, newval) = $paramspec->value_validate (value)
+
+In scalar context return a boolean indicating whether $value is valid
+for $paramspec.  In array context return also a new value which is
+$value modified to be valid, which means for instance clamped to the
+minimum/maximum, etc.
+
+=cut
+void
+g_param_value_validate (GParamSpec * pspec, SV *value)
+    PREINIT:
+        GValue v = { 0, };
+        GType type;
+        int ret;
+    PPCODE:
+        type = G_PARAM_SPEC_VALUE_TYPE (pspec);
+        g_value_init (&v, type);
+       gperl_value_from_sv (&v, value);
+        ret = g_param_value_validate (pspec, &v);
+        EXTEND (SP, 2);
+       PUSHs (sv_2mortal (boolSV (ret)));
+       if (GIMME_V == G_ARRAY)
+               PUSHs (sv_2mortal (gperl_sv_from_value (&v)));
+        g_value_unset (&v);
+
+int
+g_param_values_cmp (GParamSpec * pspec, SV *value1, SV *value2)
+    PREINIT:
+        GValue v1 = { 0, };
+        GValue v2 = { 0, };
+        GType type;
+    CODE:
+        type = G_PARAM_SPEC_VALUE_TYPE (pspec);
+        g_value_init (&v1, type);
+        g_value_init (&v2, type);
+       gperl_value_from_sv (&v1, value1);
+       gperl_value_from_sv (&v2, value2);
+        RETVAL = g_param_values_cmp (pspec, &v1, &v2);
+        g_value_unset (&v1);
+        g_value_unset (&v2);
+    OUTPUT:
+        RETVAL
+
+## gboolean g_value_type_compatible (GType src_type, GType dest_type);
+## gboolean g_value_type_transformable (GType src_type, GType dest_type);
+
+MODULE = Glib::ParamSpec       PACKAGE = Glib::ParamSpec       PREFIX = g_param_spec_
 
 ## stuff from gparamspecs.h
 


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