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