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 gio.c.functions;
29 public  import gio.c.types;
30 public  import glib.ErrorG;
31 public  import glib.GException;
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: attempting 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 length of the stream can be adjusted with
73 	 * g_seekable_truncate().
74 	 *
75 	 * Returns: %TRUE if the stream can be truncated, %FALSE otherwise.
76 	 */
77 	public bool canTruncate()
78 	{
79 		return g_seekable_can_truncate(getSeekableStruct()) != 0;
80 	}
81 
82 	/**
83 	 * Seeks in the stream by the given @offset, modified by @type.
84 	 *
85 	 * Attempting to seek past the end of the stream will have different
86 	 * results depending on if the stream is fixed-sized or resizable.  If
87 	 * the stream is resizable then seeking past the end and then writing
88 	 * will result in zeros filling the empty space.  Seeking past the end
89 	 * of a resizable stream and reading will result in EOF.  Seeking past
90 	 * the end of a fixed-sized stream will fail.
91 	 *
92 	 * Any operation that would result in a negative offset will fail.
93 	 *
94 	 * If @cancellable is not %NULL, then the operation can be cancelled by
95 	 * triggering the cancellable object from another thread. If the operation
96 	 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
97 	 *
98 	 * Params:
99 	 *     offset = a #goffset.
100 	 *     type = a #GSeekType.
101 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
102 	 *
103 	 * Returns: %TRUE if successful. If an error
104 	 *     has occurred, this function will return %FALSE and set @error
105 	 *     appropriately if present.
106 	 *
107 	 * Throws: GException on failure.
108 	 */
109 	public bool seek(long offset, GSeekType type, Cancellable cancellable)
110 	{
111 		GError* err = null;
112 
113 		auto __p = g_seekable_seek(getSeekableStruct(), offset, type, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
114 
115 		if (err !is null)
116 		{
117 			throw new GException( new ErrorG(err) );
118 		}
119 
120 		return __p;
121 	}
122 
123 	/**
124 	 * Tells the current position within the stream.
125 	 *
126 	 * Returns: the offset from the beginning of the buffer.
127 	 */
128 	public long tell()
129 	{
130 		return g_seekable_tell(getSeekableStruct());
131 	}
132 
133 	/**
134 	 * Sets the length of the stream to @offset. If the stream was previously
135 	 * larger than @offset, the extra data is discarded. If the stream was
136 	 * previously shorter than @offset, it is extended with NUL ('\0') bytes.
137 	 *
138 	 * If @cancellable is not %NULL, then the operation can be cancelled by
139 	 * triggering the cancellable object from another thread. If the operation
140 	 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
141 	 * operation was partially finished when the operation was cancelled the
142 	 * partial result will be returned, without an error.
143 	 *
144 	 * Params:
145 	 *     offset = new length for @seekable, in bytes.
146 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
147 	 *
148 	 * Returns: %TRUE if successful. If an error
149 	 *     has occurred, this function will return %FALSE and set @error
150 	 *     appropriately if present.
151 	 *
152 	 * Throws: GException on failure.
153 	 */
154 	public bool truncate(long offset, Cancellable cancellable)
155 	{
156 		GError* err = null;
157 
158 		auto __p = g_seekable_truncate(getSeekableStruct(), offset, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
159 
160 		if (err !is null)
161 		{
162 			throw new GException( new ErrorG(err) );
163 		}
164 
165 		return __p;
166 	}
167 }