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 gst.base.BitReader;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gst.base.c.functions;
30 public  import gst.base.c.types;
31 private import gtkd.Loader;
32 
33 
34 /**
35  * #GstBitReader provides a bit reader that can read any number of bits
36  * from a memory buffer. It provides functions for reading any number of bits
37  * into 8, 16, 32 and 64 bit variables.
38  */
39 public class BitReader
40 {
41 	/** the main Gtk struct */
42 	protected GstBitReader* gstBitReader;
43 	protected bool ownedRef;
44 
45 	/** Get the main Gtk struct */
46 	public GstBitReader* getBitReaderStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gstBitReader;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected void* getStruct()
55 	{
56 		return cast(void*)gstBitReader;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GstBitReader* gstBitReader, bool ownedRef = false)
63 	{
64 		this.gstBitReader = gstBitReader;
65 		this.ownedRef = ownedRef;
66 	}
67 
68 	~this ()
69 	{
70 		if ( Linker.isLoaded(LIBRARY_GSTBASE) && ownedRef )
71 			gst_bit_reader_free(gstBitReader);
72 	}
73 
74 
75 	/**
76 	 * Frees a #GstBitReader instance, which was previously allocated by
77 	 * gst_bit_reader_new().
78 	 */
79 	public void free()
80 	{
81 		gst_bit_reader_free(gstBitReader);
82 		ownedRef = false;
83 	}
84 
85 	/**
86 	 * Read @nbits bits into @val and update the current position.
87 	 *
88 	 * Params:
89 	 *     val = Pointer to a #guint16 to store the result
90 	 *     nbits = number of bits to read
91 	 *
92 	 * Returns: %TRUE if successful, %FALSE otherwise.
93 	 */
94 	public bool getBitsUint16(out ushort val, uint nbits)
95 	{
96 		return gst_bit_reader_get_bits_uint16(gstBitReader, &val, nbits) != 0;
97 	}
98 
99 	/**
100 	 * Read @nbits bits into @val and update the current position.
101 	 *
102 	 * Params:
103 	 *     val = Pointer to a #guint32 to store the result
104 	 *     nbits = number of bits to read
105 	 *
106 	 * Returns: %TRUE if successful, %FALSE otherwise.
107 	 */
108 	public bool getBitsUint32(out uint val, uint nbits)
109 	{
110 		return gst_bit_reader_get_bits_uint32(gstBitReader, &val, nbits) != 0;
111 	}
112 
113 	/**
114 	 * Read @nbits bits into @val and update the current position.
115 	 *
116 	 * Params:
117 	 *     val = Pointer to a #guint64 to store the result
118 	 *     nbits = number of bits to read
119 	 *
120 	 * Returns: %TRUE if successful, %FALSE otherwise.
121 	 */
122 	public bool getBitsUint64(out ulong val, uint nbits)
123 	{
124 		return gst_bit_reader_get_bits_uint64(gstBitReader, &val, nbits) != 0;
125 	}
126 
127 	/**
128 	 * Read @nbits bits into @val and update the current position.
129 	 *
130 	 * Params:
131 	 *     val = Pointer to a #guint8 to store the result
132 	 *     nbits = number of bits to read
133 	 *
134 	 * Returns: %TRUE if successful, %FALSE otherwise.
135 	 */
136 	public bool getBitsUint8(out ubyte val, uint nbits)
137 	{
138 		return gst_bit_reader_get_bits_uint8(gstBitReader, &val, nbits) != 0;
139 	}
140 
141 	/**
142 	 * Returns the current position of a #GstBitReader instance in bits.
143 	 *
144 	 * Returns: The current position of @reader in bits.
145 	 */
146 	public uint getPos()
147 	{
148 		return gst_bit_reader_get_pos(gstBitReader);
149 	}
150 
151 	/**
152 	 * Returns the remaining number of bits of a #GstBitReader instance.
153 	 *
154 	 * Returns: The remaining number of bits of @reader instance.
155 	 */
156 	public uint getRemaining()
157 	{
158 		return gst_bit_reader_get_remaining(gstBitReader);
159 	}
160 
161 	/**
162 	 * Returns the total number of bits of a #GstBitReader instance.
163 	 *
164 	 * Returns: The total number of bits of @reader instance.
165 	 */
166 	public uint getSize()
167 	{
168 		return gst_bit_reader_get_size(gstBitReader);
169 	}
170 
171 	/**
172 	 * Initializes a #GstBitReader instance to read from @data. This function
173 	 * can be called on already initialized instances.
174 	 *
175 	 * Params:
176 	 *     data = data from which the bit reader should read
177 	 */
178 	public void init(ubyte[] data)
179 	{
180 		gst_bit_reader_init(gstBitReader, data.ptr, cast(uint)data.length);
181 	}
182 
183 	/**
184 	 * Read @nbits bits into @val but keep the current position.
185 	 *
186 	 * Params:
187 	 *     val = Pointer to a #guint16 to store the result
188 	 *     nbits = number of bits to read
189 	 *
190 	 * Returns: %TRUE if successful, %FALSE otherwise.
191 	 */
192 	public bool peekBitsUint16(out ushort val, uint nbits)
193 	{
194 		return gst_bit_reader_peek_bits_uint16(gstBitReader, &val, nbits) != 0;
195 	}
196 
197 	/**
198 	 * Read @nbits bits into @val but keep the current position.
199 	 *
200 	 * Params:
201 	 *     val = Pointer to a #guint32 to store the result
202 	 *     nbits = number of bits to read
203 	 *
204 	 * Returns: %TRUE if successful, %FALSE otherwise.
205 	 */
206 	public bool peekBitsUint32(out uint val, uint nbits)
207 	{
208 		return gst_bit_reader_peek_bits_uint32(gstBitReader, &val, nbits) != 0;
209 	}
210 
211 	/**
212 	 * Read @nbits bits into @val but keep the current position.
213 	 *
214 	 * Params:
215 	 *     val = Pointer to a #guint64 to store the result
216 	 *     nbits = number of bits to read
217 	 *
218 	 * Returns: %TRUE if successful, %FALSE otherwise.
219 	 */
220 	public bool peekBitsUint64(out ulong val, uint nbits)
221 	{
222 		return gst_bit_reader_peek_bits_uint64(gstBitReader, &val, nbits) != 0;
223 	}
224 
225 	/**
226 	 * Read @nbits bits into @val but keep the current position.
227 	 *
228 	 * Params:
229 	 *     val = Pointer to a #guint8 to store the result
230 	 *     nbits = number of bits to read
231 	 *
232 	 * Returns: %TRUE if successful, %FALSE otherwise.
233 	 */
234 	public bool peekBitsUint8(out ubyte val, uint nbits)
235 	{
236 		return gst_bit_reader_peek_bits_uint8(gstBitReader, &val, nbits) != 0;
237 	}
238 
239 	/**
240 	 * Sets the new position of a #GstBitReader instance to @pos in bits.
241 	 *
242 	 * Params:
243 	 *     pos = The new position in bits
244 	 *
245 	 * Returns: %TRUE if the position could be set successfully, %FALSE
246 	 *     otherwise.
247 	 */
248 	public bool setPos(uint pos)
249 	{
250 		return gst_bit_reader_set_pos(gstBitReader, pos) != 0;
251 	}
252 
253 	/**
254 	 * Skips @nbits bits of the #GstBitReader instance.
255 	 *
256 	 * Params:
257 	 *     nbits = the number of bits to skip
258 	 *
259 	 * Returns: %TRUE if @nbits bits could be skipped, %FALSE otherwise.
260 	 */
261 	public bool skip(uint nbits)
262 	{
263 		return gst_bit_reader_skip(gstBitReader, nbits) != 0;
264 	}
265 
266 	/**
267 	 * Skips until the next byte.
268 	 *
269 	 * Returns: %TRUE if successful, %FALSE otherwise.
270 	 */
271 	public bool skipToByte()
272 	{
273 		return gst_bit_reader_skip_to_byte(gstBitReader) != 0;
274 	}
275 
276 	/**
277 	 * Create a new #GstBitReader instance, which will read from @data.
278 	 *
279 	 * Free-function: gst_bit_reader_free
280 	 *
281 	 * Params:
282 	 *     data = Data from which the #GstBitReader
283 	 *         should read
284 	 *
285 	 * Returns: a new #GstBitReader instance
286 	 *
287 	 * Throws: ConstructionException GTK+ fails to create the object.
288 	 */
289 	public this(ubyte[] data)
290 	{
291 		auto p = gst_bit_reader_new(data.ptr, cast(uint)data.length);
292 
293 		if(p is null)
294 		{
295 			throw new ConstructionException("null returned by new");
296 		}
297 
298 		this(cast(GstBitReader*) p);
299 	}
300 }