1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
* Copyright (C) 2011 Igalia S.L.
*
* Contact: Iago Toral Quiroga <itoral@igalia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/*
* This module provides helper functions to use GValues easily. Inspired by
* libsoup's soup-value-utils:
* http://git.gnome.org/browse/libsoup/tree/libsoup/soup-value-utils.c
*
*/
#include <grl-value-helper.h>
GValue *
grl_g_value_new (GType g_type)
{
GValue *value;
value = g_slice_new0 (GValue);
g_value_init (value, g_type);
return value;
}
void
grl_g_value_free (GValue *value)
{
g_value_unset (value);
g_slice_free (GValue, value);
}
/**
* grl_g_value_hashtable_new:
*
* Returns: (element-type utf8 GValue) (transfer full): a new hash table made to contain GValues.
*/
GHashTable *
grl_g_value_hashtable_new (void)
{
return g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)grl_g_value_free);
}
/**
* grl_g_value_hashtable_new_direct:
*
* Returns: (element-type gpointer GValue) (transfer full): a new hash table made to contain GValues.
*/
GHashTable *
grl_g_value_hashtable_new_direct (void)
{
return g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)grl_g_value_free);
}
/**
* grl_g_value_dup:
* @value: the #GValue to copy
*
* Returns: (transfer full): a duplicated #GValue
*/
GValue *
grl_g_value_dup (const GValue *value)
{
GValue *new_value = grl_g_value_new (G_VALUE_TYPE (value));
g_value_copy (value, new_value);
return new_value;
}
|