source: appstream-generator/build/girepo/gobject/WeakRef.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 4.4 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gobject.WeakRef;
22
23private import gi.gobject;
24public  import gi.gobjecttypes;
25private import gobject.ObjectG;
26
27
28/**
29 * A structure containing a weak reference to a #GObject.  It can either
30 * be empty (i.e. point to %NULL), or point to an object for as long as
31 * at least one "strong" reference to that object exists. Before the
32 * object's #GObjectClass.dispose method is called, every #GWeakRef
33 * associated with becomes empty (i.e. points to %NULL).
34 *
35 * Like #GValue, #GWeakRef can be statically allocated, stack- or
36 * heap-allocated, or embedded in larger structures.
37 *
38 * Unlike g_object_weak_ref() and g_object_add_weak_pointer(), this weak
39 * reference is thread-safe: converting a weak pointer to a reference is
40 * atomic with respect to invalidation of weak pointers to destroyed
41 * objects.
42 *
43 * If the object's #GObjectClass.dispose method results in additional
44 * references to the object being held, any #GWeakRefs taken
45 * before it was disposed will continue to point to %NULL.  If
46 * #GWeakRefs are taken after the object is disposed and
47 * re-referenced, they will continue to point to it until its refcount
48 * goes back to zero, at which point they too will be invalidated.
49 */
50public class WeakRef
51{
52        /** the main Gtk struct */
53        protected GWeakRef* gWeakRef;
54        protected bool ownedRef;
55
56        /** Get the main Gtk struct */
57        public GWeakRef* getWeakRefStruct()
58        {
59                return gWeakRef;
60        }
61
62        /** the main Gtk struct as a void* */
63        protected void* getStruct()
64        {
65                return cast(void*)gWeakRef;
66        }
67
68        /**
69         * Sets our main struct and passes it to the parent class.
70         */
71        public this (GWeakRef* gWeakRef, bool ownedRef = false)
72        {
73                this.gWeakRef = gWeakRef;
74                this.ownedRef = ownedRef;
75        }
76
77        /** */
78        this(void* object)
79        {
80                g_weak_ref_init(gWeakRef, object);
81        }
82
83        /**
84         */
85
86        /**
87         * Frees resources associated with a non-statically-allocated #GWeakRef.
88         * After this call, the #GWeakRef is left in an undefined state.
89         *
90         * You should only call this on a #GWeakRef that previously had
91         * g_weak_ref_init() called on it.
92         *
93         * Since: 2.32
94         */
95        public void clear()
96        {
97                g_weak_ref_clear(gWeakRef);
98        }
99
100        /**
101         * If @weak_ref is not empty, atomically acquire a strong
102         * reference to the object it points to, and return that reference.
103         *
104         * This function is needed because of the potential race between taking
105         * the pointer value and g_object_ref() on it, if the object was losing
106         * its last reference at the same time in a different thread.
107         *
108         * The caller should release the resulting reference in the usual way,
109         * by using g_object_unref().
110         *
111         * Returns: the object pointed to
112         *     by @weak_ref, or %NULL if it was empty
113         *
114         * Since: 2.32
115         */
116        public ObjectG get()
117        {
118                auto p = g_weak_ref_get(gWeakRef);
119               
120                if(p is null)
121                {
122                        return null;
123                }
124               
125                return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true);
126        }
127
128        /**
129         * Initialise a non-statically-allocated #GWeakRef.
130         *
131         * This function also calls g_weak_ref_set() with @object on the
132         * freshly-initialised weak reference.
133         *
134         * This function should always be matched with a call to
135         * g_weak_ref_clear().  It is not necessary to use this function for a
136         * #GWeakRef in static storage because it will already be
137         * properly initialised.  Just use g_weak_ref_set() directly.
138         *
139         * Params:
140         *     object = a #GObject or %NULL
141         *
142         * Since: 2.32
143         */
144        public void init(void* object)
145        {
146                g_weak_ref_init(gWeakRef, object);
147        }
148
149        /**
150         * Change the object to which @weak_ref points, or set it to
151         * %NULL.
152         *
153         * You must own a strong reference on @object while calling this
154         * function.
155         *
156         * Params:
157         *     object = a #GObject or %NULL
158         *
159         * Since: 2.32
160         */
161        public void set(void* object)
162        {
163                g_weak_ref_set(gWeakRef, object);
164        }
165}
Note: See TracBrowser for help on using the repository browser.