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