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