source: appstream-generator/build/girepo/gobject/TypeClass.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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