1 /* -*- Mode: C; ; c-file-style: "python" -*- */
3 * Copyright (C) 2005 Edward Hervey
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Edward Hervey <edward@fluendo.com>
29 gst_tag_list_add_values
30 gst_tag_list_add_valist_values
31 gst_tag_list_copy_value
33 gst_tag_list_remove_tag
37 define GstTagList.keys noargs
39 tag_foreach_func_list (const GstTagList *list,
45 count = gst_tag_list_get_tag_size(GST_TAG_LIST(list), tag);
47 PyErr_SetString(PyExc_KeyError, tag);
49 PyList_Append(py_list, PyString_FromString(tag));
53 _wrap_gst_tag_list_keys(PyGObject *self)
59 gst_tag_list_foreach(GST_TAG_LIST(self->obj),
60 (GstTagForeachFunc)tag_foreach_func_list,
65 override-slot GstTagList.tp_as_mapping
67 _wrap_gst_tag_list_length(PyObject *self)
69 PyGObject *gself = (PyGObject *)self;
70 return gst_structure_n_fields((GstStructure*)gself->obj);
74 _wrap_gst_tag_list_subscript(PyGObject *self, PyObject *py_key)
77 const char *field = PyString_AsString(py_key);
79 if (gst_structure_has_field((GstStructure*)self->obj, field)) {
81 gvalue = gst_structure_get_value((GstStructure*)self->obj, field);
82 g_assert(gvalue != NULL);
83 v = pygst_value_as_pyobject(gvalue, TRUE);
85 PyErr_SetString(PyExc_KeyError, field);
92 _wrap_gst_tag_list_ass_subscript(PyGObject *self,
97 GstStructure* structure;
100 structure = (GstStructure*)self->obj;
101 key = PyString_AsString(py_key);
102 if (py_value != NULL) {
105 if (!pygst_value_init_for_pyobject (&v, py_value))
107 if (pygst_value_from_pyobject(&v, py_value))
110 /* some tags are supposed to be uint, but there is no unsigned
111 * int python type, so convert here if needed */
112 if (gst_tag_exists (key)) {
113 tagtype = gst_tag_get_type (key);
115 if (tagtype && tagtype != G_VALUE_TYPE (&v)) {
118 g_value_init (&w, tagtype);
119 g_value_transform (&v, &w);
121 g_value_init (&v, tagtype);
122 g_value_copy (&w, &v);
125 gst_structure_set_value(structure, key, &v);
128 gst_structure_remove_field(structure, key);
134 static PyMappingMethods _wrap_gst_tag_list_tp_as_mapping = {
135 _wrap_gst_tag_list_length, /* mp_length */
136 (binaryfunc)_wrap_gst_tag_list_subscript, /* mp_subscript */
137 (objobjargproc)_wrap_gst_tag_list_ass_subscript /* mp_ass_subscript */
140 override-slot GstTagList.tp_as_sequence
142 _wrap_gst_tag_list_contains(PyGObject *self, PyObject *py_key)
144 return gst_structure_has_field((GstStructure*)self->obj,
145 PyString_AsString(py_key));
148 static PySequenceMethods _wrap_gst_tag_list_tp_as_sequence = {
153 (ssizessizeargfunc)NULL,
154 (ssizeobjargproc)NULL,
155 (ssizessizeobjargproc)NULL,
156 (objobjproc)_wrap_gst_tag_list_contains,