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 * Conversion parameters: 26 * inFile = 27 * outPack = gobject 28 * outFile = WeakRef 29 * strct = GWeakRef 30 * realStrct= 31 * ctorStrct= 32 * clss = WeakRef 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_weak_ref_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * - notify 46 * imports: 47 * structWrap: 48 * module aliases: 49 * local aliases: 50 * overrides: 51 */ 52 53 module gobject.WeakRef; 54 55 public import gtkc.gobjecttypes; 56 57 private import gtkc.gobject; 58 private import glib.ConstructionException; 59 private import gobject.ObjectG; 60 61 private import gobject.Signals; 62 public import gtkc.gdktypes; 63 64 65 66 67 68 /** 69 * GObject is the fundamental type providing the common attributes and 70 * methods for all object types in GTK+, Pango and other libraries 71 * based on GObject. The GObject class provides methods for object 72 * construction and destruction, property access methods, and signal 73 * support. Signals are described in detail in Signals(3). 74 * 75 * GInitiallyUnowned is derived from GObject. The only difference between 76 * the two is that the initial reference of a GInitiallyUnowned is flagged 77 * as a floating reference. 78 * This means that it is not specifically claimed to be "owned" by 79 * any code portion. The main motivation for providing floating references is 80 * C convenience. In particular, it allows code to be written as: 81 * 82 * $(DDOC_COMMENT example) 83 * 84 * If container_add_child() will g_object_ref_sink() the 85 * passed in child, no reference of the newly created child is leaked. 86 * Without floating references, container_add_child() 87 * can only g_object_ref() the new child, so to implement this code without 88 * reference leaks, it would have to be written as: 89 * 90 * $(DDOC_COMMENT example) 91 * 92 * The floating reference can be converted into 93 * an ordinary reference by calling g_object_ref_sink(). 94 * For already sunken objects (objects that don't have a floating reference 95 * anymore), g_object_ref_sink() is equivalent to g_object_ref() and returns 96 * a new reference. 97 * Since floating references are useful almost exclusively for C convenience, 98 * language bindings that provide automated reference and memory ownership 99 * maintenance (such as smart pointers or garbage collection) should not 100 * expose floating references in their API. 101 * 102 * Some object implementations may need to save an objects floating state 103 * across certain code portions (an example is GtkMenu), to achieve this, 104 * the following sequence can be used: 105 * 106 * $(DDOC_COMMENT example) 107 */ 108 public class WeakRef 109 { 110 111 /** the main Gtk struct */ 112 protected GWeakRef* gWeakRef; 113 114 115 public GWeakRef* getWeakRefStruct() 116 { 117 return gWeakRef; 118 } 119 120 121 /** the main Gtk struct as a void* */ 122 protected void* getStruct() 123 { 124 return cast(void*)gWeakRef; 125 } 126 127 /** 128 * Sets our main struct and passes it to the parent class 129 */ 130 public this (GWeakRef* gWeakRef) 131 { 132 this.gWeakRef = gWeakRef; 133 } 134 135 /** */ 136 this(void* object) 137 { 138 g_weak_ref_init(gWeakRef, object); 139 } 140 141 /** 142 */ 143 144 /** 145 * Initialise a non-statically-allocated GWeakRef. 146 * This function also calls g_weak_ref_set() with object on the 147 * freshly-initialised weak reference. 148 * This function should always be matched with a call to 149 * g_weak_ref_clear(). It is not necessary to use this function for a 150 * GWeakRef in static storage because it will already be 151 * properly initialised. Just use g_weak_ref_set() directly. 152 * Since 2.32 153 * Params: 154 * object = a GObject or NULL. [allow-none] 155 */ 156 public void init(void* object) 157 { 158 // void g_weak_ref_init (GWeakRef *weak_ref, gpointer object); 159 g_weak_ref_init(gWeakRef, object); 160 } 161 162 /** 163 * Frees resources associated with a non-statically-allocated GWeakRef. 164 * After this call, the GWeakRef is left in an undefined state. 165 * You should only call this on a GWeakRef that previously had 166 * g_weak_ref_init() called on it. 167 * Since 2.32 168 */ 169 public void clear() 170 { 171 // void g_weak_ref_clear (GWeakRef *weak_ref); 172 g_weak_ref_clear(gWeakRef); 173 } 174 175 /** 176 * If weak_ref is not empty, atomically acquire a strong 177 * reference to the object it points to, and return that reference. 178 * This function is needed because of the potential race between taking 179 * the pointer value and g_object_ref() on it, if the object was losing 180 * its last reference at the same time in a different thread. 181 * The caller should release the resulting reference in the usual way, 182 * by using g_object_unref(). 183 * Since 2.32 184 * Returns: the object pointed to by weak_ref, or NULL if it was empty. [transfer full][type GObject.Object] 185 */ 186 public void* get() 187 { 188 // gpointer g_weak_ref_get (GWeakRef *weak_ref); 189 return g_weak_ref_get(gWeakRef); 190 } 191 192 /** 193 * Change the object to which weak_ref points, or set it to 194 * NULL. 195 * You must own a strong reference on object while calling this 196 * function. 197 * Since 2.32 198 * Signal Details 199 * The "notify" signal 200 * void user_function (GObject *gobject, 201 * GParamSpec *pspec, 202 * gpointer user_data) : No Hooks 203 * The notify signal is emitted on an object when one of its 204 * properties has been changed. Note that getting this signal 205 * doesn't guarantee that the value of the property has actually 206 * changed, it may also be emitted when the setter for the property 207 * is called to reinstate the previous value. 208 * This signal is typically used to obtain change notification for a 209 * single property, by specifying the property name as a detail in the 210 * Params: 211 * object = a GObject or NULL. [allow-none] 212 */ 213 public void set(void* object) 214 { 215 // void g_weak_ref_set (GWeakRef *weak_ref, gpointer object); 216 g_weak_ref_set(gWeakRef, object); 217 } 218 }