source: appstream-generator/build/girepo/gio/ConverterT.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 7.3 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.ConverterT;
22
23public  import gi.gio;
24public  import gi.giotypes;
25public  import glib.ErrorG;
26public  import glib.GException;
27
28
29/**
30 * #GConverter is implemented by objects that convert
31 * binary data in various ways. The conversion can be
32 * stateful and may fail at any place.
33 *
34 * Some example conversions are: character set conversion,
35 * compression, decompression and regular expression
36 * replace.
37 *
38 * Since: 2.24
39 */
40public template ConverterT(TStruct)
41{
42        /** Get the main Gtk struct */
43        public GConverter* getConverterStruct()
44        {
45                return cast(GConverter*)getStruct();
46        }
47
48
49        /**
50         * This is the main operation used when converting data. It is to be called
51         * multiple times in a loop, and each time it will do some work, i.e.
52         * producing some output (in @outbuf) or consuming some input (from @inbuf) or
53         * both. If its not possible to do any work an error is returned.
54         *
55         * Note that a single call may not consume all input (or any input at all).
56         * Also a call may produce output even if given no input, due to state stored
57         * in the converter producing output.
58         *
59         * If any data was either produced or consumed, and then an error happens, then
60         * only the successful conversion is reported and the error is returned on the
61         * next call.
62         *
63         * A full conversion loop involves calling this method repeatedly, each time
64         * giving it new input and space output space. When there is no more input
65         * data after the data in @inbuf, the flag %G_CONVERTER_INPUT_AT_END must be set.
66         * The loop will be (unless some error happens) returning %G_CONVERTER_CONVERTED
67         * each time until all data is consumed and all output is produced, then
68         * %G_CONVERTER_FINISHED is returned instead. Note, that %G_CONVERTER_FINISHED
69         * may be returned even if %G_CONVERTER_INPUT_AT_END is not set, for instance
70         * in a decompression converter where the end of data is detectable from the
71         * data (and there might even be other data after the end of the compressed data).
72         *
73         * When some data has successfully been converted @bytes_read and is set to
74         * the number of bytes read from @inbuf, and @bytes_written is set to indicate
75         * how many bytes was written to @outbuf. If there are more data to output
76         * or consume (i.e. unless the %G_CONVERTER_INPUT_AT_END is specified) then
77         * %G_CONVERTER_CONVERTED is returned, and if no more data is to be output
78         * then %G_CONVERTER_FINISHED is returned.
79         *
80         * On error %G_CONVERTER_ERROR is returned and @error is set accordingly.
81         * Some errors need special handling:
82         *
83         * %G_IO_ERROR_NO_SPACE is returned if there is not enough space
84         * to write the resulting converted data, the application should
85         * call the function again with a larger @outbuf to continue.
86         *
87         * %G_IO_ERROR_PARTIAL_INPUT is returned if there is not enough
88         * input to fully determine what the conversion should produce,
89         * and the %G_CONVERTER_INPUT_AT_END flag is not set. This happens for
90         * example with an incomplete multibyte sequence when converting text,
91         * or when a regexp matches up to the end of the input (and may match
92         * further input). It may also happen when @inbuf_size is zero and
93         * there is no more data to produce.
94         *
95         * When this happens the application should read more input and then
96         * call the function again. If further input shows that there is no
97         * more data call the function again with the same data but with
98         * the %G_CONVERTER_INPUT_AT_END flag set. This may cause the conversion
99         * to finish as e.g. in the regexp match case (or, to fail again with
100         * %G_IO_ERROR_PARTIAL_INPUT in e.g. a charset conversion where the
101         * input is actually partial).
102         *
103         * After g_converter_convert() has returned %G_CONVERTER_FINISHED the
104         * converter object is in an invalid state where its not allowed
105         * to call g_converter_convert() anymore. At this time you can only
106         * free the object or call g_converter_reset() to reset it to the
107         * initial state.
108         *
109         * If the flag %G_CONVERTER_FLUSH is set then conversion is modified
110         * to try to write out all internal state to the output. The application
111         * has to call the function multiple times with the flag set, and when
112         * the available input has been consumed and all internal state has
113         * been produced then %G_CONVERTER_FLUSHED (or %G_CONVERTER_FINISHED if
114         * really at the end) is returned instead of %G_CONVERTER_CONVERTED.
115         * This is somewhat similar to what happens at the end of the input stream,
116         * but done in the middle of the data.
117         *
118         * This has different meanings for different conversions. For instance
119         * in a compression converter it would mean that we flush all the
120         * compression state into output such that if you uncompress the
121         * compressed data you get back all the input data. Doing this may
122         * make the final file larger due to padding though. Another example
123         * is a regexp conversion, where if you at the end of the flushed data
124         * have a match, but there is also a potential longer match. In the
125         * non-flushed case we would ask for more input, but when flushing we
126         * treat this as the end of input and do the match.
127         *
128         * Flushing is not always possible (like if a charset converter flushes
129         * at a partial multibyte sequence). Converters are supposed to try
130         * to produce as much output as possible and then return an error
131         * (typically %G_IO_ERROR_PARTIAL_INPUT).
132         *
133         * Params:
134         *     inbuf = the buffer
135         *         containing the data to convert.
136         *     inbufSize = the number of bytes in @inbuf
137         *     outbuf = a buffer to write converted data in.
138         *     outbufSize = the number of bytes in @outbuf, must be at least one
139         *     flags = a #GConverterFlags controlling the conversion details
140         *     bytesRead = will be set to the number of bytes read from @inbuf on success
141         *     bytesWritten = will be set to the number of bytes written to @outbuf on success
142         *
143         * Returns: a #GConverterResult, %G_CONVERTER_ERROR on error.
144         *
145         * Since: 2.24
146         *
147         * Throws: GException on failure.
148         */
149        public GConverterResult convert(ubyte[] inbuf, void* outbuf, size_t outbufSize, GConverterFlags flags, out size_t bytesRead, out size_t bytesWritten)
150        {
151                GError* err = null;
152               
153                auto p = g_converter_convert(getConverterStruct(), inbuf.ptr, cast(size_t)inbuf.length, outbuf, outbufSize, flags, &bytesRead, &bytesWritten, &err);
154               
155                if (err !is null)
156                {
157                        throw new GException( new ErrorG(err) );
158                }
159               
160                return p;
161        }
162
163        /**
164         * Resets all internal state in the converter, making it behave
165         * as if it was just created. If the converter has any internal
166         * state that would produce output then that output is lost.
167         *
168         * Since: 2.24
169         */
170        public void reset()
171        {
172                g_converter_reset(getConverterStruct());
173        }
174}
Note: See TracBrowser for help on using the repository browser.