After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 534208 - [API] add gst_structure_get()
[API] add gst_structure_get()
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal enhancement
: 0.10.24
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2008-05-21 15:38 UTC by Andy Wingo
Modified: 2009-06-10 08:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
API: add gst_structure_{id}_get{_valist}() convenience functions (14.04 KB, patch)
2009-06-08 22:49 UTC, Tim-Philipp Müller
none Details | Review

Description Andy Wingo 2008-05-21 15:38:34 UTC
Verily, some functions we should have:

You have to #include <gobject/gvaluecollector.h> in the .c file for these.

What think the people?

gboolean
gst_structure_get_valist (GstStructure *s, const char *first_field_name,
                          va_list args)
{
  const char *field_name = first_field_name;

  while (field_name) {
    GType t;
    const GValue *got = NULL;
    gchar *error;

    t = va_arg (args, GType);

    got = gst_structure_get_value (s, field_name);
    if (!got)
      return FALSE;
    if (G_VALUE_TYPE (got) != t)
      return FALSE;
    
    G_VALUE_LCOPY (got, args, 0, &error);
    if (error) {
      g_warning ("%s: %s", G_STRFUNC, error);
      g_free (error);
      return FALSE;
    }

    field_name = va_arg (args, const gchar*);
  }
  
  return TRUE;
}

gboolean
gst_structure_get (GstStructure *s, const char *first_field_name, ...)
{
  gboolean ret;
  va_list args;
  va_start (args, first_field_name);
  ret = gst_structure_get_valist (s, first_field_name, args);
  va_end (args);
  return ret;
}
Comment 1 Wim Taymans 2008-05-22 14:11:53 UTC
and don't forget the gst_structure_id_get variants!
Comment 2 Sebastian Dröge (slomo) 2008-05-22 18:41:24 UTC
Sounds like a good idea IMHO :)
Comment 3 Tim-Philipp Müller 2009-06-08 22:49:05 UTC
Created attachment 136178 [details] [review]
API: add gst_structure_{id}_get{_valist}() convenience functions

How 'bout this then?
Comment 4 Edward Hervey 2009-06-09 09:16:26 UTC
awesome, it should go in ASAP
Comment 5 Tim-Philipp Müller 2009-06-10 08:41:21 UTC
Committed with slight changes after discussion on IRC (so that NULL return locations work as well):

 commit cdd47a37e9b11604ab626907d43aa510a0b5d614
 Author: Tim-Philipp Müller <tim.muller@collabora.co.uk>
 Date:   Mon Jun 8 23:43:16 2009 +0100

    structure: add gst_structure_*_get*() vararg functions
    
    Add a bunch of vararg getter convenience functions to complement
    the vararg setter functions, and a basic unit test. Fixes #534208.
    
    API: gst_structure_get()
    API: gst_structure_id_get()
    API: gst_structure_get_valist()
    API: gst_structure_id_get_valist()