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