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 glib.ErrorG;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gtkc.glib;
30 public  import gtkc.glibtypes;
31 
32 
33 /**
34  * The `GError` structure contains information about
35  * an error that has occurred.
36  */
37 public class ErrorG
38 {
39 	/** the main Gtk struct */
40 	protected GError* gError;
41 
42 	/** Get the main Gtk struct */
43 	public GError* getErrorGStruct()
44 	{
45 		return gError;
46 	}
47 
48 	/** the main Gtk struct as a void* */
49 	protected void* getStruct()
50 	{
51 		return cast(void*)gError;
52 	}
53 
54 	/**
55 	 * Sets our main struct and passes it to the parent class.
56 	 */
57 	public this (GError* gError)
58 	{
59 		this.gError = gError;
60 	}
61 
62 	/**
63 	 */
64 
65 	/**
66 	 * Creates a new #GError; unlike g_error_new(), @message is
67 	 * not a printf()-style format string. Use this function if
68 	 * @message contains text you don't have control over,
69 	 * that could include printf() escape sequences.
70 	 *
71 	 * Params:
72 	 *     domain = error domain
73 	 *     code = error code
74 	 *     message = error message
75 	 *
76 	 * Return: a new #GError
77 	 *
78 	 * Throws: ConstructionException GTK+ fails to create the object.
79 	 */
80 	public this(GQuark domain, int code, string message)
81 	{
82 		auto p = g_error_new_literal(domain, code, Str.toStringz(message));
83 		
84 		if(p is null)
85 		{
86 			throw new ConstructionException("null returned by new_literal");
87 		}
88 		
89 		this(cast(GError*) p);
90 	}
91 
92 	/**
93 	 * Creates a new #GError with the given @domain and @code,
94 	 * and a message formatted with @format.
95 	 *
96 	 * Params:
97 	 *     domain = error domain
98 	 *     code = error code
99 	 *     format = printf()-style format for error message
100 	 *     args = #va_list of parameters for the message format
101 	 *
102 	 * Return: a new #GError
103 	 *
104 	 * Since: 2.22
105 	 *
106 	 * Throws: ConstructionException GTK+ fails to create the object.
107 	 */
108 	public this(GQuark domain, int code, string format, void* args)
109 	{
110 		auto p = g_error_new_valist(domain, code, Str.toStringz(format), args);
111 		
112 		if(p is null)
113 		{
114 			throw new ConstructionException("null returned by new_valist");
115 		}
116 		
117 		this(cast(GError*) p);
118 	}
119 
120 	/**
121 	 * Makes a copy of @error.
122 	 *
123 	 * Return: a new #GError
124 	 */
125 	public ErrorG copy()
126 	{
127 		auto p = g_error_copy(gError);
128 		
129 		if(p is null)
130 		{
131 			return null;
132 		}
133 		
134 		return new ErrorG(cast(GError*) p);
135 	}
136 
137 	/**
138 	 * Frees a #GError and associated resources.
139 	 */
140 	public void free()
141 	{
142 		g_error_free(gError);
143 	}
144 
145 	/**
146 	 * Returns %TRUE if @error matches @domain and @code, %FALSE
147 	 * otherwise. In particular, when @error is %NULL, %FALSE will
148 	 * be returned.
149 	 *
150 	 * If @domain contains a `FAILED` (or otherwise generic) error code,
151 	 * you should generally not check for it explicitly, but should
152 	 * instead treat any not-explicitly-recognized error code as being
153 	 * equilalent to the `FAILED` code. This way, if the domain is
154 	 * extended in the future to provide a more specific error code for
155 	 * a certain case, your code will still work.
156 	 *
157 	 * Params:
158 	 *     domain = an error domain
159 	 *     code = an error code
160 	 *
161 	 * Return: whether @error has @domain and @code
162 	 */
163 	public bool matches(GQuark domain, int code)
164 	{
165 		return g_error_matches(gError, domain, code) != 0;
166 	}
167 
168 	/**
169 	 * If @dest is %NULL, free @src; otherwise, moves @src into *@dest.
170 	 * The error variable @dest points to must be %NULL.
171 	 *
172 	 * Note that @src is no longer valid after this call. If you want
173 	 * to keep using the same GError*, you need to set it to %NULL
174 	 * after calling this function on it.
175 	 *
176 	 * Params:
177 	 *     dest = error return location
178 	 *     src = error to move into the return location
179 	 */
180 	public static void propagateError(out ErrorG dest, ErrorG src)
181 	{
182 		GError* outdest = null;
183 		
184 		g_propagate_error(&outdest, (src is null) ? null : src.getErrorGStruct());
185 		
186 		dest = new ErrorG(outdest);
187 	}
188 
189 	/**
190 	 * Does nothing if @err is %NULL; if @err is non-%NULL, then *@err
191 	 * must be %NULL. A new #GError is created and assigned to *@err.
192 	 * Unlike g_set_error(), @message is not a printf()-style format string.
193 	 * Use this function if @message contains text you don't have control over,
194 	 * that could include printf() escape sequences.
195 	 *
196 	 * Params:
197 	 *     err = a return location for a #GError, or %NULL
198 	 *     domain = error domain
199 	 *     code = error code
200 	 *     message = error message
201 	 *
202 	 * Since: 2.18
203 	 */
204 	public static void setErrorLiteral(out ErrorG err, GQuark domain, int code, string message)
205 	{
206 		GError* outerr = null;
207 		
208 		g_set_error_literal(&outerr, domain, code, Str.toStringz(message));
209 		
210 		err = new ErrorG(outerr);
211 	}
212 }