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 public  import gtkc.giotypes;
33 
34 
35 /**
36  * #GSeekable is implemented by streams (implementations of
37  * #GInputStream or #GOutputStream) that support seeking.
38  * 
39  * Seekable streams largely fall into two categories: resizable and
40  * fixed-size.
41  * 
42  * #GSeekable on fixed-sized streams is approximately the same as POSIX
43  * lseek() on a block device (for example: attmepting to seek past the
44  * end of the device is an error).  Fixed streams typically cannot be
45  * truncated.
46  * 
47  * #GSeekable on resizable streams is approximately the same as POSIX
48  * lseek() on a normal file.  Seeking past the end and writing data will
49  * usually cause the stream to resize by introducing zero bytes.
50  */
51 public template SeekableT(TStruct)
52 {
53 	/** Get the main Gtk struct */
54 	public GSeekable* getSeekableStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return cast(GSeekable*)getStruct();
59 	}
60 
61 
62 	/**
63 	 * Tests if the stream supports the #GSeekableIface.
64 	 *
65 	 * Returns: %TRUE if @seekable can be seeked. %FALSE otherwise.
66 	 */
67 	public bool canSeek()
68 	{
69 		return g_seekable_can_seek(getSeekableStruct()) != 0;
70 	}
71 
72 	/**
73 	 * Tests if the stream can be truncated.
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 	 * Truncates a stream with a given #offset.
135 	 *
136 	 * If @cancellable is not %NULL, then the operation can be cancelled by
137 	 * triggering the cancellable object from another thread. If the operation
138 	 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
139 	 * operation was partially finished when the operation was cancelled the
140 	 * partial result will be returned, without an error.
141 	 *
142 	 * Params:
143 	 *     offset = a #goffset.
144 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
145 	 *
146 	 * Returns: %TRUE if successful. If an error
147 	 *     has occurred, this function will return %FALSE and set @error
148 	 *     appropriately if present.
149 	 *
150 	 * Throws: GException on failure.
151 	 */
152 	public bool truncate(long offset, Cancellable cancellable)
153 	{
154 		GError* err = null;
155 
156 		auto p = g_seekable_truncate(getSeekableStruct(), offset, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
157 
158 		if (err !is null)
159 		{
160 			throw new GException( new ErrorG(err) );
161 		}
162 
163 		return p;
164 	}
165 }