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