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 gobject.c.functions;
29 public  import gobject.c.types;
30 private import gtkd.Loader;
31 
32 
33 /**
34  * An opaque structure used as the base of all classes.
35  */
36 public class TypeClass
37 {
38 	/** the main Gtk struct */
39 	protected GTypeClass* gTypeClass;
40 	protected bool ownedRef;
41 
42 	/** Get the main Gtk struct */
43 	public GTypeClass* getTypeClassStruct(bool transferOwnership = false)
44 	{
45 		if (transferOwnership)
46 			ownedRef = false;
47 		return gTypeClass;
48 	}
49 
50 	/** the main Gtk struct as a void* */
51 	protected void* getStruct()
52 	{
53 		return cast(void*)gTypeClass;
54 	}
55 
56 	/**
57 	 * Sets our main struct and passes it to the parent class.
58 	 */
59 	public this (GTypeClass* gTypeClass, bool ownedRef = false)
60 	{
61 		this.gTypeClass = gTypeClass;
62 		this.ownedRef = ownedRef;
63 	}
64 
65 	~this ()
66 	{
67 		if ( Linker.isLoaded(LIBRARY_GOBJECT) && ownedRef )
68 			g_type_class_unref(gTypeClass);
69 	}
70 
71 
72 	/**
73 	 * Registers a private structure for an instantiatable type.
74 	 *
75 	 * When an object is allocated, the private structures for
76 	 * the type and all of its parent types are allocated
77 	 * sequentially in the same memory block as the public
78 	 * structures, and are zero-filled.
79 	 *
80 	 * Note that the accumulated size of the private structures of
81 	 * a type and all its parent types cannot exceed 64 KiB.
82 	 *
83 	 * This function should be called in the type's class_init() function.
84 	 * The private structure can be retrieved using the
85 	 * G_TYPE_INSTANCE_GET_PRIVATE() macro.
86 	 *
87 	 * The following example shows attaching a private structure
88 	 * MyObjectPrivate to an object MyObject defined in the standard
89 	 * GObject fashion in the type's class_init() function.
90 	 *
91 	 * Note the use of a structure member "priv" to avoid the overhead
92 	 * of repeatedly calling MY_OBJECT_GET_PRIVATE().
93 	 *
94 	 * |[<!-- language="C" -->
95 	 * typedef struct _MyObject        MyObject;
96 	 * typedef struct _MyObjectPrivate MyObjectPrivate;
97 	 *
98 	 * struct _MyObject {
99 	 * GObject parent;
100 	 *
101 	 * MyObjectPrivate *priv;
102 	 * };
103 	 *
104 	 * struct _MyObjectPrivate {
105 	 * int some_field;
106 	 * };
107 	 *
108 	 * static void
109 	 * my_object_class_init (MyObjectClass *klass)
110 	 * {
111 	 * g_type_class_add_private (klass, sizeof (MyObjectPrivate));
112 	 * }
113 	 *
114 	 * static void
115 	 * my_object_init (MyObject *my_object)
116 	 * {
117 	 * my_object->priv = G_TYPE_INSTANCE_GET_PRIVATE (my_object,
118 	 * MY_TYPE_OBJECT,
119 	 * MyObjectPrivate);
120 	 * // my_object->priv->some_field will be automatically initialised to 0
121 	 * }
122 	 *
123 	 * static int
124 	 * my_object_get_some_field (MyObject *my_object)
125 	 * {
126 	 * MyObjectPrivate *priv;
127 	 *
128 	 * g_return_val_if_fail (MY_IS_OBJECT (my_object), 0);
129 	 *
130 	 * priv = my_object->priv;
131 	 *
132 	 * return priv->some_field;
133 	 * }
134 	 * ]|
135 	 *
136 	 * Deprecated: Use the G_ADD_PRIVATE() macro with the `G_DEFINE_*`
137 	 * family of macros to add instance private data to a type
138 	 *
139 	 * Params:
140 	 *     privateSize = size of private structure
141 	 *
142 	 * Since: 2.4
143 	 */
144 	public void addPrivate(size_t privateSize)
145 	{
146 		g_type_class_add_private(gTypeClass, privateSize);
147 	}
148 
149 	/**
150 	 * Gets the offset of the private data for instances of @g_class.
151 	 *
152 	 * This is how many bytes you should add to the instance pointer of a
153 	 * class in order to get the private data for the type represented by
154 	 * @g_class.
155 	 *
156 	 * You can only call this function after you have registered a private
157 	 * data area for @g_class using g_type_class_add_private().
158 	 *
159 	 * Returns: the offset, in bytes
160 	 *
161 	 * Since: 2.38
162 	 */
163 	public int getInstancePrivateOffset()
164 	{
165 		return g_type_class_get_instance_private_offset(gTypeClass);
166 	}
167 
168 	/** */
169 	public void* getPrivate(GType privateType)
170 	{
171 		return g_type_class_get_private(gTypeClass, privateType);
172 	}
173 
174 	/**
175 	 * This is a convenience function often needed in class initializers.
176 	 * It returns the class structure of the immediate parent type of the
177 	 * class passed in.  Since derived classes hold a reference count on
178 	 * their parent classes as long as they are instantiated, the returned
179 	 * class will always exist.
180 	 *
181 	 * This function is essentially equivalent to:
182 	 * g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class)))
183 	 *
184 	 * Returns: the parent class
185 	 *     of @g_class
186 	 */
187 	public TypeClass peekParent()
188 	{
189 		auto __p = g_type_class_peek_parent(gTypeClass);
190 
191 		if(__p is null)
192 		{
193 			return null;
194 		}
195 
196 		return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) __p);
197 	}
198 
199 	/**
200 	 * Decrements the reference count of the class structure being passed in.
201 	 * Once the last reference count of a class has been released, classes
202 	 * may be finalized by the type system, so further dereferencing of a
203 	 * class pointer after g_type_class_unref() are invalid.
204 	 */
205 	public void unref()
206 	{
207 		g_type_class_unref(gTypeClass);
208 	}
209 
210 	/**
211 	 * A variant of g_type_class_unref() for use in #GTypeClassCacheFunc
212 	 * implementations. It unreferences a class without consulting the chain
213 	 * of #GTypeClassCacheFuncs, avoiding the recursion which would occur
214 	 * otherwise.
215 	 */
216 	public void unrefUncached()
217 	{
218 		g_type_class_unref_uncached(gTypeClass);
219 	}
220 
221 	/** */
222 	public static void adjustPrivateOffset(void* gClass, int* privateSizeOrOffset)
223 	{
224 		g_type_class_adjust_private_offset(gClass, privateSizeOrOffset);
225 	}
226 
227 	/**
228 	 * This function is essentially the same as g_type_class_ref(),
229 	 * except that the classes reference count isn't incremented.
230 	 * As a consequence, this function may return %NULL if the class
231 	 * of the type passed in does not currently exist (hasn't been
232 	 * referenced before).
233 	 *
234 	 * Params:
235 	 *     type = type ID of a classed type
236 	 *
237 	 * Returns: the #GTypeClass
238 	 *     structure for the given type ID or %NULL if the class does not
239 	 *     currently exist
240 	 */
241 	public static TypeClass peek(GType type)
242 	{
243 		auto __p = g_type_class_peek(type);
244 
245 		if(__p is null)
246 		{
247 			return null;
248 		}
249 
250 		return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) __p);
251 	}
252 
253 	/**
254 	 * A more efficient version of g_type_class_peek() which works only for
255 	 * static types.
256 	 *
257 	 * Params:
258 	 *     type = type ID of a classed type
259 	 *
260 	 * Returns: the #GTypeClass
261 	 *     structure for the given type ID or %NULL if the class does not
262 	 *     currently exist or is dynamically loaded
263 	 *
264 	 * Since: 2.4
265 	 */
266 	public static TypeClass peekStatic(GType type)
267 	{
268 		auto __p = g_type_class_peek_static(type);
269 
270 		if(__p is null)
271 		{
272 			return null;
273 		}
274 
275 		return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) __p);
276 	}
277 
278 	alias doref = ref_;
279 	/**
280 	 * Increments the reference count of the class structure belonging to
281 	 * @type. This function will demand-create the class if it doesn't
282 	 * exist already.
283 	 *
284 	 * Params:
285 	 *     type = type ID of a classed type
286 	 *
287 	 * Returns: the #GTypeClass
288 	 *     structure for the given type ID
289 	 */
290 	public static TypeClass ref_(GType type)
291 	{
292 		auto __p = g_type_class_ref(type);
293 
294 		if(__p is null)
295 		{
296 			return null;
297 		}
298 
299 		return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) __p);
300 	}
301 }