1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gobject.TypeClass;
26 
27 private import gobject.ObjectG;
28 private import gtkc.gobject;
29 public  import gtkc.gobjecttypes;
30 
31 
32 /**
33  * An opaque structure used as the base of all classes.
34  */
35 public class TypeClass
36 {
37 	/** the main Gtk struct */
38 	protected GTypeClass* gTypeClass;
39 
40 	/** Get the main Gtk struct */
41 	public GTypeClass* getTypeClassStruct()
42 	{
43 		return gTypeClass;
44 	}
45 
46 	/** the main Gtk struct as a void* */
47 	protected void* getStruct()
48 	{
49 		return cast(void*)gTypeClass;
50 	}
51 
52 	/**
53 	 * Sets our main struct and passes it to the parent class.
54 	 */
55 	public this (GTypeClass* gTypeClass)
56 	{
57 		this.gTypeClass = gTypeClass;
58 	}
59 
60 
61 	/** */
62 	public void* getPrivate(GType privateType)
63 	{
64 		return g_type_class_get_private(gTypeClass, privateType);
65 	}
66 
67 	/**
68 	 * This is a convenience function often needed in class initializers.
69 	 * It returns the class structure of the immediate parent type of the
70 	 * class passed in.  Since derived classes hold a reference count on
71 	 * their parent classes as long as they are instantiated, the returned
72 	 * class will always exist.
73 	 *
74 	 * This function is essentially equivalent to:
75 	 * g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)))
76 	 *
77 	 * Return: the parent class
78 	 *     of @g_class
79 	 */
80 	public TypeClass peekParent()
81 	{
82 		auto p = g_type_class_peek_parent(gTypeClass);
83 		
84 		if(p is null)
85 		{
86 			return null;
87 		}
88 		
89 		return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) p);
90 	}
91 
92 	/**
93 	 * Decrements the reference count of the class structure being passed in.
94 	 * Once the last reference count of a class has been released, classes
95 	 * may be finalized by the type system, so further dereferencing of a
96 	 * class pointer after g_type_class_unref() are invalid.
97 	 */
98 	public void unref()
99 	{
100 		g_type_class_unref(gTypeClass);
101 	}
102 
103 	/**
104 	 * A variant of g_type_class_unref() for use in #GTypeClassCacheFunc
105 	 * implementations. It unreferences a class without consulting the chain
106 	 * of #GTypeClassCacheFuncs, avoiding the recursion which would occur
107 	 * otherwise.
108 	 */
109 	public void unrefUncached()
110 	{
111 		g_type_class_unref_uncached(gTypeClass);
112 	}
113 
114 	/**
115 	 * Registers a private structure for an instantiatable type.
116 	 *
117 	 * When an object is allocated, the private structures for
118 	 * the type and all of its parent types are allocated
119 	 * sequentially in the same memory block as the public
120 	 * structures, and are zero-filled.
121 	 *
122 	 * Note that the accumulated size of the private structures of
123 	 * a type and all its parent types cannot exceed 64 KiB.
124 	 *
125 	 * This function should be called in the type's class_init() function.
126 	 * The private structure can be retrieved using the
127 	 * G_TYPE_INSTANCE_GET_PRIVATE() macro.
128 	 *
129 	 * The following example shows attaching a private structure
130 	 * MyObjectPrivate to an object MyObject defined in the standard
131 	 * GObject fashion in the type's class_init() function.
132 	 *
133 	 * Note the use of a structure member "priv" to avoid the overhead
134 	 * of repeatedly calling MY_OBJECT_GET_PRIVATE().
135 	 *
136 	 * |[<!-- language="C" -->
137 	 * typedef struct _MyObject        MyObject;
138 	 * typedef struct _MyObjectPrivate MyObjectPrivate;
139 	 *
140 	 * struct _MyObject {
141 	 * GObject parent;
142 	 *
143 	 * MyObjectPrivate *priv;
144 	 * };
145 	 *
146 	 * struct _MyObjectPrivate {
147 	 * int some_field;
148 	 * };
149 	 *
150 	 * static void
151 	 * my_object_class_init (MyObjectClass *klass)
152 	 * {
153 	 * g_type_class_add_private (klass, sizeof (MyObjectPrivate));
154 	 * }
155 	 *
156 	 * static void
157 	 * my_object_init (MyObject *my_object)
158 	 * {
159 	 * my_object->priv = G_TYPE_INSTANCE_GET_PRIVATE (my_object,
160 	 * MY_TYPE_OBJECT,
161 	 * MyObjectPrivate);
162 	 * // my_object->priv->some_field will be automatically initialised to 0
163 	 * }
164 	 *
165 	 * static int
166 	 * my_object_get_some_field (MyObject *my_object)
167 	 * {
168 	 * MyObjectPrivate *priv;
169 	 *
170 	 * g_return_val_if_fail (MY_IS_OBJECT (my_object), 0);
171 	 *
172 	 * priv = my_object->priv;
173 	 *
174 	 * return priv->some_field;
175 	 * }
176 	 * ]|
177 	 *
178 	 * Params:
179 	 *     gClass = class structure for an instantiatable type
180 	 *     privateSize = size of private structure
181 	 *
182 	 * Since: 2.4
183 	 */
184 	public static void addPrivate(void* gClass, size_t privateSize)
185 	{
186 		g_type_class_add_private(gClass, privateSize);
187 	}
188 
189 	/** */
190 	public static void adjustPrivateOffset(void* gClass, int* privateSizeOrOffset)
191 	{
192 		g_type_class_adjust_private_offset(gClass, privateSizeOrOffset);
193 	}
194 
195 	/**
196 	 * Gets the offset of the private data for instances of @g_class.
197 	 *
198 	 * This is how many bytes you should add to the instance pointer of a
199 	 * class in order to get the private data for the type represented by
200 	 * @g_class.
201 	 *
202 	 * You can only call this function after you have registered a private
203 	 * data area for @g_class using g_type_class_add_private().
204 	 *
205 	 * Params:
206 	 *     gClass = a #GTypeClass
207 	 *
208 	 * Return: the offset, in bytes
209 	 *
210 	 * Since: 2.38
211 	 */
212 	public static int getInstancePrivateOffset(void* gClass)
213 	{
214 		return g_type_class_get_instance_private_offset(gClass);
215 	}
216 
217 	/**
218 	 * This function is essentially the same as g_type_class_ref(),
219 	 * except that the classes reference count isn't incremented.
220 	 * As a consequence, this function may return %NULL if the class
221 	 * of the type passed in does not currently exist (hasn't been
222 	 * referenced before).
223 	 *
224 	 * Params:
225 	 *     type = type ID of a classed type
226 	 *
227 	 * Return: the #GTypeClass
228 	 *     structure for the given type ID or %NULL if the class does not
229 	 *     currently exist
230 	 */
231 	public static TypeClass peek(GType type)
232 	{
233 		auto p = g_type_class_peek(type);
234 		
235 		if(p is null)
236 		{
237 			return null;
238 		}
239 		
240 		return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) p);
241 	}
242 
243 	/**
244 	 * A more efficient version of g_type_class_peek() which works only for
245 	 * static types.
246 	 *
247 	 * Params:
248 	 *     type = type ID of a classed type
249 	 *
250 	 * Return: the #GTypeClass
251 	 *     structure for the given type ID or %NULL if the class does not
252 	 *     currently exist or is dynamically loaded
253 	 *
254 	 * Since: 2.4
255 	 */
256 	public static TypeClass peekStatic(GType type)
257 	{
258 		auto p = g_type_class_peek_static(type);
259 		
260 		if(p is null)
261 		{
262 			return null;
263 		}
264 		
265 		return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) p);
266 	}
267 
268 	/**
269 	 * Increments the reference count of the class structure belonging to
270 	 * @type. This function will demand-create the class if it doesn't
271 	 * exist already.
272 	 *
273 	 * Params:
274 	 *     type = type ID of a classed type
275 	 *
276 	 * Return: the #GTypeClass
277 	 *     structure for the given type ID
278 	 */
279 	public static TypeClass doref(GType type)
280 	{
281 		auto p = g_type_class_ref(type);
282 		
283 		if(p is null)
284 		{
285 			return null;
286 		}
287 		
288 		return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) p);
289 	}
290 }