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 = GConverter.html 27 * outPack = gio 28 * outFile = ConverterT 29 * strct = GConverter 30 * realStrct= 31 * ctorStrct= 32 * clss = ConverterT 33 * interf = ConverterIF 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * - TStruct 38 * extend = 39 * implements: 40 * prefixes: 41 * - g_converter_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * omit signals: 46 * imports: 47 * - glib.ErrorG 48 * - glib.GException 49 * structWrap: 50 * module aliases: 51 * local aliases: 52 * overrides: 53 */ 54 55 module gio.ConverterT; 56 57 public import gtkc.giotypes; 58 59 public import gtkc.gio; 60 public import glib.ConstructionException; 61 public import gobject.ObjectG; 62 63 64 public import glib.ErrorG; 65 public import glib.GException; 66 67 68 69 70 /** 71 * GConverter is implemented by objects that convert 72 * binary data in various ways. The conversion can be 73 * stateful and may fail at any place. 74 * 75 * Some example conversions are: character set conversion, 76 * compression, decompression and regular expression 77 * replace. 78 */ 79 public template ConverterT(TStruct) 80 { 81 82 /** the main Gtk struct */ 83 protected GConverter* gConverter; 84 85 86 public GConverter* getConverterTStruct() 87 { 88 return cast(GConverter*)getStruct(); 89 } 90 91 92 /** 93 */ 94 95 /** 96 * This is the main operation used when converting data. It is to be called 97 * multiple times in a loop, and each time it will do some work, i.e. 98 * producing some output (in outbuf) or consuming some input (from inbuf) or 99 * both. If its not possible to do any work an error is returned. 100 * Note that a single call may not consume all input (or any input at all). 101 * Also a call may produce output even if given no input, due to state stored 102 * in the converter producing output. 103 * If any data was either produced or consumed, and then an error happens, then 104 * only the successful conversion is reported and the error is returned on the 105 * next call. 106 * A full conversion loop involves calling this method repeatedly, each time 107 * giving it new input and space output space. When there is no more input 108 * data after the data in inbuf, the flag G_CONVERTER_INPUT_AT_END must be set. 109 * The loop will be (unless some error happens) returning G_CONVERTER_CONVERTED 110 * each time until all data is consumed and all output is produced, then 111 * G_CONVERTER_FINISHED is returned instead. Note, that G_CONVERTER_FINISHED 112 * may be returned even if G_CONVERTER_INPUT_AT_END is not set, for instance 113 * in a decompression converter where the end of data is detectable from the 114 * data (and there might even be other data after the end of the compressed data). 115 * When some data has successfully been converted bytes_read and is set to 116 * the number of bytes read from inbuf, and bytes_written is set to indicate 117 * how many bytes was written to outbuf. If there are more data to output 118 * or consume (i.e. unless the G_CONVERTER_INPUT_AT_END is specified) then 119 * G_CONVERTER_CONVERTED is returned, and if no more data is to be output 120 * then G_CONVERTER_FINISHED is returned. 121 * On error G_CONVERTER_ERROR is returned and error is set accordingly. 122 * Since 2.24 123 * Params: 124 * inbuf = the buffer 125 * containing the data to convert. [array length=inbuf_size][element-type guint8] 126 * outbuf = a buffer to write converted data in. 127 * flags = a GConverterFlags controlling the conversion details 128 * bytesRead = will be set to the number of bytes read from inbuf on success. [out] 129 * bytesWritten = will be set to the number of bytes written to outbuf on success. [out] 130 * Returns: a GConverterResult, G_CONVERTER_ERROR on error. 131 * Throws: GException on failure. 132 */ 133 public GConverterResult convert(void[] inbuf, void[] outbuf, GConverterFlags flags, out gsize bytesRead, out gsize bytesWritten) 134 { 135 // GConverterResult g_converter_convert (GConverter *converter, const void *inbuf, gsize inbuf_size, void *outbuf, gsize outbuf_size, GConverterFlags flags, gsize *bytes_read, gsize *bytes_written, GError **error); 136 GError* err = null; 137 138 auto p = g_converter_convert(getConverterTStruct(), inbuf.ptr, cast(int) inbuf.length, outbuf.ptr, cast(int) outbuf.length, flags, &bytesRead, &bytesWritten, &err); 139 140 if (err !is null) 141 { 142 throw new GException( new ErrorG(err) ); 143 } 144 145 return p; 146 } 147 148 /** 149 * Resets all internal state in the converter, making it behave 150 * as if it was just created. If the converter has any internal 151 * state that would produce output then that output is lost. 152 * Since 2.24 153 */ 154 public void reset() 155 { 156 // void g_converter_reset (GConverter *converter); 157 g_converter_reset(getConverterTStruct()); 158 } 159 }