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 = GMemoryOutputStream.html 27 * outPack = gio 28 * outFile = MemoryOutputStream 29 * strct = GMemoryOutputStream 30 * realStrct= 31 * ctorStrct=GOutputStream 32 * clss = MemoryOutputStream 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * - SeekableIF 40 * prefixes: 41 * - g_memory_output_stream_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * omit signals: 46 * imports: 47 * - gio.SeekableT 48 * - gio.SeekableIF 49 * structWrap: 50 * module aliases: 51 * local aliases: 52 * overrides: 53 */ 54 55 module gio.MemoryOutputStream; 56 57 public import gtkc.giotypes; 58 59 private import gtkc.gio; 60 private import glib.ConstructionException; 61 private import gobject.ObjectG; 62 63 private import gio.SeekableT; 64 private import gio.SeekableIF; 65 66 67 private import gio.OutputStream; 68 69 /** 70 * GMemoryOutputStream is a class for using arbitrary 71 * memory chunks as output for GIO streaming output operations. 72 * 73 * As of GLib 2.34, GMemoryOutputStream implements 74 * GPollableOutputStream. 75 */ 76 public class MemoryOutputStream : OutputStream, SeekableIF 77 { 78 79 /** the main Gtk struct */ 80 protected GMemoryOutputStream* gMemoryOutputStream; 81 82 83 /** Get the main Gtk struct */ 84 public GMemoryOutputStream* getMemoryOutputStreamStruct() 85 { 86 return gMemoryOutputStream; 87 } 88 89 90 /** the main Gtk struct as a void* */ 91 protected override void* getStruct() 92 { 93 return cast(void*)gMemoryOutputStream; 94 } 95 96 /** 97 * Sets our main struct and passes it to the parent class 98 */ 99 public this (GMemoryOutputStream* gMemoryOutputStream) 100 { 101 super(cast(GOutputStream*)gMemoryOutputStream); 102 this.gMemoryOutputStream = gMemoryOutputStream; 103 } 104 105 protected override void setStruct(GObject* obj) 106 { 107 super.setStruct(obj); 108 gMemoryOutputStream = cast(GMemoryOutputStream*)obj; 109 } 110 111 // add the Seekable capabilities 112 mixin SeekableT!(GMemoryOutputStream); 113 114 /** 115 */ 116 117 /** 118 * Creates a new GMemoryOutputStream. 119 * If data is non-NULL, the stream will use that for its internal storage. 120 * If realloc_fn is non-NULL, it will be used for resizing the internal 121 * storage when necessary. To construct a fixed-size output stream, 122 * pass NULL as realloc_fn. 123 * $(DDOC_COMMENT example) 124 * Params: 125 * data = pointer to a chunk of memory to use, or NULL. [allow-none] 126 * size = the size of data 127 * reallocFunction = a function with realloc() semantics (like g_realloc()) 128 * to be called when data needs to be grown, or NULL. [allow-none] 129 * destroyFunction = a function to be called on data when the stream is 130 * finalized, or NULL. [allow-none] 131 * Throws: ConstructionException GTK+ fails to create the object. 132 */ 133 public this (void* data, gsize size, GReallocFunc reallocFunction, GDestroyNotify destroyFunction) 134 { 135 // GOutputStream * g_memory_output_stream_new (gpointer data, gsize size, GReallocFunc realloc_function, GDestroyNotify destroy_function); 136 auto p = g_memory_output_stream_new(data, size, reallocFunction, destroyFunction); 137 if(p is null) 138 { 139 throw new ConstructionException("null returned by g_memory_output_stream_new(data, size, reallocFunction, destroyFunction)"); 140 } 141 this(cast(GMemoryOutputStream*) p); 142 } 143 144 /** 145 * Creates a new GMemoryOutputStream, using g_realloc() and g_free() 146 * for memory allocation. 147 * Since 2.36 148 * Throws: ConstructionException GTK+ fails to create the object. 149 */ 150 public this () 151 { 152 // GOutputStream * g_memory_output_stream_new_resizable (void); 153 auto p = g_memory_output_stream_new_resizable(); 154 if(p is null) 155 { 156 throw new ConstructionException("null returned by g_memory_output_stream_new_resizable()"); 157 } 158 this(cast(GMemoryOutputStream*) p); 159 } 160 161 /** 162 * Gets any loaded data from the ostream. 163 * Note that the returned pointer may become invalid on the next 164 * write or truncate operation on the stream. 165 * Returns: pointer to the stream's data. [transfer none] 166 */ 167 public void* getData() 168 { 169 // gpointer g_memory_output_stream_get_data (GMemoryOutputStream *ostream); 170 return g_memory_output_stream_get_data(gMemoryOutputStream); 171 } 172 173 /** 174 * Gets the size of the currently allocated data area (available from 175 * g_memory_output_stream_get_data()). If the stream isn't 176 * growable (no realloc was passed to g_memory_output_stream_new()) then 177 * this is the maximum size of the stream and further writes 178 * will return G_IO_ERROR_NO_SPACE. 179 * Note that for growable streams the returned size may become invalid on 180 * the next write or truncate operation on the stream. 181 * If you want the number of bytes currently written to the stream, use 182 * g_memory_output_stream_get_data_size(). 183 * Returns: the number of bytes allocated for the data buffer 184 */ 185 public gsize getSize() 186 { 187 // gsize g_memory_output_stream_get_size (GMemoryOutputStream *ostream); 188 return g_memory_output_stream_get_size(gMemoryOutputStream); 189 } 190 191 /** 192 * Returns the number of bytes from the start up 193 * to including the last byte written in the stream 194 * that has not been truncated away. 195 * Since 2.18 196 * Returns: the number of bytes written to the stream 197 */ 198 public gsize getDataSize() 199 { 200 // gsize g_memory_output_stream_get_data_size (GMemoryOutputStream *ostream); 201 return g_memory_output_stream_get_data_size(gMemoryOutputStream); 202 } 203 204 /** 205 * Gets any loaded data from the ostream. Ownership of the data 206 * is transferred to the caller; when no longer needed it must be 207 * freed using the free function set in ostream's 208 * "destroy-function" property. 209 * ostream must be closed before calling this function. 210 * Since 2.26 211 * Returns: the stream's data. [transfer full] 212 */ 213 public void* stealData() 214 { 215 // gpointer g_memory_output_stream_steal_data (GMemoryOutputStream *ostream); 216 return g_memory_output_stream_steal_data(gMemoryOutputStream); 217 } 218 219 /** 220 * Returns data from the ostream as a GBytes. ostream must be 221 * closed before calling this function. 222 * Since 2.34 223 * Returns: the stream's data. [transfer full] 224 */ 225 public GBytes* stealAsBytes() 226 { 227 // GBytes * g_memory_output_stream_steal_as_bytes (GMemoryOutputStream *ostream); 228 return g_memory_output_stream_steal_as_bytes(gMemoryOutputStream); 229 } 230 }