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 <wtf/glib/GRefPtr.h>
21
22#if USE(GLIB)
23
24#include <glib-object.h>
25#include <glib.h>
26
27namespace WTF {
28
29template <> GHashTable* refGPtr(GHashTable* ptr)
30{
31 if (ptr)
32 g_hash_table_ref(ptr);
33 return ptr;
34}
35
36template <> void derefGPtr(GHashTable* ptr)
37{
38 if (ptr)
39 g_hash_table_unref(ptr);
40}
41
42template <> GMainContext* refGPtr(GMainContext* ptr)
43{
44 if (ptr)
45 g_main_context_ref(ptr);
46 return ptr;
47}
48
49template <> void derefGPtr(GMainContext* ptr)
50{
51 if (ptr)
52 g_main_context_unref(ptr);
53}
54
55template <> GMainLoop* refGPtr(GMainLoop* ptr)
56{
57 if (ptr)
58 g_main_loop_ref(ptr);
59 return ptr;
60}
61
62template <> void derefGPtr(GMainLoop* ptr)
63{
64 if (ptr)
65 g_main_loop_unref(ptr);
66}
67
68template <> GBytes* refGPtr(GBytes* ptr)
69{
70 if (ptr)
71 g_bytes_ref(ptr);
72 return ptr;
73}
74
75template <> void derefGPtr(GBytes* ptr)
76{
77 if (ptr)
78 g_bytes_unref(ptr);
79}
80
81template <> GVariant* refGPtr(GVariant* ptr)
82{
83 if (ptr)
84 g_variant_ref_sink(ptr);
85 return ptr;
86}
87
88template <> void derefGPtr(GVariant* ptr)
89{
90 if (ptr)
91 g_variant_unref(ptr);
92}
93
94template <> GVariantBuilder* refGPtr(GVariantBuilder* ptr)
95{
96 if (ptr)
97 g_variant_builder_ref(ptr);
98 return ptr;
99}
100
101template <> void derefGPtr(GVariantBuilder* ptr)
102{
103 if (ptr)
104 g_variant_builder_unref(ptr);
105}
106
107template <> GSource* refGPtr(GSource* ptr)
108{
109 if (ptr)
110 g_source_ref(ptr);
111 return ptr;
112}
113
114template <> void derefGPtr(GSource* ptr)
115{
116 if (ptr)
117 g_source_unref(ptr);
118}
119
120template <> GPtrArray* refGPtr(GPtrArray* ptr)
121{
122 if (ptr)
123 g_ptr_array_ref(ptr);
124 return ptr;
125}
126
127template <> void derefGPtr(GPtrArray* ptr)
128{
129 if (ptr)
130 g_ptr_array_unref(ptr);
131}
132
133template <> GByteArray* refGPtr(GByteArray* ptr)
134{
135 if (ptr)
136 g_byte_array_ref(ptr);
137 return ptr;
138}
139
140template <> void derefGPtr(GByteArray* ptr)
141{
142 if (ptr)
143 g_byte_array_unref(ptr);
144}
145
146template <> GClosure* refGPtr(GClosure* ptr)
147{
148 if (ptr)
149 g_closure_ref(ptr);
150 return ptr;
151}
152
153template <> void derefGPtr(GClosure* ptr)
154{
155 if (ptr)
156 g_closure_unref(ptr);
157}
158
159template <> GRegex* refGPtr(GRegex* ptr)
160{
161 if (ptr)
162 g_regex_ref(ptr);
163 return ptr;
164}
165
166template <> void derefGPtr(GRegex* ptr)
167{
168 if (ptr)
169 g_regex_unref(ptr);
170}
171
172template <> GMappedFile* refGPtr(GMappedFile* ptr)
173{
174 if (ptr)
175 g_mapped_file_ref(ptr);
176 return ptr;
177}
178
179template <> void derefGPtr(GMappedFile* ptr)
180{
181 if (ptr)
182 g_mapped_file_unref(ptr);
183}
184
185} // namespace WTF
186
187#endif // USE(GLIB)
188