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.ConverterIF; 26 27 private import glib.ErrorG; 28 private import glib.GException; 29 private import gtkc.gio; 30 public import gtkc.giotypes; 31 32 33 /** 34 * #GConverter is implemented by objects that convert 35 * binary data in various ways. The conversion can be 36 * stateful and may fail at any place. 37 * 38 * Some example conversions are: character set conversion, 39 * compression, decompression and regular expression 40 * replace. 41 * 42 * Since: 2.24 43 */ 44 public interface ConverterIF{ 45 /** Get the main Gtk struct */ 46 public GConverter* getConverterStruct(); 47 48 /** the main Gtk struct as a void* */ 49 protected void* getStruct(); 50 51 52 /** 53 * This is the main operation used when converting data. It is to be called 54 * multiple times in a loop, and each time it will do some work, i.e. 55 * producing some output (in @outbuf) or consuming some input (from @inbuf) or 56 * both. If its not possible to do any work an error is returned. 57 * 58 * Note that a single call may not consume all input (or any input at all). 59 * Also a call may produce output even if given no input, due to state stored 60 * in the converter producing output. 61 * 62 * If any data was either produced or consumed, and then an error happens, then 63 * only the successful conversion is reported and the error is returned on the 64 * next call. 65 * 66 * A full conversion loop involves calling this method repeatedly, each time 67 * giving it new input and space output space. When there is no more input 68 * data after the data in @inbuf, the flag %G_CONVERTER_INPUT_AT_END must be set. 69 * The loop will be (unless some error happens) returning %G_CONVERTER_CONVERTED 70 * each time until all data is consumed and all output is produced, then 71 * %G_CONVERTER_FINISHED is returned instead. Note, that %G_CONVERTER_FINISHED 72 * may be returned even if %G_CONVERTER_INPUT_AT_END is not set, for instance 73 * in a decompression converter where the end of data is detectable from the 74 * data (and there might even be other data after the end of the compressed data). 75 * 76 * When some data has successfully been converted @bytes_read and is set to 77 * the number of bytes read from @inbuf, and @bytes_written is set to indicate 78 * how many bytes was written to @outbuf. If there are more data to output 79 * or consume (i.e. unless the %G_CONVERTER_INPUT_AT_END is specified) then 80 * %G_CONVERTER_CONVERTED is returned, and if no more data is to be output 81 * then %G_CONVERTER_FINISHED is returned. 82 * 83 * On error %G_CONVERTER_ERROR is returned and @error is set accordingly. 84 * Some errors need special handling: 85 * 86 * %G_IO_ERROR_NO_SPACE is returned if there is not enough space 87 * to write the resulting converted data, the application should 88 * call the function again with a larger @outbuf to continue. 89 * 90 * %G_IO_ERROR_PARTIAL_INPUT is returned if there is not enough 91 * input to fully determine what the conversion should produce, 92 * and the %G_CONVERTER_INPUT_AT_END flag is not set. This happens for 93 * example with an incomplete multibyte sequence when converting text, 94 * or when a regexp matches up to the end of the input (and may match 95 * further input). It may also happen when @inbuf_size is zero and 96 * there is no more data to produce. 97 * 98 * When this happens the application should read more input and then 99 * call the function again. If further input shows that there is no 100 * more data call the function again with the same data but with 101 * the %G_CONVERTER_INPUT_AT_END flag set. This may cause the conversion 102 * to finish as e.g. in the regexp match case (or, to fail again with 103 * %G_IO_ERROR_PARTIAL_INPUT in e.g. a charset conversion where the 104 * input is actually partial). 105 * 106 * After g_converter_convert() has returned %G_CONVERTER_FINISHED the 107 * converter object is in an invalid state where its not allowed 108 * to call g_converter_convert() anymore. At this time you can only 109 * free the object or call g_converter_reset() to reset it to the 110 * initial state. 111 * 112 * If the flag %G_CONVERTER_FLUSH is set then conversion is modified 113 * to try to write out all internal state to the output. The application 114 * has to call the function multiple times with the flag set, and when 115 * the available input has been consumed and all internal state has 116 * been produced then %G_CONVERTER_FLUSHED (or %G_CONVERTER_FINISHED if 117 * really at the end) is returned instead of %G_CONVERTER_CONVERTED. 118 * This is somewhat similar to what happens at the end of the input stream, 119 * but done in the middle of the data. 120 * 121 * This has different meanings for different conversions. For instance 122 * in a compression converter it would mean that we flush all the 123 * compression state into output such that if you uncompress the 124 * compressed data you get back all the input data. Doing this may 125 * make the final file larger due to padding though. Another example 126 * is a regexp conversion, where if you at the end of the flushed data 127 * have a match, but there is also a potential longer match. In the 128 * non-flushed case we would ask for more input, but when flushing we 129 * treat this as the end of input and do the match. 130 * 131 * Flushing is not always possible (like if a charset converter flushes 132 * at a partial multibyte sequence). Converters are supposed to try 133 * to produce as much output as possible and then return an error 134 * (typically %G_IO_ERROR_PARTIAL_INPUT). 135 * 136 * Params: 137 * inbuf = the buffer 138 * containing the data to convert. 139 * inbufSize = the number of bytes in @inbuf 140 * outbuf = a buffer to write 141 * converted data in. 142 * outbufSize = the number of bytes in @outbuf, must be at least one 143 * flags = a #GConverterFlags controlling the conversion details 144 * bytesRead = will be set to the number of bytes read from @inbuf on success 145 * bytesWritten = will be set to the number of bytes written to @outbuf on success 146 * 147 * Return: a #GConverterResult, %G_CONVERTER_ERROR on error. 148 * 149 * Since: 2.24 150 * 151 * Throws: GException on failure. 152 */ 153 public GConverterResult convert(ubyte[] inbuf, ubyte[] outbuf, GConverterFlags flags, out size_t bytesRead, out size_t bytesWritten); 154 155 /** 156 * Resets all internal state in the converter, making it behave 157 * as if it was just created. If the converter has any internal 158 * state that would produce output then that output is lost. 159 * 160 * Since: 2.24 161 */ 162 public void reset(); 163 }