Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

error.h

Go to the documentation of this file.
00001 /*********************************************************************
00002 * lescegra                                                           *
00003 *                                                                    *
00004 * http://geeky.kicks-ass.org/projects/lescegra.html                  *
00005 *                                                                    *
00006 * Copyright 2003 by Enno Cramer <uebergeek@web.de>                   *
00007 *                                                                    *
00008 * This library is free software; you can redistribute it and/or      *
00009 * modify it under the terms of the GNU Library General Public        *
00010 * License as published by the Free Software Foundation; either       *
00011 * version 2 of the License, or (at your option) any later version.   *
00012 *                                                                    *
00013 * This library is distributed in the hope that it will be useful,    *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  *
00016 * Library General Public License for more details.                   *
00017 *                                                                    *
00018 * You should have received a copy of the GNU Library General Public  *
00019 * License along with this library; if not, write to the Free         *
00020 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
00021 *********************************************************************/
00022 
00023 #ifndef LSG_ERROR_H
00024 #define LSH_ERROR_H 1
00025 
00026 /**
00027  * \file  error.h
00028  * \brief Error handling
00029  */
00030 
00031 #include <lescegra/util/object.h>
00032 
00033 /**
00034  * \brief Error Message
00035  *
00036  * Encapsulate an error message and the location where it has been reported.
00037  */
00038 typedef struct {
00039     LsgObject super;
00040     char* message;
00041     char* file;
00042     char* method;
00043     int line;
00044 } LsgError;
00045 
00046 /**
00047  * \relates LsgError
00048  * Allocate and initialize a new LsgError instance.
00049  * \note Use the macros \c __FILE__ and \c __LINE__ for \a file and \a line
00050  * respectively.
00051  * @param message   The error message
00052  * @param file      The source file from where the error is reported
00053  * @param method    The method reporting the error
00054  * @param line      The line of the source file where the error is reported
00055  */
00056 LsgError* LsgError_create(const char* message, const char* file, const char* method, int line);
00057 
00058 /**
00059  * \relates LsgError
00060  * Constructor for LsgError.
00061  * @param self      The instance variable
00062  * @param message   The error message
00063  * @param file      The source file from where the error is reported
00064  * @param method    The method reporting the error
00065  * @param line      The line of the source file where the error is reported
00066  */
00067 void LsgError_init(LsgError* self, const char* message, const char* file, const char* method, int line);
00068 
00069 /**
00070  * \relates LsgError
00071  * Convert the error message to a simple string.
00072  * \note The generated string has to be free'd by the caller.
00073  * @param self      The instance variable
00074  * @return a newly allocated string containing the complete error message and
00075  * the location of the error report
00076  */
00077 char* LsgError_toString(LsgError* self);
00078 
00079 /**
00080  * \relates LsgError
00081  * Destructor for LsgError.
00082  * @param self      The instance variable
00083  */
00084 void LsgError_destroy(LsgError* self);
00085 
00086 /**
00087  * \relates LsgError
00088  * Return the number of error currently stored in the global error list.
00089  * @return the number of errors currently stored
00090  */
00091 int LsgError_count(void);
00092 
00093 /**
00094  * \relates LsgError
00095  * Store an error in the global error list.
00096  * @param error     The error to store
00097  */
00098 void LsgError_add(LsgError* error);
00099 
00100 /**
00101  * \relates LsgError
00102  * Create and add an error to the global error list.
00103  * @param file      The source file from where the error is reported
00104  * @param method    The method reporting the error
00105  * @param line      The line of the source file where the error is reported
00106  * @param message   The error message
00107  */
00108 void LsgError_addMessage(const char* file, const char* method, int line, const char* message);
00109 
00110 /**
00111  * \relates LsgError
00112  * Format an error message and add an error to the global error list with.
00113  * @param file      The source file from where the error is reported
00114  * @param method    The method reporting the error
00115  * @param line      The line of the source file where the error is reported
00116  * @param format    The error message template
00117  */
00118 void LsgError_addFormat(const char* file, const char* method, int line, const char* format, ...);
00119 
00120 /**
00121  * \relates LsgError
00122  * Return an error from the global error list.
00123  * @param num       The index of the error in the global error list
00124  * @return the error stored at index \a num in the global error list
00125  * or \c NULL if num is greater than or equal to the value returned by
00126  * \c LsgError_count
00127  */
00128 const LsgError* LsgError_get(int num);
00129 
00130 /**
00131  * \relates LsgError
00132  * Empty the global error list.
00133  */
00134 void LsgError_clear(void);
00135 
00136 #endif

(c) 2003, by Enno Cramer
generated on 13 Jul 2003
lescegra - doxygen