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.DataOutputStream;
26 
27 private import gio.Cancellable;
28 private import gio.FilterOutputStream;
29 private import gio.OutputStream;
30 private import gio.SeekableIF;
31 private import gio.SeekableT;
32 private import glib.ConstructionException;
33 private import glib.ErrorG;
34 private import glib.GException;
35 private import glib.Str;
36 private import gobject.ObjectG;
37 private import gtkc.gio;
38 public  import gtkc.giotypes;
39 
40 
41 /**
42  * Data output stream implements #GOutputStream and includes functions for
43  * writing data directly to an output stream.
44  */
45 public class DataOutputStream : FilterOutputStream, SeekableIF
46 {
47 	/** the main Gtk struct */
48 	protected GDataOutputStream* gDataOutputStream;
49 
50 	/** Get the main Gtk struct */
51 	public GDataOutputStream* getDataOutputStreamStruct()
52 	{
53 		return gDataOutputStream;
54 	}
55 
56 	/** the main Gtk struct as a void* */
57 	protected override void* getStruct()
58 	{
59 		return cast(void*)gDataOutputStream;
60 	}
61 
62 	protected override void setStruct(GObject* obj)
63 	{
64 		gDataOutputStream = cast(GDataOutputStream*)obj;
65 		super.setStruct(obj);
66 	}
67 
68 	/**
69 	 * Sets our main struct and passes it to the parent class.
70 	 */
71 	public this (GDataOutputStream* gDataOutputStream, bool ownedRef = false)
72 	{
73 		this.gDataOutputStream = gDataOutputStream;
74 		super(cast(GFilterOutputStream*)gDataOutputStream, ownedRef);
75 	}
76 
77 	// add the Seekable capabilities
78 	mixin SeekableT!(GDataOutputStream);
79 
80 
81 	/** */
82 	public static GType getType()
83 	{
84 		return g_data_output_stream_get_type();
85 	}
86 
87 	/**
88 	 * Creates a new data output stream for @base_stream.
89 	 *
90 	 * Params:
91 	 *     baseStream = a #GOutputStream.
92 	 *
93 	 * Return: #GDataOutputStream.
94 	 *
95 	 * Throws: ConstructionException GTK+ fails to create the object.
96 	 */
97 	public this(OutputStream baseStream)
98 	{
99 		auto p = g_data_output_stream_new((baseStream is null) ? null : baseStream.getOutputStreamStruct());
100 		
101 		if(p is null)
102 		{
103 			throw new ConstructionException("null returned by new");
104 		}
105 		
106 		this(cast(GDataOutputStream*) p, true);
107 	}
108 
109 	/**
110 	 * Gets the byte order for the stream.
111 	 *
112 	 * Return: the #GDataStreamByteOrder for the @stream.
113 	 */
114 	public GDataStreamByteOrder getByteOrder()
115 	{
116 		return g_data_output_stream_get_byte_order(gDataOutputStream);
117 	}
118 
119 	/**
120 	 * Puts a byte into the output stream.
121 	 *
122 	 * Params:
123 	 *     data = a #guchar.
124 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
125 	 *
126 	 * Return: %TRUE if @data was successfully added to the @stream.
127 	 *
128 	 * Throws: GException on failure.
129 	 */
130 	public bool putByte(char data, Cancellable cancellable)
131 	{
132 		GError* err = null;
133 		
134 		auto p = g_data_output_stream_put_byte(gDataOutputStream, data, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
135 		
136 		if (err !is null)
137 		{
138 			throw new GException( new ErrorG(err) );
139 		}
140 		
141 		return p;
142 	}
143 
144 	/**
145 	 * Puts a signed 16-bit integer into the output stream.
146 	 *
147 	 * Params:
148 	 *     data = a #gint16.
149 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
150 	 *
151 	 * Return: %TRUE if @data was successfully added to the @stream.
152 	 *
153 	 * Throws: GException on failure.
154 	 */
155 	public bool putInt16(short data, Cancellable cancellable)
156 	{
157 		GError* err = null;
158 		
159 		auto p = g_data_output_stream_put_int16(gDataOutputStream, data, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
160 		
161 		if (err !is null)
162 		{
163 			throw new GException( new ErrorG(err) );
164 		}
165 		
166 		return p;
167 	}
168 
169 	/**
170 	 * Puts a signed 32-bit integer into the output stream.
171 	 *
172 	 * Params:
173 	 *     data = a #gint32.
174 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
175 	 *
176 	 * Return: %TRUE if @data was successfully added to the @stream.
177 	 *
178 	 * Throws: GException on failure.
179 	 */
180 	public bool putInt32(int data, Cancellable cancellable)
181 	{
182 		GError* err = null;
183 		
184 		auto p = g_data_output_stream_put_int32(gDataOutputStream, data, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
185 		
186 		if (err !is null)
187 		{
188 			throw new GException( new ErrorG(err) );
189 		}
190 		
191 		return p;
192 	}
193 
194 	/**
195 	 * Puts a signed 64-bit integer into the stream.
196 	 *
197 	 * Params:
198 	 *     data = a #gint64.
199 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
200 	 *
201 	 * Return: %TRUE if @data was successfully added to the @stream.
202 	 *
203 	 * Throws: GException on failure.
204 	 */
205 	public bool putInt64(long data, Cancellable cancellable)
206 	{
207 		GError* err = null;
208 		
209 		auto p = g_data_output_stream_put_int64(gDataOutputStream, data, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
210 		
211 		if (err !is null)
212 		{
213 			throw new GException( new ErrorG(err) );
214 		}
215 		
216 		return p;
217 	}
218 
219 	/**
220 	 * Puts a string into the output stream.
221 	 *
222 	 * Params:
223 	 *     str = a string.
224 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
225 	 *
226 	 * Return: %TRUE if @string was successfully added to the @stream.
227 	 *
228 	 * Throws: GException on failure.
229 	 */
230 	public bool putString(string str, Cancellable cancellable)
231 	{
232 		GError* err = null;
233 		
234 		auto p = g_data_output_stream_put_string(gDataOutputStream, Str.toStringz(str), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
235 		
236 		if (err !is null)
237 		{
238 			throw new GException( new ErrorG(err) );
239 		}
240 		
241 		return p;
242 	}
243 
244 	/**
245 	 * Puts an unsigned 16-bit integer into the output stream.
246 	 *
247 	 * Params:
248 	 *     data = a #guint16.
249 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
250 	 *
251 	 * Return: %TRUE if @data was successfully added to the @stream.
252 	 *
253 	 * Throws: GException on failure.
254 	 */
255 	public bool putUint16(ushort data, Cancellable cancellable)
256 	{
257 		GError* err = null;
258 		
259 		auto p = g_data_output_stream_put_uint16(gDataOutputStream, data, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
260 		
261 		if (err !is null)
262 		{
263 			throw new GException( new ErrorG(err) );
264 		}
265 		
266 		return p;
267 	}
268 
269 	/**
270 	 * Puts an unsigned 32-bit integer into the stream.
271 	 *
272 	 * Params:
273 	 *     data = a #guint32.
274 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
275 	 *
276 	 * Return: %TRUE if @data was successfully added to the @stream.
277 	 *
278 	 * Throws: GException on failure.
279 	 */
280 	public bool putUint32(uint data, Cancellable cancellable)
281 	{
282 		GError* err = null;
283 		
284 		auto p = g_data_output_stream_put_uint32(gDataOutputStream, data, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
285 		
286 		if (err !is null)
287 		{
288 			throw new GException( new ErrorG(err) );
289 		}
290 		
291 		return p;
292 	}
293 
294 	/**
295 	 * Puts an unsigned 64-bit integer into the stream.
296 	 *
297 	 * Params:
298 	 *     data = a #guint64.
299 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
300 	 *
301 	 * Return: %TRUE if @data was successfully added to the @stream.
302 	 *
303 	 * Throws: GException on failure.
304 	 */
305 	public bool putUint64(ulong data, Cancellable cancellable)
306 	{
307 		GError* err = null;
308 		
309 		auto p = g_data_output_stream_put_uint64(gDataOutputStream, data, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
310 		
311 		if (err !is null)
312 		{
313 			throw new GException( new ErrorG(err) );
314 		}
315 		
316 		return p;
317 	}
318 
319 	/**
320 	 * Sets the byte order of the data output stream to @order.
321 	 *
322 	 * Params:
323 	 *     order = a %GDataStreamByteOrder.
324 	 */
325 	public void setByteOrder(GDataStreamByteOrder order)
326 	{
327 		g_data_output_stream_set_byte_order(gDataOutputStream, order);
328 	}
329 }