Re: Wrapping variable argument functions



Murray Cumming wrote:
On Wed, 2008-02-06 at 22:26 -0500, José Alburquerque wrote:
José Alburquerque wrote:
You know, I think I'll do something like what happens with Gst::Element::link() which returns the element so another link can be called right after, as in:

element->link(one)->link(two);

So the syntax would look like:

pad->set(f1)->set(f2).  Would this work?  Thanks.

This almost worked, but the series of references causes GstStructure immutability warnings because the GstCaps is referenced more than once when an attempt at adding a field to one of its GstStructure occurs. I'm left with adding fields one at time.

I don't quite understand. Could you send me a patch that shows the
problem - maybe I can fix it.

Okay. Here's the patch. To produce the problem simply run tests/test-caps. The way it's in svn now, test/test-caps works fine, but with this patch I get warnings.

-Jose
Index: gstreamer/src/caps.ccg
===================================================================
--- gstreamer/src/caps.ccg	(revision 1324)
+++ gstreamer/src/caps.ccg	(working copy)
@@ -45,15 +45,14 @@
   set the field in the Structure ourselves so we must check for only one
   Structure ourselves also (because we wont be calling gst_caps_set_simple)
 */
-//Glib::RefPtr<Caps>
-void
+Glib::RefPtr<Caps>
 Caps::set_simple(const Glib::ustring& name, const Glib::ValueBase& value)
 {
-  //g_return_val_if_fail((gobj()->structs->len == 1), Glib::RefPtr<Caps>());
-  g_return_if_fail((gobj()->structs->len == 1));
+  g_return_val_if_fail((gobj()->structs->len == 1), Glib::RefPtr<Caps>());
+  //g_return_if_fail((gobj()->structs->len == 1));
   gst_structure_set_value(gst_caps_get_structure(gobj(), 0), name.c_str(), value.gobj());
 
-  //return Glib::wrap(gobj(), true);
+  return Glib::wrap(gobj(), true);
 }
 
 } //namespace Gst
Index: gstreamer/src/caps.hg
===================================================================
--- gstreamer/src/caps.hg	(revision 1324)
+++ gstreamer/src/caps.hg	(working copy)
@@ -36,7 +36,7 @@
   //TODO: as 'caps->set_simple(name1, value1)->set_simple(name2, value2)' a
   //TODO: causes Structure immutability warnings because the Caps is referenced
   //TODO: more than once in the expression
-  void set_simple(const Glib::ustring& name, const Glib::ValueBase& value);
+  Glib::RefPtr<Caps> set_simple(const Glib::ustring& name, const Glib::ValueBase& value);
 
   //TODO: Is this method useful? -Jose
   _WRAP_METHOD(void set_simple_valist(char* field, const va_list& varargs), gst_caps_set_simple_valist)
Index: tests/test-caps.cc
===================================================================
--- tests/test-caps.cc	(revision 1324)
+++ tests/test-caps.cc	(working copy)
@@ -17,8 +17,7 @@
   height.init(G_TYPE_INT);
   height.set(288);
 
-  caps->set_simple("width", width);
-  caps->set_simple("height", height);
+  caps->set_simple("width", width)->set_simple("height", height);
 
   return 0;
 }


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