mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-22 17:51:16 +00:00
Add gst_value_init_and_copy() and use it, to avoid silly mistakes in using g_value_copy()
Original commit message from CVS: Add gst_value_init_and_copy() and use it, to avoid silly mistakes in using g_value_copy()
This commit is contained in:
parent
003a59c4f3
commit
72163f3e5c
4 changed files with 30 additions and 25 deletions
|
@ -1,3 +1,9 @@
|
|||
2003-12-22 David Schleef <ds@schleef.org>
|
||||
|
||||
* gststructure.c, gstvalue.c, gstvalue.h: Add
|
||||
gst_value_init_and_copy() and use it, to avoid silly mistakes in
|
||||
using g_value_copy()
|
||||
|
||||
2003-12-21 David Schleef <ds@schleef.org>
|
||||
|
||||
* many, many files: Merge CAPS branch. This includes:
|
||||
|
|
|
@ -221,9 +221,7 @@ GstStructure *gst_structure_copy(GstStructure *structure)
|
|||
field = GST_STRUCTURE_FIELD(structure, i);
|
||||
|
||||
new_field.name = field->name;
|
||||
g_value_init(&new_field.value, G_VALUE_TYPE(&field->value));
|
||||
g_value_copy(&field->value, &new_field.value);
|
||||
|
||||
gst_value_init_and_copy (&new_field.value, &field->value);
|
||||
g_array_append_val(new_structure->fields, new_field);
|
||||
}
|
||||
|
||||
|
@ -308,8 +306,7 @@ void gst_structure_id_set_value(GstStructure *structure, GQuark fieldname,
|
|||
g_return_if_fail(G_IS_VALUE(value));
|
||||
|
||||
field.name = fieldname;
|
||||
g_value_init(&field.value, G_VALUE_TYPE (value));
|
||||
g_value_copy(value, &field.value);
|
||||
gst_value_init_and_copy (&field.value, value);
|
||||
|
||||
gst_structure_set_field(structure, &field);
|
||||
}
|
||||
|
|
|
@ -71,8 +71,8 @@ gst_value_list_array_copy (const GArray *src)
|
|||
dest = g_array_sized_new (FALSE, TRUE, sizeof(GValue), src->len);
|
||||
g_array_set_size (dest, src->len);
|
||||
for (i = 0; i < src->len; i++) {
|
||||
g_value_init (&g_array_index(dest, GValue, i), G_VALUE_TYPE (&g_array_index(src, GValue, i)));
|
||||
g_value_copy (&g_array_index(src, GValue, i), &g_array_index(dest, GValue, i));
|
||||
gst_value_init_and_copy (&g_array_index(dest, GValue, i),
|
||||
&g_array_index(src, GValue, i));
|
||||
}
|
||||
|
||||
return dest;
|
||||
|
@ -197,22 +197,21 @@ gst_value_list_concat (GValue *dest, const GValue *value1, const GValue *value2)
|
|||
|
||||
if (GST_VALUE_HOLDS_LIST (value1)) {
|
||||
for (i = 0; i < value1_length; i++) {
|
||||
g_value_init (&g_array_index(array, GValue, i), G_VALUE_TYPE (gst_value_list_get_value (value1, i)));
|
||||
g_value_copy (gst_value_list_get_value (value1, i), &g_array_index(array, GValue, i));
|
||||
gst_value_init_and_copy (&g_array_index(array, GValue, i),
|
||||
gst_value_list_get_value (value1, i));
|
||||
}
|
||||
} else {
|
||||
g_value_init (&g_array_index(array, GValue, 0), G_VALUE_TYPE (value1));
|
||||
g_value_copy (value1, &g_array_index(array, GValue, 0));
|
||||
gst_value_init_and_copy (&g_array_index(array, GValue, 0), value1);
|
||||
}
|
||||
|
||||
if (GST_VALUE_HOLDS_LIST (value2)) {
|
||||
for (i = 0; i < value2_length; i++) {
|
||||
g_value_init (&g_array_index(array, GValue, i + value1_length), G_VALUE_TYPE (gst_value_list_get_value (value2, i)));
|
||||
g_value_copy (gst_value_list_get_value (value2, i), &g_array_index(array, GValue, i + value1_length));
|
||||
gst_value_init_and_copy (&g_array_index(array, GValue, i + value1_length),
|
||||
gst_value_list_get_value (value2, i));
|
||||
}
|
||||
} else {
|
||||
g_value_init (&g_array_index(array, GValue, value1_length), G_VALUE_TYPE (value2));
|
||||
g_value_copy (value2, &g_array_index(array, GValue, value1_length));
|
||||
gst_value_init_and_copy (&g_array_index(array, GValue, value1_length),
|
||||
value2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -703,8 +702,7 @@ gst_value_intersect_int_int_range (GValue *dest, const GValue *src1,
|
|||
|
||||
if (src2->data[0].v_int <= src1->data[0].v_int &&
|
||||
src2->data[1].v_int >= src1->data[0].v_int){
|
||||
g_value_init(dest, G_TYPE_INT);
|
||||
g_value_copy(src1, dest);
|
||||
gst_value_init_and_copy (dest, src1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -747,8 +745,7 @@ gst_value_intersect_double_double_range (GValue *dest, const GValue *src1,
|
|||
|
||||
if (src2->data[0].v_double <= src1->data[0].v_double &&
|
||||
src2->data[1].v_double >= src1->data[0].v_double){
|
||||
g_value_init(dest, G_TYPE_DOUBLE);
|
||||
g_value_copy(src1, dest);
|
||||
gst_value_init_and_copy (dest, src1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -798,16 +795,14 @@ gst_value_intersect_list (GValue *dest, const GValue *value1, const GValue *valu
|
|||
if (gst_value_intersect (&intersection, cur, value2)) {
|
||||
/* append value */
|
||||
if (!ret) {
|
||||
g_value_init (dest, G_VALUE_TYPE(&intersection));
|
||||
g_value_copy (dest, &intersection);
|
||||
gst_value_init_and_copy (dest, &intersection);
|
||||
ret = TRUE;
|
||||
} else if (GST_VALUE_HOLDS_LIST (dest)) {
|
||||
gst_value_list_append_value (dest, &intersection);
|
||||
} else {
|
||||
GValue temp = {0, };
|
||||
|
||||
g_value_init (&temp, G_VALUE_TYPE(dest));
|
||||
g_value_copy (dest, &temp);
|
||||
gst_value_init_and_copy (&temp, dest);
|
||||
g_value_unset (dest);
|
||||
gst_value_list_concat (dest, &temp, &intersection);
|
||||
}
|
||||
|
@ -868,14 +863,20 @@ gst_value_intersect (GValue *dest, const GValue *value1, const GValue *value2)
|
|||
}
|
||||
|
||||
if(gst_value_compare(value1, value2) == GST_VALUE_EQUAL){
|
||||
g_value_init(dest, G_VALUE_TYPE(value1));
|
||||
g_value_copy(value1, dest);
|
||||
gst_value_init_and_copy (dest, value1);
|
||||
ret = TRUE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
gst_value_init_and_copy (GValue *dest, const GValue *src)
|
||||
{
|
||||
g_value_init (dest, G_VALUE_TYPE(src));
|
||||
g_value_copy (src, dest);
|
||||
}
|
||||
|
||||
void
|
||||
gst_value_register_intersect_func (GType type1, GType type2,
|
||||
GstValueIntersectFunc func)
|
||||
|
|
|
@ -85,6 +85,7 @@ void gst_value_list_concat (GValue *dest, const GValue *value1, const GValue *va
|
|||
|
||||
void _gst_value_initialize (void);
|
||||
|
||||
void gst_value_init_and_copy (GValue *dest, const GValue *src);
|
||||
int gst_value_compare (const GValue *src1, const GValue *src2);
|
||||
gboolean gst_value_intersect (GValue *dest, const GValue *src1, const GValue *src2);
|
||||
gboolean gst_value_union (GValue *dest, const GValue *src1, const GValue *src2);
|
||||
|
|
Loading…
Reference in a new issue