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