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 private import gtkd.Loader; 32 33 34 /** 35 * The `GError` structure contains information about 36 * an error that has occurred. 37 */ 38 public class ErrorG 39 { 40 /** the main Gtk struct */ 41 protected GError* gError; 42 protected bool ownedRef; 43 44 /** Get the main Gtk struct */ 45 public GError* getErrorGStruct(bool transferOwnership = false) 46 { 47 if (transferOwnership) 48 ownedRef = false; 49 return gError; 50 } 51 52 /** the main Gtk struct as a void* */ 53 protected void* getStruct() 54 { 55 return cast(void*)gError; 56 } 57 58 /** 59 * Sets our main struct and passes it to the parent class. 60 */ 61 public this (GError* gError, bool ownedRef = false) 62 { 63 this.gError = gError; 64 this.ownedRef = ownedRef; 65 } 66 67 ~this () 68 { 69 if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef ) 70 g_error_free(gError); 71 } 72 73 74 /** 75 * Creates a new #GError; unlike g_error_new(), @message is 76 * not a printf()-style format string. Use this function if 77 * @message contains text you don't have control over, 78 * that could include printf() escape sequences. 79 * 80 * Params: 81 * domain = error domain 82 * code = error code 83 * message = error message 84 * 85 * Returns: a new #GError 86 * 87 * Throws: ConstructionException GTK+ fails to create the object. 88 */ 89 public this(GQuark domain, int code, string message) 90 { 91 auto __p = g_error_new_literal(domain, code, Str.toStringz(message)); 92 93 if(__p is null) 94 { 95 throw new ConstructionException("null returned by new_literal"); 96 } 97 98 this(cast(GError*) __p); 99 } 100 101 /** 102 * Creates a new #GError with the given @domain and @code, 103 * and a message formatted with @format. 104 * 105 * Params: 106 * domain = error domain 107 * code = error code 108 * format = printf()-style format for error message 109 * args = #va_list of parameters for the message format 110 * 111 * Returns: a new #GError 112 * 113 * Since: 2.22 114 * 115 * Throws: ConstructionException GTK+ fails to create the object. 116 */ 117 public this(GQuark domain, int code, string format, void* args) 118 { 119 auto __p = g_error_new_valist(domain, code, Str.toStringz(format), args); 120 121 if(__p is null) 122 { 123 throw new ConstructionException("null returned by new_valist"); 124 } 125 126 this(cast(GError*) __p); 127 } 128 129 /** 130 * Makes a copy of @error. 131 * 132 * Returns: a new #GError 133 */ 134 public ErrorG copy() 135 { 136 auto __p = g_error_copy(gError); 137 138 if(__p is null) 139 { 140 return null; 141 } 142 143 return new ErrorG(cast(GError*) __p, true); 144 } 145 146 /** 147 * Frees a #GError and associated resources. 148 */ 149 public void free() 150 { 151 g_error_free(gError); 152 ownedRef = false; 153 } 154 155 /** 156 * Returns %TRUE if @error matches @domain and @code, %FALSE 157 * otherwise. In particular, when @error is %NULL, %FALSE will 158 * be returned. 159 * 160 * If @domain contains a `FAILED` (or otherwise generic) error code, 161 * you should generally not check for it explicitly, but should 162 * instead treat any not-explicitly-recognized error code as being 163 * equivalent to the `FAILED` code. This way, if the domain is 164 * extended in the future to provide a more specific error code for 165 * a certain case, your code will still work. 166 * 167 * Params: 168 * domain = an error domain 169 * code = an error code 170 * 171 * Returns: whether @error has @domain and @code 172 */ 173 public bool matches(GQuark domain, int code) 174 { 175 return g_error_matches(gError, domain, code) != 0; 176 } 177 178 /** 179 * This function registers an extended #GError domain. 180 * @error_type_name will be duplicated. Otherwise does the same as 181 * g_error_domain_register_static(). 182 * 183 * Params: 184 * errorTypeName = string to create a #GQuark from 185 * errorTypePrivateSize = size of the private error data in bytes 186 * errorTypeInit = function initializing fields of the private error data 187 * errorTypeCopy = function copying fields of the private error data 188 * errorTypeClear = function freeing fields of the private error data 189 * 190 * Returns: #GQuark representing the error domain 191 * 192 * Since: 2.68 193 */ 194 public static GQuark domainRegister(string errorTypeName, size_t errorTypePrivateSize, GErrorInitFunc errorTypeInit, GErrorCopyFunc errorTypeCopy, GErrorClearFunc errorTypeClear) 195 { 196 return g_error_domain_register(Str.toStringz(errorTypeName), errorTypePrivateSize, errorTypeInit, errorTypeCopy, errorTypeClear); 197 } 198 199 /** 200 * This function registers an extended #GError domain. 201 * 202 * @error_type_name should not be freed. @error_type_private_size must 203 * be greater than 0. 204 * 205 * @error_type_init receives an initialized #GError and should then initialize 206 * the private data. 207 * 208 * @error_type_copy is a function that receives both original and a copy 209 * #GError and should copy the fields of the private error data. The standard 210 * #GError fields are already handled. 211 * 212 * @error_type_clear receives the pointer to the error, and it should free the 213 * fields of the private error data. It should not free the struct itself though. 214 * 215 * Normally, it is better to use G_DEFINE_EXTENDED_ERROR(), as it 216 * already takes care of passing valid information to this function. 217 * 218 * Params: 219 * errorTypeName = static string to create a #GQuark from 220 * errorTypePrivateSize = size of the private error data in bytes 221 * errorTypeInit = function initializing fields of the private error data 222 * errorTypeCopy = function copying fields of the private error data 223 * errorTypeClear = function freeing fields of the private error data 224 * 225 * Returns: #GQuark representing the error domain 226 * 227 * Since: 2.68 228 */ 229 public static GQuark domainRegisterStatic(string errorTypeName, size_t errorTypePrivateSize, GErrorInitFunc errorTypeInit, GErrorCopyFunc errorTypeCopy, GErrorClearFunc errorTypeClear) 230 { 231 return g_error_domain_register_static(Str.toStringz(errorTypeName), errorTypePrivateSize, errorTypeInit, errorTypeCopy, errorTypeClear); 232 } 233 234 /** 235 * If @dest is %NULL, free @src; otherwise, moves @src into *@dest. 236 * The error variable @dest points to must be %NULL. 237 * 238 * @src must be non-%NULL. 239 * 240 * Note that @src is no longer valid after this call. If you want 241 * to keep using the same GError*, you need to set it to %NULL 242 * after calling this function on it. 243 * 244 * Params: 245 * dest = error return location 246 * src = error to move into the return location 247 */ 248 public static void propagateError(out ErrorG dest, ErrorG src) 249 { 250 GError* outdest = null; 251 252 g_propagate_error(&outdest, (src is null) ? null : src.getErrorGStruct(true)); 253 254 dest = new ErrorG(outdest); 255 } 256 257 /** 258 * Does nothing if @err is %NULL; if @err is non-%NULL, then *@err 259 * must be %NULL. A new #GError is created and assigned to *@err. 260 * Unlike g_set_error(), @message is not a printf()-style format string. 261 * Use this function if @message contains text you don't have control over, 262 * that could include printf() escape sequences. 263 * 264 * Params: 265 * err = a return location for a #GError 266 * domain = error domain 267 * code = error code 268 * message = error message 269 * 270 * Since: 2.18 271 */ 272 public static void setErrorLiteral(out ErrorG err, GQuark domain, int code, string message) 273 { 274 GError* outerr = null; 275 276 g_set_error_literal(&outerr, domain, code, Str.toStringz(message)); 277 278 err = new ErrorG(outerr); 279 } 280 }