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