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