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