cogl-boxed-value: Add _cogl_boxed_value_copy

This adds a function to copy one boxed value to another. It is assumed
that the destination boxed value is totally initialised (so it won't
try to free any memory in it).

Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
Neil Roberts 2011-11-04 16:21:28 +00:00
parent 7068849ae6
commit 436a7a45da
2 changed files with 45 additions and 0 deletions

View File

@ -201,6 +201,40 @@ _cogl_boxed_value_set_matrix (CoglBoxedValue *bv,
transpose); transpose);
} }
void
_cogl_boxed_value_copy (CoglBoxedValue *dst,
const CoglBoxedValue *src)
{
*dst = *src;
if (src->count > 1)
{
switch (src->type)
{
case COGL_BOXED_NONE:
break;
case COGL_BOXED_INT:
dst->v.int_array = g_memdup (src->v.int_array,
src->size * src->count * sizeof (int));
break;
case COGL_BOXED_FLOAT:
dst->v.float_array = g_memdup (src->v.float_array,
src->size *
src->count *
sizeof (float));
break;
case COGL_BOXED_MATRIX:
dst->v.float_array = g_memdup (src->v.float_array,
src->size * src->size *
src->count * sizeof (float));
break;
}
}
}
void void
_cogl_boxed_value_destroy (CoglBoxedValue *bv) _cogl_boxed_value_destroy (CoglBoxedValue *bv)
{ {

View File

@ -89,6 +89,17 @@ _cogl_boxed_value_set_matrix (CoglBoxedValue *bv,
gboolean transpose, gboolean transpose,
const float *value); const float *value);
/*
* _cogl_boxed_value_copy:
* @dst: The destination boxed value
* @src: The source boxed value
*
* This copies @src to @dst. It is assumed that @dst is initialised.
*/
void
_cogl_boxed_value_copy (CoglBoxedValue *dst,
const CoglBoxedValue *src);
void void
_cogl_boxed_value_destroy (CoglBoxedValue *bv); _cogl_boxed_value_destroy (CoglBoxedValue *bv);