PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // PLearn (A C++ Machine Learning Library) 00004 // Copyright (C) 1998 Pascal Vincent 00005 // Copyright (C) 1999-2002 Pascal Vincent, Yoshua Bengio and University of Montreal 00006 // 00007 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 00037 00038 00039 /* ******************************************************* 00040 * $Id: plerror.h 9705 2008-11-20 20:12:05Z nouiz $ 00041 * AUTHORS: Pascal Vincent & Yoshua Bengio 00042 * This file is part of the PLearn library. 00043 ******************************************************* */ 00044 00045 00048 #ifndef perror_INC 00049 #define perror_INC 00050 00051 #include <string> 00052 #include "plexceptions.h" 00053 #include <cstdarg> 00054 00055 #ifndef __GNUC__ 00056 // Suppress __attribute__(()) GCC extension on other compilers. 00057 #define __attribute__(x) 00058 #endif 00059 00060 00061 namespace PLearn { 00062 00063 #ifndef USE_EXCEPTIONS 00064 extern ostream* error_stream; 00065 #endif 00066 00067 //#define PLERROR errormsg //Use if the compiler don't like variadic macros 00068 #define PLERROR(...) errormsg2(__FILE__,__LINE__,__VA_ARGS__) 00069 #define PLWARNING warningmsg 00070 #define PLDEPRECATED deprecationmsg 00071 //#define PLWARN_ERR warn_err //Use if the compiler don't like variadic macros 00072 #define PLWARN_ERR(...) warn_err2(__FILE__,__LINE__,__VA_ARGS__) 00073 00074 void errormsg2(const char* filename, const int linenumber, const char* msg, ...) 00075 __attribute__((noreturn)) 00076 __attribute__((format(printf, 3, 4))); 00077 //errormsg: version that takes a variable number of args 00078 void errormsg(const char* msg, ...) 00079 __attribute__((noreturn)) 00080 __attribute__((format(printf, 1, 2))); 00081 //verrormsg: internal errormsg that takes a single va_list 00082 void verrormsg(const char* msg, va_list args) 00083 __attribute__((noreturn)); 00084 void warningmsg(const char* msg, ...) 00085 __attribute__((format(printf, 1, 2))); 00086 //vwarningmsg: internal warningmsg that takes a single va_list 00087 void vwarningmsg(const char* msg, va_list args); 00088 void warn_err(bool warn, const char* msg, ...) 00089 __attribute__((format(printf, 2, 3))); 00090 void warn_err2(const char* filename, const int linenumber, bool warn, const char* msg,...) 00091 __attribute__((format(printf, 4, 5))); 00092 void deprecationmsg(const char* msg, ...) 00093 __attribute__((format(printf, 1, 2))); 00094 void exitmsg(const char* msg, ...) 00095 __attribute__((noreturn)) 00096 __attribute__((format(printf, 1, 2))); 00097 void pl_assert_fail(const char* expr, const char* file, unsigned line, 00098 const char* function, const std::string& message) 00099 __attribute__((noreturn)); 00100 void pl_check_fail(const char* expr, const char* file, unsigned line, 00101 const char* function, const std::string& message) 00102 __attribute__((noreturn)); 00103 00104 // Redefine the assert mechanism to throw an exception through PLERROR. 00105 // The following macros are defined: 00106 // 00107 // 1) PLASSERT: same syntax as standard assert(), but throws exception 00108 // 00109 // 2) PLASSERT_MSG: accepts a second argument (std::string) which indicates 00110 // a cause for the assertion failure. If one needs to 00111 // perform complex formatting on that string (substitute 00112 // variables, etc.), it is recommended to use the Boost 00113 // 'format' library. 00114 00115 // When debugging, do nothing (do static cast as in GCC) 00116 #ifdef NDEBUG 00117 00118 # define PLASSERT(expr) static_cast<void>(0) 00119 # define PLASSERT_MSG(expr, message) static_cast<void>(0) 00120 00121 #else // ! defined(NDEBUG) 00122 00123 # define PLASSERT(expr) \ 00124 static_cast<void>((expr) ? 0 : \ 00125 (PLearn::pl_assert_fail(#expr, __FILE__, __LINE__, \ 00126 PL_ASSERT_FUNCTION, ""), 0)) 00127 00128 # define PLASSERT_MSG(expr, message) \ 00129 static_cast<void>((expr) ? 0 : \ 00130 (PLearn::pl_assert_fail(#expr, __FILE__, __LINE__, \ 00131 PL_ASSERT_FUNCTION, (message)), 0)) 00132 00133 # define PL_ASSERT_DEFINED 00134 00135 #endif // NDEBUG 00136 00137 // Similarly, define PLCHECK mechanism to perform some checks. These checks 00138 // will be done even if NDEBUG is defined. 00139 00140 # define PLCHECK(expr) \ 00141 static_cast<void>((expr) ? 0 : \ 00142 (PLearn::pl_check_fail(#expr, __FILE__, __LINE__, \ 00143 PL_ASSERT_FUNCTION, ""), 0)) 00144 00145 # define PLCHECK_MSG(expr, message) \ 00146 static_cast<void>((expr) ? 0 : \ 00147 (PLearn::pl_check_fail(#expr, __FILE__, __LINE__, \ 00148 PL_ASSERT_FUNCTION, (message)), 0)) 00149 00150 # define PL_ASSERT_DEFINED 00151 00152 00153 // Use the function prettification code present in GCC's assert.h include 00154 #if defined __USE_GNU 00155 # define PL_ASSERT_FUNCTION __PRETTY_FUNCTION__ 00156 #else 00157 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L 00158 # define PL_ASSERT_FUNCTION __func__ 00159 # else 00160 # define PL_ASSERT_FUNCTION ((__const char *) 0) 00161 # endif 00162 #endif 00163 00164 00165 } // end of namespace PLearn 00166 00167 #endif 00168 00169 00170 /* 00171 Local Variables: 00172 mode:c++ 00173 c-basic-offset:4 00174 c-file-style:"stroustrup" 00175 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00176 indent-tabs-mode:nil 00177 fill-column:79 00178 End: 00179 */ 00180 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :