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