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 
63 	public void* getPrivate(GType privateType)
64 	{
65 		return g_type_class_get_private(gTypeClass, privateType);
66 	}
67 
68 	/**
69 	 * This is a convenience function often needed in class initializers.
70 	 * It returns the class structure of the immediate parent type of the
71 	 * class passed in.  Since derived classes hold a reference count on
72 	 * their parent classes as long as they are instantiated, the returned
73 	 * class will always exist.
74 	 *
75 	 * This function is essentially equivalent to:
76 	 * g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)))
77 	 *
78 	 * Return: the parent class
79 	 *     of @g_class
80 	 */
81 	public TypeClass peekParent()
82 	{
83 		auto p = g_type_class_peek_parent(gTypeClass);
84 		
85 		if(p is null)
86 		{
87 			return null;
88 		}
89 		
90 		return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) p);
91 	}
92 
93 	/**
94 	 * Decrements the reference count of the class structure being passed in.
95 	 * Once the last reference count of a class has been released, classes
96 	 * may be finalized by the type system, so further dereferencing of a
97 	 * class pointer after g_type_class_unref() are invalid.
98 	 */
99 	public void unref()
100 	{
101 		g_type_class_unref(gTypeClass);
102 	}
103 
104 	/**
105 	 * A variant of g_type_class_unref() for use in #GTypeClassCacheFunc
106 	 * implementations. It unreferences a class without consulting the chain
107 	 * of #GTypeClassCacheFuncs, avoiding the recursion which would occur
108 	 * otherwise.
109 	 */
110 	public void unrefUncached()
111 	{
112 		g_type_class_unref_uncached(gTypeClass);
113 	}
114 
115 	/**
116 	 * Registers a private structure for an instantiatable type.
117 	 *
118 	 * When an object is allocated, the private structures for
119 	 * the type and all of its parent types are allocated
120 	 * sequentially in the same memory block as the public
121 	 * structures, and are zero-filled.
122 	 *
123 	 * Note that the accumulated size of the private structures of
124 	 * a type and all its parent types cannot exceed 64 KiB.
125 	 *
126 	 * This function should be called in the type's class_init() function.
127 	 * The private structure can be retrieved using the
128 	 * G_TYPE_INSTANCE_GET_PRIVATE() macro.
129 	 *
130 	 * The following example shows attaching a private structure
131 	 * MyObjectPrivate to an object MyObject defined in the standard
132 	 * GObject fashion in the type's class_init() function.
133 	 *
134 	 * Note the use of a structure member "priv" to avoid the overhead
135 	 * of repeatedly calling MY_OBJECT_GET_PRIVATE().
136 	 *
137 	 * |[<!-- language="C" -->
138 	 * typedef struct _MyObject        MyObject;
139 	 * typedef struct _MyObjectPrivate MyObjectPrivate;
140 	 *
141 	 * struct _MyObject {
142 	 * GObject parent;
143 	 *
144 	 * MyObjectPrivate *priv;
145 	 * };
146 	 *
147 	 * struct _MyObjectPrivate {
148 	 * int some_field;
149 	 * };
150 	 *
151 	 * static void
152 	 * my_object_class_init (MyObjectClass *klass)
153 	 * {
154 	 * g_type_class_add_private (klass, sizeof (MyObjectPrivate));
155 	 * }
156 	 *
157 	 * static void
158 	 * my_object_init (MyObject *my_object)
159 	 * {
160 	 * my_object->priv = G_TYPE_INSTANCE_GET_PRIVATE (my_object,
161 	 * MY_TYPE_OBJECT,
162 	 * MyObjectPrivate);
163 	 * // my_object->priv->some_field will be automatically initialised to 0
164 	 * }
165 	 *
166 	 * static int
167 	 * my_object_get_some_field (MyObject *my_object)
168 	 * {
169 	 * MyObjectPrivate *priv;
170 	 *
171 	 * g_return_val_if_fail (MY_IS_OBJECT (my_object), 0);
172 	 *
173 	 * priv = my_object->priv;
174 	 *
175 	 * return priv->some_field;
176 	 * }
177 	 * ]|
178 	 *
179 	 * Params:
180 	 *     gClass = class structure for an instantiatable type
181 	 *     privateSize = size of private structure
182 	 *
183 	 * Since: 2.4
184 	 */
185 	public static void addPrivate(void* gClass, size_t privateSize)
186 	{
187 		g_type_class_add_private(gClass, privateSize);
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 }