source: appstream-generator/build/girepo/gio/MemoryOutputStream.d @ 4841

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

Initial release

File size: 7.9 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 gio.MemoryOutputStream;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.OutputStream;
26private import gio.PollableOutputStreamIF;
27private import gio.PollableOutputStreamT;
28private import gio.SeekableIF;
29private import gio.SeekableT;
30private import glib.Bytes;
31private import glib.ConstructionException;
32private import gobject.ObjectG;
33
34
35/**
36 * #GMemoryOutputStream is a class for using arbitrary
37 * memory chunks as output for GIO streaming output operations.
38 *
39 * As of GLib 2.34, #GMemoryOutputStream trivially implements
40 * #GPollableOutputStream: it always polls as ready.
41 */
42public class MemoryOutputStream : OutputStream, PollableOutputStreamIF, SeekableIF
43{
44        /** the main Gtk struct */
45        protected GMemoryOutputStream* gMemoryOutputStream;
46
47        /** Get the main Gtk struct */
48        public GMemoryOutputStream* getMemoryOutputStreamStruct()
49        {
50                return gMemoryOutputStream;
51        }
52
53        /** the main Gtk struct as a void* */
54        protected override void* getStruct()
55        {
56                return cast(void*)gMemoryOutputStream;
57        }
58
59        protected override void setStruct(GObject* obj)
60        {
61                gMemoryOutputStream = cast(GMemoryOutputStream*)obj;
62                super.setStruct(obj);
63        }
64
65        /**
66         * Sets our main struct and passes it to the parent class.
67         */
68        public this (GMemoryOutputStream* gMemoryOutputStream, bool ownedRef = false)
69        {
70                this.gMemoryOutputStream = gMemoryOutputStream;
71                super(cast(GOutputStream*)gMemoryOutputStream, ownedRef);
72        }
73
74        // add the PollableOutputStream capabilities
75        mixin PollableOutputStreamT!(GMemoryOutputStream);
76
77        // add the Seekable capabilities
78        mixin SeekableT!(GMemoryOutputStream);
79
80
81        /** */
82        public static GType getType()
83        {
84                return g_memory_output_stream_get_type();
85        }
86
87        /**
88         * Creates a new #GMemoryOutputStream.
89         *
90         * In most cases this is not the function you want.  See
91         * g_memory_output_stream_new_resizable() instead.
92         *
93         * If @data is non-%NULL, the stream will use that for its internal storage.
94         *
95         * If @realloc_fn is non-%NULL, it will be used for resizing the internal
96         * storage when necessary and the stream will be considered resizable.
97         * In that case, the stream will start out being (conceptually) empty.
98         * @size is used only as a hint for how big @data is.  Specifically,
99         * seeking to the end of a newly-created stream will seek to zero, not
100         * @size.  Seeking past the end of the stream and then writing will
101         * introduce a zero-filled gap.
102         *
103         * If @realloc_fn is %NULL then the stream is fixed-sized.  Seeking to
104         * the end will seek to @size exactly.  Writing past the end will give
105         * an 'out of space' error.  Attempting to seek past the end will fail.
106         * Unlike the resizable case, seeking to an offset within the stream and
107         * writing will preserve the bytes passed in as @data before that point
108         * and will return them as part of g_memory_output_stream_steal_data().
109         * If you intend to seek you should probably therefore ensure that @data
110         * is properly initialised.
111         *
112         * It is probably only meaningful to provide @data and @size in the case
113         * that you want a fixed-sized stream.  Put another way: if @realloc_fn
114         * is non-%NULL then it makes most sense to give @data as %NULL and
115         * @size as 0 (allowing #GMemoryOutputStream to do the initial
116         * allocation for itself).
117         *
118         * |[<!-- language="C" -->
119         * // a stream that can grow
120         * stream = g_memory_output_stream_new (NULL, 0, realloc, free);
121         *
122         * // another stream that can grow
123         * stream2 = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
124         *
125         * // a fixed-size stream
126         * data = malloc (200);
127         * stream3 = g_memory_output_stream_new (data, 200, NULL, free);
128         * ]|
129         *
130         * Params:
131         *     data = pointer to a chunk of memory to use, or %NULL
132         *     size = the size of @data
133         *     reallocFunction = a function with realloc() semantics (like g_realloc())
134         *         to be called when @data needs to be grown, or %NULL
135         *     destroyFunction = a function to be called on @data when the stream is
136         *         finalized, or %NULL
137         *
138         * Returns: A newly created #GMemoryOutputStream object.
139         *
140         * Throws: ConstructionException GTK+ fails to create the object.
141         */
142        public this(void* data, size_t size, GReallocFunc reallocFunction, GDestroyNotify destroyFunction)
143        {
144                auto p = g_memory_output_stream_new(data, size, reallocFunction, destroyFunction);
145               
146                if(p is null)
147                {
148                        throw new ConstructionException("null returned by new");
149                }
150               
151                this(cast(GMemoryOutputStream*) p, true);
152        }
153
154        /**
155         * Creates a new #GMemoryOutputStream, using g_realloc() and g_free()
156         * for memory allocation.
157         *
158         * Since: 2.36
159         *
160         * Throws: ConstructionException GTK+ fails to create the object.
161         */
162        public this()
163        {
164                auto p = g_memory_output_stream_new_resizable();
165               
166                if(p is null)
167                {
168                        throw new ConstructionException("null returned by new_resizable");
169                }
170               
171                this(cast(GMemoryOutputStream*) p, true);
172        }
173
174        /**
175         * Gets any loaded data from the @ostream.
176         *
177         * Note that the returned pointer may become invalid on the next
178         * write or truncate operation on the stream.
179         *
180         * Returns: pointer to the stream's data
181         */
182        public void* getData()
183        {
184                return g_memory_output_stream_get_data(gMemoryOutputStream);
185        }
186
187        /**
188         * Returns the number of bytes from the start up to including the last
189         * byte written in the stream that has not been truncated away.
190         *
191         * Returns: the number of bytes written to the stream
192         *
193         * Since: 2.18
194         */
195        public size_t getDataSize()
196        {
197                return g_memory_output_stream_get_data_size(gMemoryOutputStream);
198        }
199
200        /**
201         * Gets the size of the currently allocated data area (available from
202         * g_memory_output_stream_get_data()).
203         *
204         * You probably don't want to use this function on resizable streams.
205         * See g_memory_output_stream_get_data_size() instead.  For resizable
206         * streams the size returned by this function is an implementation
207         * detail and may be change at any time in response to operations on the
208         * stream.
209         *
210         * If the stream is fixed-sized (ie: no realloc was passed to
211         * g_memory_output_stream_new()) then this is the maximum size of the
212         * stream and further writes will return %G_IO_ERROR_NO_SPACE.
213         *
214         * In any case, if you want the number of bytes currently written to the
215         * stream, use g_memory_output_stream_get_data_size().
216         *
217         * Returns: the number of bytes allocated for the data buffer
218         */
219        public size_t getSize()
220        {
221                return g_memory_output_stream_get_size(gMemoryOutputStream);
222        }
223
224        /**
225         * Returns data from the @ostream as a #GBytes. @ostream must be
226         * closed before calling this function.
227         *
228         * Returns: the stream's data
229         *
230         * Since: 2.34
231         */
232        public Bytes stealAsBytes()
233        {
234                auto p = g_memory_output_stream_steal_as_bytes(gMemoryOutputStream);
235               
236                if(p is null)
237                {
238                        return null;
239                }
240               
241                return new Bytes(cast(GBytes*) p, true);
242        }
243
244        /**
245         * Gets any loaded data from the @ostream. Ownership of the data
246         * is transferred to the caller; when no longer needed it must be
247         * freed using the free function set in @ostream's
248         * #GMemoryOutputStream:destroy-function property.
249         *
250         * @ostream must be closed before calling this function.
251         *
252         * Returns: the stream's data
253         *
254         * Since: 2.26
255         */
256        public void* stealData()
257        {
258                return g_memory_output_stream_steal_data(gMemoryOutputStream);
259        }
260}
Note: See TracBrowser for help on using the repository browser.