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 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 * Params: 137 * privateSize = size of private structure 138 * 139 * Since: 2.4 140 */ 141 public void addPrivate(size_t privateSize) 142 { 143 g_type_class_add_private(gTypeClass, privateSize); 144 } 145 146 /** 147 * Gets the offset of the private data for instances of @g_class. 148 * 149 * This is how many bytes you should add to the instance pointer of a 150 * class in order to get the private data for the type represented by 151 * @g_class. 152 * 153 * You can only call this function after you have registered a private 154 * data area for @g_class using g_type_class_add_private(). 155 * 156 * Returns: the offset, in bytes 157 * 158 * Since: 2.38 159 */ 160 public int getInstancePrivateOffset() 161 { 162 return g_type_class_get_instance_private_offset(gTypeClass); 163 } 164 165 /** */ 166 public void* getPrivate(GType privateType) 167 { 168 return g_type_class_get_private(gTypeClass, privateType); 169 } 170 171 /** 172 * This is a convenience function often needed in class initializers. 173 * It returns the class structure of the immediate parent type of the 174 * class passed in. Since derived classes hold a reference count on 175 * their parent classes as long as they are instantiated, the returned 176 * class will always exist. 177 * 178 * This function is essentially equivalent to: 179 * g_type_class_peek (g_type_parent (G_TYPE_FROM_CLASS (g_class))) 180 * 181 * Returns: the parent class 182 * of @g_class 183 */ 184 public TypeClass peekParent() 185 { 186 auto p = g_type_class_peek_parent(gTypeClass); 187 188 if(p is null) 189 { 190 return null; 191 } 192 193 return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) p); 194 } 195 196 /** 197 * Decrements the reference count of the class structure being passed in. 198 * Once the last reference count of a class has been released, classes 199 * may be finalized by the type system, so further dereferencing of a 200 * class pointer after g_type_class_unref() are invalid. 201 */ 202 public void unref() 203 { 204 g_type_class_unref(gTypeClass); 205 } 206 207 /** 208 * A variant of g_type_class_unref() for use in #GTypeClassCacheFunc 209 * implementations. It unreferences a class without consulting the chain 210 * of #GTypeClassCacheFuncs, avoiding the recursion which would occur 211 * otherwise. 212 */ 213 public void unrefUncached() 214 { 215 g_type_class_unref_uncached(gTypeClass); 216 } 217 218 /** */ 219 public static void adjustPrivateOffset(void* gClass, int* privateSizeOrOffset) 220 { 221 g_type_class_adjust_private_offset(gClass, privateSizeOrOffset); 222 } 223 224 /** 225 * This function is essentially the same as g_type_class_ref(), 226 * except that the classes reference count isn't incremented. 227 * As a consequence, this function may return %NULL if the class 228 * of the type passed in does not currently exist (hasn't been 229 * referenced before). 230 * 231 * Params: 232 * type = type ID of a classed type 233 * 234 * Returns: the #GTypeClass 235 * structure for the given type ID or %NULL if the class does not 236 * currently exist 237 */ 238 public static TypeClass peek(GType type) 239 { 240 auto p = g_type_class_peek(type); 241 242 if(p is null) 243 { 244 return null; 245 } 246 247 return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) p); 248 } 249 250 /** 251 * A more efficient version of g_type_class_peek() which works only for 252 * static types. 253 * 254 * Params: 255 * type = type ID of a classed type 256 * 257 * Returns: the #GTypeClass 258 * structure for the given type ID or %NULL if the class does not 259 * currently exist or is dynamically loaded 260 * 261 * Since: 2.4 262 */ 263 public static TypeClass peekStatic(GType type) 264 { 265 auto p = g_type_class_peek_static(type); 266 267 if(p is null) 268 { 269 return null; 270 } 271 272 return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) p); 273 } 274 275 /** 276 * Increments the reference count of the class structure belonging to 277 * @type. This function will demand-create the class if it doesn't 278 * exist already. 279 * 280 * Params: 281 * type = type ID of a classed type 282 * 283 * Returns: the #GTypeClass 284 * structure for the given type ID 285 */ 286 public static TypeClass doref(GType type) 287 { 288 auto p = g_type_class_ref(type); 289 290 if(p is null) 291 { 292 return null; 293 } 294 295 return ObjectG.getDObject!(TypeClass)(cast(GTypeClass*) p); 296 } 297 }