1 /* valacomment.c generated by valac, the Vala compiler
2  * generated from valacomment.vala, do not modify */
3 
4 /* valacomment.vala
5  *
6  * Copyright (C) 2008-2009  Florian Brosch
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
21  *
22  * Author:
23  * 	Florian Brosch <flo.brosch@gmail.com>
24  */
25 
26 #include "vala.h"
27 #include <stdlib.h>
28 #include <string.h>
29 #include <glib.h>
30 #include <gobject/gvaluecollector.h>
31 
32 #define _g_free0(var) (var = (g_free (var), NULL))
33 #define _vala_source_reference_unref0(var) ((var == NULL) ? NULL : (var = (vala_source_reference_unref (var), NULL)))
34 typedef struct _ValaParamSpecComment ValaParamSpecComment;
35 
36 struct _ValaCommentPrivate {
37 	gchar* _content;
38 	ValaSourceReference* _source_reference;
39 };
40 
41 struct _ValaParamSpecComment {
42 	GParamSpec parent_instance;
43 };
44 
45 static gint ValaComment_private_offset;
46 static gpointer vala_comment_parent_class = NULL;
47 
48 static void vala_comment_finalize (ValaComment * obj);
49 static GType vala_comment_get_type_once (void);
50 
51 static inline gpointer
vala_comment_get_instance_private(ValaComment * self)52 vala_comment_get_instance_private (ValaComment* self)
53 {
54 	return G_STRUCT_MEMBER_P (self, ValaComment_private_offset);
55 }
56 
57 ValaComment*
vala_comment_construct(GType object_type,const gchar * comment,ValaSourceReference * _source_reference)58 vala_comment_construct (GType object_type,
59                         const gchar* comment,
60                         ValaSourceReference* _source_reference)
61 {
62 	ValaComment* self = NULL;
63 	g_return_val_if_fail (comment != NULL, NULL);
64 	g_return_val_if_fail (_source_reference != NULL, NULL);
65 	self = (ValaComment*) g_type_create_instance (object_type);
66 	vala_comment_set_source_reference (self, _source_reference);
67 	vala_comment_set_content (self, comment);
68 	return self;
69 }
70 
71 ValaComment*
vala_comment_new(const gchar * comment,ValaSourceReference * _source_reference)72 vala_comment_new (const gchar* comment,
73                   ValaSourceReference* _source_reference)
74 {
75 	return vala_comment_construct (VALA_TYPE_COMMENT, comment, _source_reference);
76 }
77 
78 const gchar*
vala_comment_get_content(ValaComment * self)79 vala_comment_get_content (ValaComment* self)
80 {
81 	const gchar* result;
82 	const gchar* _tmp0_;
83 	g_return_val_if_fail (self != NULL, NULL);
84 	_tmp0_ = self->priv->_content;
85 	result = _tmp0_;
86 	return result;
87 }
88 
89 void
vala_comment_set_content(ValaComment * self,const gchar * value)90 vala_comment_set_content (ValaComment* self,
91                           const gchar* value)
92 {
93 	gchar* _tmp0_;
94 	g_return_if_fail (self != NULL);
95 	_tmp0_ = g_strdup (value);
96 	_g_free0 (self->priv->_content);
97 	self->priv->_content = _tmp0_;
98 }
99 
100 ValaSourceReference*
vala_comment_get_source_reference(ValaComment * self)101 vala_comment_get_source_reference (ValaComment* self)
102 {
103 	ValaSourceReference* result;
104 	ValaSourceReference* _tmp0_;
105 	g_return_val_if_fail (self != NULL, NULL);
106 	_tmp0_ = self->priv->_source_reference;
107 	result = _tmp0_;
108 	return result;
109 }
110 
111 static gpointer
_vala_source_reference_ref0(gpointer self)112 _vala_source_reference_ref0 (gpointer self)
113 {
114 	return self ? vala_source_reference_ref (self) : NULL;
115 }
116 
117 void
vala_comment_set_source_reference(ValaComment * self,ValaSourceReference * value)118 vala_comment_set_source_reference (ValaComment* self,
119                                    ValaSourceReference* value)
120 {
121 	ValaSourceReference* _tmp0_;
122 	g_return_if_fail (self != NULL);
123 	_tmp0_ = _vala_source_reference_ref0 (value);
124 	_vala_source_reference_unref0 (self->priv->_source_reference);
125 	self->priv->_source_reference = _tmp0_;
126 }
127 
128 static void
vala_value_comment_init(GValue * value)129 vala_value_comment_init (GValue* value)
130 {
131 	value->data[0].v_pointer = NULL;
132 }
133 
134 static void
vala_value_comment_free_value(GValue * value)135 vala_value_comment_free_value (GValue* value)
136 {
137 	if (value->data[0].v_pointer) {
138 		vala_comment_unref (value->data[0].v_pointer);
139 	}
140 }
141 
142 static void
vala_value_comment_copy_value(const GValue * src_value,GValue * dest_value)143 vala_value_comment_copy_value (const GValue* src_value,
144                                GValue* dest_value)
145 {
146 	if (src_value->data[0].v_pointer) {
147 		dest_value->data[0].v_pointer = vala_comment_ref (src_value->data[0].v_pointer);
148 	} else {
149 		dest_value->data[0].v_pointer = NULL;
150 	}
151 }
152 
153 static gpointer
vala_value_comment_peek_pointer(const GValue * value)154 vala_value_comment_peek_pointer (const GValue* value)
155 {
156 	return value->data[0].v_pointer;
157 }
158 
159 static gchar*
vala_value_comment_collect_value(GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)160 vala_value_comment_collect_value (GValue* value,
161                                   guint n_collect_values,
162                                   GTypeCValue* collect_values,
163                                   guint collect_flags)
164 {
165 	if (collect_values[0].v_pointer) {
166 		ValaComment * object;
167 		object = collect_values[0].v_pointer;
168 		if (object->parent_instance.g_class == NULL) {
169 			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
170 		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
171 			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
172 		}
173 		value->data[0].v_pointer = vala_comment_ref (object);
174 	} else {
175 		value->data[0].v_pointer = NULL;
176 	}
177 	return NULL;
178 }
179 
180 static gchar*
vala_value_comment_lcopy_value(const GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)181 vala_value_comment_lcopy_value (const GValue* value,
182                                 guint n_collect_values,
183                                 GTypeCValue* collect_values,
184                                 guint collect_flags)
185 {
186 	ValaComment ** object_p;
187 	object_p = collect_values[0].v_pointer;
188 	if (!object_p) {
189 		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
190 	}
191 	if (!value->data[0].v_pointer) {
192 		*object_p = NULL;
193 	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
194 		*object_p = value->data[0].v_pointer;
195 	} else {
196 		*object_p = vala_comment_ref (value->data[0].v_pointer);
197 	}
198 	return NULL;
199 }
200 
201 GParamSpec*
vala_param_spec_comment(const gchar * name,const gchar * nick,const gchar * blurb,GType object_type,GParamFlags flags)202 vala_param_spec_comment (const gchar* name,
203                          const gchar* nick,
204                          const gchar* blurb,
205                          GType object_type,
206                          GParamFlags flags)
207 {
208 	ValaParamSpecComment* spec;
209 	g_return_val_if_fail (g_type_is_a (object_type, VALA_TYPE_COMMENT), NULL);
210 	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
211 	G_PARAM_SPEC (spec)->value_type = object_type;
212 	return G_PARAM_SPEC (spec);
213 }
214 
215 gpointer
vala_value_get_comment(const GValue * value)216 vala_value_get_comment (const GValue* value)
217 {
218 	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_COMMENT), NULL);
219 	return value->data[0].v_pointer;
220 }
221 
222 void
vala_value_set_comment(GValue * value,gpointer v_object)223 vala_value_set_comment (GValue* value,
224                         gpointer v_object)
225 {
226 	ValaComment * old;
227 	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_COMMENT));
228 	old = value->data[0].v_pointer;
229 	if (v_object) {
230 		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_COMMENT));
231 		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
232 		value->data[0].v_pointer = v_object;
233 		vala_comment_ref (value->data[0].v_pointer);
234 	} else {
235 		value->data[0].v_pointer = NULL;
236 	}
237 	if (old) {
238 		vala_comment_unref (old);
239 	}
240 }
241 
242 void
vala_value_take_comment(GValue * value,gpointer v_object)243 vala_value_take_comment (GValue* value,
244                          gpointer v_object)
245 {
246 	ValaComment * old;
247 	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_COMMENT));
248 	old = value->data[0].v_pointer;
249 	if (v_object) {
250 		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_COMMENT));
251 		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
252 		value->data[0].v_pointer = v_object;
253 	} else {
254 		value->data[0].v_pointer = NULL;
255 	}
256 	if (old) {
257 		vala_comment_unref (old);
258 	}
259 }
260 
261 static void
vala_comment_class_init(ValaCommentClass * klass,gpointer klass_data)262 vala_comment_class_init (ValaCommentClass * klass,
263                          gpointer klass_data)
264 {
265 	vala_comment_parent_class = g_type_class_peek_parent (klass);
266 	((ValaCommentClass *) klass)->finalize = vala_comment_finalize;
267 	g_type_class_adjust_private_offset (klass, &ValaComment_private_offset);
268 }
269 
270 static void
vala_comment_instance_init(ValaComment * self,gpointer klass)271 vala_comment_instance_init (ValaComment * self,
272                             gpointer klass)
273 {
274 	self->priv = vala_comment_get_instance_private (self);
275 	self->ref_count = 1;
276 }
277 
278 static void
vala_comment_finalize(ValaComment * obj)279 vala_comment_finalize (ValaComment * obj)
280 {
281 	ValaComment * self;
282 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_COMMENT, ValaComment);
283 	g_signal_handlers_destroy (self);
284 	_g_free0 (self->priv->_content);
285 	_vala_source_reference_unref0 (self->priv->_source_reference);
286 }
287 
288 /**
289  * A documentation comment used by valadoc
290  */
291 static GType
vala_comment_get_type_once(void)292 vala_comment_get_type_once (void)
293 {
294 	static const GTypeValueTable g_define_type_value_table = { vala_value_comment_init, vala_value_comment_free_value, vala_value_comment_copy_value, vala_value_comment_peek_pointer, "p", vala_value_comment_collect_value, "p", vala_value_comment_lcopy_value };
295 	static const GTypeInfo g_define_type_info = { sizeof (ValaCommentClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_comment_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaComment), 0, (GInstanceInitFunc) vala_comment_instance_init, &g_define_type_value_table };
296 	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
297 	GType vala_comment_type_id;
298 	vala_comment_type_id = g_type_register_fundamental (g_type_fundamental_next (), "ValaComment", &g_define_type_info, &g_define_type_fundamental_info, 0);
299 	ValaComment_private_offset = g_type_add_instance_private (vala_comment_type_id, sizeof (ValaCommentPrivate));
300 	return vala_comment_type_id;
301 }
302 
303 GType
vala_comment_get_type(void)304 vala_comment_get_type (void)
305 {
306 	static volatile gsize vala_comment_type_id__volatile = 0;
307 	if (g_once_init_enter (&vala_comment_type_id__volatile)) {
308 		GType vala_comment_type_id;
309 		vala_comment_type_id = vala_comment_get_type_once ();
310 		g_once_init_leave (&vala_comment_type_id__volatile, vala_comment_type_id);
311 	}
312 	return vala_comment_type_id__volatile;
313 }
314 
315 gpointer
vala_comment_ref(gpointer instance)316 vala_comment_ref (gpointer instance)
317 {
318 	ValaComment * self;
319 	self = instance;
320 	g_atomic_int_inc (&self->ref_count);
321 	return instance;
322 }
323 
324 void
vala_comment_unref(gpointer instance)325 vala_comment_unref (gpointer instance)
326 {
327 	ValaComment * self;
328 	self = instance;
329 	if (g_atomic_int_dec_and_test (&self->ref_count)) {
330 		VALA_COMMENT_GET_CLASS (self)->finalize (self);
331 		g_type_free_instance ((GTypeInstance *) self);
332 	}
333 }
334 
335