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 	public static GType getType()
87 	{
88 		return g_memory_input_stream_get_type();
89 	}
90 
91 	/**
92 	 * Creates a new empty #GMemoryInputStream.
93 	 *
94 	 * Return: a new #GInputStream
95 	 *
96 	 * Throws: ConstructionException GTK+ fails to create the object.
97 	 */
98 	public this()
99 	{
100 		auto p = g_memory_input_stream_new();
101 		
102 		if(p is null)
103 		{
104 			throw new ConstructionException("null returned by new");
105 		}
106 		
107 		this(cast(GMemoryInputStream*) p, true);
108 	}
109 
110 	/**
111 	 * Creates a new #GMemoryInputStream with data from the given @bytes.
112 	 *
113 	 * Params:
114 	 *     bytes = a #GBytes
115 	 *
116 	 * Return: new #GInputStream read from @bytes
117 	 *
118 	 * Since: 2.34
119 	 *
120 	 * Throws: ConstructionException GTK+ fails to create the object.
121 	 */
122 	public this(Bytes bytes)
123 	{
124 		auto p = g_memory_input_stream_new_from_bytes((bytes is null) ? null : bytes.getBytesStruct());
125 		
126 		if(p is null)
127 		{
128 			throw new ConstructionException("null returned by new_from_bytes");
129 		}
130 		
131 		this(cast(GMemoryInputStream*) p, true);
132 	}
133 
134 	/**
135 	 * Creates a new #GMemoryInputStream with data in memory of a given size.
136 	 *
137 	 * Params:
138 	 *     data = input data
139 	 *     len = length of the data, may be -1 if @data is a nul-terminated string
140 	 *     destroy = function that is called to free @data, or %NULL
141 	 *
142 	 * Return: new #GInputStream read from @data of @len bytes.
143 	 *
144 	 * Throws: ConstructionException GTK+ fails to create the object.
145 	 */
146 	public this(ubyte[] data, GDestroyNotify destroy)
147 	{
148 		auto p = g_memory_input_stream_new_from_data(data.ptr, cast(ptrdiff_t)data.length, destroy);
149 		
150 		if(p is null)
151 		{
152 			throw new ConstructionException("null returned by new_from_data");
153 		}
154 		
155 		this(cast(GMemoryInputStream*) p, true);
156 	}
157 
158 	/**
159 	 * Appends @bytes to data that can be read from the input stream.
160 	 *
161 	 * Params:
162 	 *     bytes = input data
163 	 *
164 	 * Since: 2.34
165 	 */
166 	public void addBytes(Bytes bytes)
167 	{
168 		g_memory_input_stream_add_bytes(gMemoryInputStream, (bytes is null) ? null : bytes.getBytesStruct());
169 	}
170 
171 	/**
172 	 * Appends @data to data that can be read from the input stream
173 	 *
174 	 * Params:
175 	 *     data = input data
176 	 *     len = length of the data, may be -1 if @data is a nul-terminated string
177 	 *     destroy = function that is called to free @data, or %NULL
178 	 */
179 	public void addData(ubyte[] data, GDestroyNotify destroy)
180 	{
181 		g_memory_input_stream_add_data(gMemoryInputStream, data.ptr, cast(ptrdiff_t)data.length, destroy);
182 	}
183 }