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 module gio.MemoryInputStream; 26 27 private import gio.InputStream; 28 private import gio.PollableInputStreamIF; 29 private import gio.PollableInputStreamT; 30 private import gio.SeekableIF; 31 private import gio.SeekableT; 32 private import gio.c.functions; 33 public import gio.c.types; 34 private import glib.Bytes; 35 private import glib.ConstructionException; 36 private import gobject.ObjectG; 37 public import gtkc.giotypes; 38 39 40 /** 41 * #GMemoryInputStream is a class for using arbitrary 42 * memory chunks as input for GIO streaming input operations. 43 * 44 * As of GLib 2.34, #GMemoryInputStream implements 45 * #GPollableInputStream. 46 */ 47 public class MemoryInputStream : InputStream, PollableInputStreamIF, SeekableIF 48 { 49 /** the main Gtk struct */ 50 protected GMemoryInputStream* gMemoryInputStream; 51 52 /** Get the main Gtk struct */ 53 public GMemoryInputStream* getMemoryInputStreamStruct(bool transferOwnership = false) 54 { 55 if (transferOwnership) 56 ownedRef = false; 57 return gMemoryInputStream; 58 } 59 60 /** the main Gtk struct as a void* */ 61 protected override void* getStruct() 62 { 63 return cast(void*)gMemoryInputStream; 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (GMemoryInputStream* gMemoryInputStream, bool ownedRef = false) 70 { 71 this.gMemoryInputStream = gMemoryInputStream; 72 super(cast(GInputStream*)gMemoryInputStream, ownedRef); 73 } 74 75 // add the PollableInputStream capabilities 76 mixin PollableInputStreamT!(GMemoryInputStream); 77 78 // add the Seekable capabilities 79 mixin SeekableT!(GMemoryInputStream); 80 81 82 /** */ 83 public static GType getType() 84 { 85 return g_memory_input_stream_get_type(); 86 } 87 88 /** 89 * Creates a new empty #GMemoryInputStream. 90 * 91 * Returns: a new #GInputStream 92 * 93 * Throws: ConstructionException GTK+ fails to create the object. 94 */ 95 public this() 96 { 97 auto p = g_memory_input_stream_new(); 98 99 if(p is null) 100 { 101 throw new ConstructionException("null returned by new"); 102 } 103 104 this(cast(GMemoryInputStream*) p, true); 105 } 106 107 /** 108 * Creates a new #GMemoryInputStream with data from the given @bytes. 109 * 110 * Params: 111 * bytes = a #GBytes 112 * 113 * Returns: new #GInputStream read from @bytes 114 * 115 * Since: 2.34 116 * 117 * Throws: ConstructionException GTK+ fails to create the object. 118 */ 119 public this(Bytes bytes) 120 { 121 auto p = g_memory_input_stream_new_from_bytes((bytes is null) ? null : bytes.getBytesStruct()); 122 123 if(p is null) 124 { 125 throw new ConstructionException("null returned by new_from_bytes"); 126 } 127 128 this(cast(GMemoryInputStream*) p, true); 129 } 130 131 /** 132 * Creates a new #GMemoryInputStream with data in memory of a given size. 133 * 134 * Params: 135 * data = input data 136 * destroy = function that is called to free @data, or %NULL 137 * 138 * Returns: new #GInputStream read from @data of @len bytes. 139 * 140 * Throws: ConstructionException GTK+ fails to create the object. 141 */ 142 public this(ubyte[] data, GDestroyNotify destroy) 143 { 144 auto p = g_memory_input_stream_new_from_data(data.ptr, cast(ptrdiff_t)data.length, destroy); 145 146 if(p is null) 147 { 148 throw new ConstructionException("null returned by new_from_data"); 149 } 150 151 this(cast(GMemoryInputStream*) p, true); 152 } 153 154 /** 155 * Appends @bytes to data that can be read from the input stream. 156 * 157 * Params: 158 * bytes = input data 159 * 160 * Since: 2.34 161 */ 162 public void addBytes(Bytes bytes) 163 { 164 g_memory_input_stream_add_bytes(gMemoryInputStream, (bytes is null) ? null : bytes.getBytesStruct()); 165 } 166 167 /** 168 * Appends @data to data that can be read from the input stream 169 * 170 * Params: 171 * data = input data 172 * destroy = function that is called to free @data, or %NULL 173 */ 174 public void addData(ubyte[] data, GDestroyNotify destroy) 175 { 176 g_memory_input_stream_add_data(gMemoryInputStream, data.ptr, cast(ptrdiff_t)data.length, destroy); 177 } 178 }