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