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