initial import
[vuplus_webkit] / Source / JavaScriptCore / wtf / gobject / GRefPtr.cpp
1 /*
2  * Copyright (C) 2009 Martin Robinson
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2 of the License, or (at your option) any later version.
8  *
9  *  This library is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with this library; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include "config.h"
20 #include "GRefPtr.h"
21
22 #if ENABLE(GLIB_SUPPORT)
23
24 #include <glib.h>
25
26 namespace WTF {
27
28 template <> GHashTable* refGPtr(GHashTable* ptr)
29 {
30     if (ptr)
31         g_hash_table_ref(ptr);
32     return ptr;
33 }
34
35 template <> void derefGPtr(GHashTable* ptr)
36 {
37     g_hash_table_unref(ptr);
38 }
39
40 #if GLIB_CHECK_VERSION(2, 24, 0)
41 template <> GVariant* refGPtr(GVariant* ptr)
42 {
43     if (ptr)
44         g_variant_ref(ptr);
45     return ptr;
46 }
47
48 template <> void derefGPtr(GVariant* ptr)
49 {
50     g_variant_unref(ptr);
51 }
52
53 #else
54
55 // We do this so that we can avoid including the glib.h header in GRefPtr.h.
56 typedef struct _GVariant {
57     bool fake;
58 } GVariant; 
59
60 template <> GVariant* refGPtr(GVariant* ptr)
61 {
62     return ptr;
63 }
64
65 template <> void derefGPtr(GVariant* ptr)
66 {
67 }
68
69 #endif
70
71 template <> GSource* refGPtr(GSource* ptr)
72 {
73     if (ptr)
74         g_source_ref(ptr);
75     return ptr;
76 }
77
78 template <> void derefGPtr(GSource* ptr)
79 {
80     if (ptr)
81         g_source_unref(ptr);
82 }
83
84 } // namespace WTF
85
86 #endif // ENABLE(GLIB_SUPPORT)