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