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