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 	protected override void setStruct(GObject* obj)
67 	{
68 		gMemoryInputStream = cast(GMemoryInputStream*)obj;
69 		super.setStruct(obj);
70 	}
71 
72 	/**
73 	 * Sets our main struct and passes it to the parent class.
74 	 */
75 	public this (GMemoryInputStream* gMemoryInputStream, bool ownedRef = false)
76 	{
77 		this.gMemoryInputStream = gMemoryInputStream;
78 		super(cast(GInputStream*)gMemoryInputStream, ownedRef);
79 	}
80 
81 	// add the PollableInputStream capabilities
82 	mixin PollableInputStreamT!(GMemoryInputStream);
83 
84 	// add the Seekable capabilities
85 	mixin SeekableT!(GMemoryInputStream);
86 
87 
88 	/** */
89 	public static GType getType()
90 	{
91 		return g_memory_input_stream_get_type();
92 	}
93 
94 	/**
95 	 * Creates a new empty #GMemoryInputStream.
96 	 *
97 	 * Returns: a new #GInputStream
98 	 *
99 	 * Throws: ConstructionException GTK+ fails to create the object.
100 	 */
101 	public this()
102 	{
103 		auto p = g_memory_input_stream_new();
104 
105 		if(p is null)
106 		{
107 			throw new ConstructionException("null returned by new");
108 		}
109 
110 		this(cast(GMemoryInputStream*) p, true);
111 	}
112 
113 	/**
114 	 * Creates a new #GMemoryInputStream with data from the given @bytes.
115 	 *
116 	 * Params:
117 	 *     bytes = a #GBytes
118 	 *
119 	 * Returns: new #GInputStream read from @bytes
120 	 *
121 	 * Since: 2.34
122 	 *
123 	 * Throws: ConstructionException GTK+ fails to create the object.
124 	 */
125 	public this(Bytes bytes)
126 	{
127 		auto p = g_memory_input_stream_new_from_bytes((bytes is null) ? null : bytes.getBytesStruct());
128 
129 		if(p is null)
130 		{
131 			throw new ConstructionException("null returned by new_from_bytes");
132 		}
133 
134 		this(cast(GMemoryInputStream*) p, true);
135 	}
136 
137 	/**
138 	 * Creates a new #GMemoryInputStream with data in memory of a given size.
139 	 *
140 	 * Params:
141 	 *     data = input data
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 	 *     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 }