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