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.SeekableT;
26 
27 public  import gio.Cancellable;
28 public  import glib.ErrorG;
29 public  import glib.GException;
30 public  import gtkc.gio;
31 public  import gtkc.giotypes;
32 
33 
34 /**
35  * #GSeekable is implemented by streams (implementations of
36  * #GInputStream or #GOutputStream) that support seeking.
37  * 
38  * Seekable streams largely fall into two categories: resizable and
39  * fixed-size.
40  * 
41  * #GSeekable on fixed-sized streams is approximately the same as POSIX
42  * lseek() on a block device (for example: attmepting to seek past the
43  * end of the device is an error).  Fixed streams typically cannot be
44  * truncated.
45  * 
46  * #GSeekable on resizable streams is approximately the same as POSIX
47  * lseek() on a normal file.  Seeking past the end and writing data will
48  * usually cause the stream to resize by introducing zero bytes.
49  */
50 public template SeekableT(TStruct)
51 {
52 	/** Get the main Gtk struct */
53 	public GSeekable* getSeekableStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return cast(GSeekable*)getStruct();
58 	}
59 
60 
61 	/**
62 	 * Tests if the stream supports the #GSeekableIface.
63 	 *
64 	 * Returns: %TRUE if @seekable can be seeked. %FALSE otherwise.
65 	 */
66 	public bool canSeek()
67 	{
68 		return g_seekable_can_seek(getSeekableStruct()) != 0;
69 	}
70 
71 	/**
72 	 * Tests if the stream can be truncated.
73 	 *
74 	 * Returns: %TRUE if the stream can be truncated, %FALSE otherwise.
75 	 */
76 	public bool canTruncate()
77 	{
78 		return g_seekable_can_truncate(getSeekableStruct()) != 0;
79 	}
80 
81 	/**
82 	 * Seeks in the stream by the given @offset, modified by @type.
83 	 *
84 	 * Attempting to seek past the end of the stream will have different
85 	 * results depending on if the stream is fixed-sized or resizable.  If
86 	 * the stream is resizable then seeking past the end and then writing
87 	 * will result in zeros filling the empty space.  Seeking past the end
88 	 * of a resizable stream and reading will result in EOF.  Seeking past
89 	 * the end of a fixed-sized stream will fail.
90 	 *
91 	 * Any operation that would result in a negative offset will fail.
92 	 *
93 	 * If @cancellable is not %NULL, then the operation can be cancelled by
94 	 * triggering the cancellable object from another thread. If the operation
95 	 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
96 	 *
97 	 * Params:
98 	 *     offset = a #goffset.
99 	 *     type = a #GSeekType.
100 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
101 	 *
102 	 * Returns: %TRUE if successful. If an error
103 	 *     has occurred, this function will return %FALSE and set @error
104 	 *     appropriately if present.
105 	 *
106 	 * Throws: GException on failure.
107 	 */
108 	public bool seek(long offset, GSeekType type, Cancellable cancellable)
109 	{
110 		GError* err = null;
111 		
112 		auto p = g_seekable_seek(getSeekableStruct(), offset, type, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
113 		
114 		if (err !is null)
115 		{
116 			throw new GException( new ErrorG(err) );
117 		}
118 		
119 		return p;
120 	}
121 
122 	/**
123 	 * Tells the current position within the stream.
124 	 *
125 	 * Returns: the offset from the beginning of the buffer.
126 	 */
127 	public long tell()
128 	{
129 		return g_seekable_tell(getSeekableStruct());
130 	}
131 
132 	/**
133 	 * Truncates a stream with a given #offset.
134 	 *
135 	 * If @cancellable is not %NULL, then the operation can be cancelled by
136 	 * triggering the cancellable object from another thread. If the operation
137 	 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
138 	 * operation was partially finished when the operation was cancelled the
139 	 * partial result will be returned, without an error.
140 	 *
141 	 * Params:
142 	 *     offset = a #goffset.
143 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
144 	 *
145 	 * Returns: %TRUE if successful. If an error
146 	 *     has occurred, this function will return %FALSE and set @error
147 	 *     appropriately if present.
148 	 *
149 	 * Throws: GException on failure.
150 	 */
151 	public bool truncate(long offset, Cancellable cancellable)
152 	{
153 		GError* err = null;
154 		
155 		auto p = g_seekable_truncate(getSeekableStruct(), offset, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
156 		
157 		if (err !is null)
158 		{
159 			throw new GException( new ErrorG(err) );
160 		}
161 		
162 		return p;
163 	}
164 }