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  * Conversion parameters:
26  * inFile  = 
27  * outPack = glib
28  * outFile = Bytes
29  * strct   = GBytes
30  * realStrct=
31  * ctorStrct=
32  * clss    = Bytes
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_bytes_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- g_bytes_new_take
45  * 	- g_bytes_new_static
46  * omit signals:
47  * imports:
48  * 	- glib.ByteArray
49  * structWrap:
50  * 	- GByteArray* -> ByteArray
51  * 	- GBytes* -> Bytes
52  * module aliases:
53  * local aliases:
54  * overrides:
55  */
56 
57 module glib.Bytes;
58 
59 public  import gtkc.glibtypes;
60 
61 private import gtkc.glib;
62 private import glib.ConstructionException;
63 
64 private import glib.ByteArray;
65 
66 
67 
68 /**
69  * GByteArray is a mutable array of bytes based on GArray, to provide arrays
70  * of bytes which grow automatically as elements are added.
71  *
72  * To create a new GByteArray use g_byte_array_new(). To add elements to a
73  * GByteArray, use g_byte_array_append(), and g_byte_array_prepend().
74  *
75  * To set the size of a GByteArray, use g_byte_array_set_size().
76  *
77  * To free a GByteArray, use g_byte_array_free().
78  *
79  * $(DDOC_COMMENT example)
80  *
81  * See GBytes if you are interested in an immutable object representing a
82  * sequence of bytes.
83  */
84 public class Bytes
85 {
86 	
87 	/** the main Gtk struct */
88 	protected GBytes* gBytes;
89 	
90 	
91 	/** Get the main Gtk struct */
92 	public GBytes* getBytesStruct()
93 	{
94 		return gBytes;
95 	}
96 	
97 	
98 	/** the main Gtk struct as a void* */
99 	protected void* getStruct()
100 	{
101 		return cast(void*)gBytes;
102 	}
103 	
104 	/**
105 	 * Sets our main struct and passes it to the parent class
106 	 */
107 	public this (GBytes* gBytes)
108 	{
109 		this.gBytes = gBytes;
110 	}
111 	
112 	/**
113 	 */
114 	
115 	/**
116 	 * Creates a new GBytes from data.
117 	 * data is copied.
118 	 * Since 2.32
119 	 * Params:
120 	 * data = the data to be used for the bytes. [transfer none][array length=size][element-type guint8]
121 	 * size = the size of data
122 	 * Throws: ConstructionException GTK+ fails to create the object.
123 	 */
124 	public this (void* data, gsize size)
125 	{
126 		// GBytes * g_bytes_new (gconstpointer data,  gsize size);
127 		auto p = g_bytes_new(data, size);
128 		if(p is null)
129 		{
130 			throw new ConstructionException("null returned by g_bytes_new(data, size)");
131 		}
132 		this(cast(GBytes*) p);
133 	}
134 	
135 	/**
136 	 * Creates a GBytes from data.
137 	 * When the last reference is dropped, free_func will be called with the
138 	 * user_data argument.
139 	 * data must not be modified after this call is made until free_func has
140 	 * been called to indicate that the bytes is no longer in use.
141 	 * Since 2.32
142 	 * Params:
143 	 * data = the data to be used for the bytes. [array length=size]
144 	 * size = the size of data
145 	 * freeFunc = the function to call to release the data
146 	 * userData = data to pass to free_func
147 	 * Throws: ConstructionException GTK+ fails to create the object.
148 	 */
149 	public this (void* data, gsize size, GDestroyNotify freeFunc, void* userData)
150 	{
151 		// GBytes * g_bytes_new_with_free_func (gconstpointer data,  gsize size,  GDestroyNotify free_func,  gpointer user_data);
152 		auto p = g_bytes_new_with_free_func(data, size, freeFunc, userData);
153 		if(p is null)
154 		{
155 			throw new ConstructionException("null returned by g_bytes_new_with_free_func(data, size, freeFunc, userData)");
156 		}
157 		this(cast(GBytes*) p);
158 	}
159 	
160 	/**
161 	 * Creates a GBytes which is a subsection of another GBytes. The offset +
162 	 * length may not be longer than the size of bytes.
163 	 * A reference to bytes will be held by the newly created GBytes until
164 	 * the byte data is no longer needed.
165 	 * Since 2.32
166 	 * Params:
167 	 * bytes = a GBytes
168 	 * offset = offset which subsection starts at
169 	 * length = length of subsection
170 	 * Throws: ConstructionException GTK+ fails to create the object.
171 	 */
172 	public this (Bytes bytes, gsize offset, gsize length)
173 	{
174 		// GBytes * g_bytes_new_from_bytes (GBytes *bytes,  gsize offset,  gsize length);
175 		auto p = g_bytes_new_from_bytes((bytes is null) ? null : bytes.getBytesStruct(), offset, length);
176 		if(p is null)
177 		{
178 			throw new ConstructionException("null returned by g_bytes_new_from_bytes((bytes is null) ? null : bytes.getBytesStruct(), offset, length)");
179 		}
180 		this(cast(GBytes*) p);
181 	}
182 	
183 	/**
184 	 * Get the byte data in the GBytes. This data should not be modified.
185 	 * This function will always return the same pointer for a given GBytes.
186 	 * Since 2.32
187 	 * Returns: a pointer to the byte data. [transfer none][array length=size][type guint8]
188 	 */
189 	public void[] getData()
190 	{
191 		// gconstpointer g_bytes_get_data (GBytes *bytes,  gsize *size);
192 		gsize size;
193 		auto p = g_bytes_get_data(gBytes, &size);
194 		
195 		if(p is null)
196 		{
197 			return null;
198 		}
199 		
200 		return p[0 .. size];
201 	}
202 	
203 	/**
204 	 * Get the size of the byte data in the GBytes.
205 	 * This function will always return the same value for a given GBytes.
206 	 * Since 2.32
207 	 * Returns: the size
208 	 */
209 	public gsize getSize()
210 	{
211 		// gsize g_bytes_get_size (GBytes *bytes);
212 		return g_bytes_get_size(gBytes);
213 	}
214 	
215 	/**
216 	 * Creates an integer hash code for the byte data in the GBytes.
217 	 * This function can be passed to g_hash_table_new() as the key_equal_func
218 	 * parameter, when using non-NULL GBytes pointers as keys in a GHashTable.
219 	 * Since 2.32
220 	 * Params:
221 	 * bytes = a pointer to a GBytes key. [type GLib.Bytes]
222 	 * Returns: a hash value corresponding to the key.
223 	 */
224 	public static uint hash(void* bytes)
225 	{
226 		// guint g_bytes_hash (gconstpointer bytes);
227 		return g_bytes_hash(bytes);
228 	}
229 	
230 	/**
231 	 * Compares the two GBytes values being pointed to and returns
232 	 * TRUE if they are equal.
233 	 * This function can be passed to g_hash_table_new() as the key_equal_func
234 	 * parameter, when using non-NULL GBytes pointers as keys in a GHashTable.
235 	 * Since 2.32
236 	 * Params:
237 	 * bytes1 = a pointer to a GBytes. [type GLib.Bytes]
238 	 * bytes2 = a pointer to a GBytes to compare with bytes1. [type GLib.Bytes]
239 	 * Returns: TRUE if the two keys match.
240 	 */
241 	public static int equal(void* bytes1, void* bytes2)
242 	{
243 		// gboolean g_bytes_equal (gconstpointer bytes1,  gconstpointer bytes2);
244 		return g_bytes_equal(bytes1, bytes2);
245 	}
246 	
247 	/**
248 	 * Compares the two GBytes values.
249 	 * This function can be used to sort GBytes instances in lexographical order.
250 	 * Since 2.32
251 	 * Params:
252 	 * bytes1 = a pointer to a GBytes. [type GLib.Bytes]
253 	 * bytes2 = a pointer to a GBytes to compare with bytes1. [type GLib.Bytes]
254 	 * Returns: a negative value if bytes2 is lesser, a positive value if bytes2 is greater, and zero if bytes2 is equal to bytes1
255 	 */
256 	public static int compare(void* bytes1, void* bytes2)
257 	{
258 		// gint g_bytes_compare (gconstpointer bytes1,  gconstpointer bytes2);
259 		return g_bytes_compare(bytes1, bytes2);
260 	}
261 	
262 	/**
263 	 * Increase the reference count on bytes.
264 	 * Since 2.32
265 	 * Returns: the GBytes
266 	 */
267 	public Bytes doref()
268 	{
269 		// GBytes * g_bytes_ref (GBytes *bytes);
270 		auto p = g_bytes_ref(gBytes);
271 		
272 		if(p is null)
273 		{
274 			return null;
275 		}
276 		
277 		return new Bytes(cast(GBytes*) p);
278 	}
279 	
280 	/**
281 	 * Releases a reference on bytes. This may result in the bytes being
282 	 * freed.
283 	 * Since 2.32
284 	 */
285 	public void unref()
286 	{
287 		// void g_bytes_unref (GBytes *bytes);
288 		g_bytes_unref(gBytes);
289 	}
290 	
291 	/**
292 	 * Unreferences the bytes, and returns a pointer the same byte data
293 	 * contents.
294 	 * As an optimization, the byte data is returned without copying if this was
295 	 * the last reference to bytes and bytes was created with g_bytes_new(),
296 	 * g_bytes_new_take() or g_byte_array_free_to_bytes(). In all other cases the
297 	 * data is copied.
298 	 * Since 2.32
299 	 * Returns: a pointer to the same byte data, which should be freed with g_free(). [transfer full]
300 	 */
301 	public void[] unrefToData()
302 	{
303 		// gpointer g_bytes_unref_to_data (GBytes *bytes,  gsize *size);
304 		gsize size;
305 		auto p = g_bytes_unref_to_data(gBytes, &size);
306 		
307 		if(p is null)
308 		{
309 			return null;
310 		}
311 		
312 		return p[0 .. size];
313 	}
314 	
315 	/**
316 	 * Unreferences the bytes, and returns a new mutable GByteArray containing
317 	 * the same byte data.
318 	 * As an optimization, the byte data is transferred to the array without copying
319 	 * if this was the last reference to bytes and bytes was created with
320 	 * g_bytes_new(), g_bytes_new_take() or g_byte_array_free_to_bytes(). In all
321 	 * other cases the data is copied.
322 	 * Since 2.32
323 	 * Returns: a new mutable GByteArray containing the same byte data. [transfer full]
324 	 */
325 	public ByteArray unrefToArray()
326 	{
327 		// GByteArray * g_bytes_unref_to_array (GBytes *bytes);
328 		auto p = g_bytes_unref_to_array(gBytes);
329 		
330 		if(p is null)
331 		{
332 			return null;
333 		}
334 		
335 		return new ByteArray(cast(GByteArray*) p);
336 	}
337 }