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