polylib: arithmetic_errors.h Source File

- Main Page
- Classes
- Files

- File List
- File Members

# arithmetic_errors.h

Go to the documentation of this file.

    00001 /*
    00002     This file is part of PolyLib.
    00003
    00004     PolyLib is free software: you can redistribute it and/or modify
    00005     it under the terms of the GNU General Public License as published by
    00006     the Free Software Foundation, either version 3 of the License, or
    00007     (at your option) any later version.
    00008
    00009     PolyLib is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012     GNU General Public License for more details.
    00013
    00014     You should have received a copy of the GNU General Public License
    00015     along with PolyLib.  If not, see <http://www.gnu.org/licenses/>.
    00016 */
    00017
    00018 /*
    00019  * $Id: arithmetic_errors.h,v 1.4 2006/03/15 19:59:37 verdoolaege Exp $
    00020  *
    00021  * managing arithmetic errors...
    00022  * detecting and managing arithmetic errors on Values should be
    00023  * systematic. These macros gives a C++ look and feel to this
    00024  * management.
    00025  *
    00026  * (c) CA et FC, Sept 1997
    00027  *
    00028  * $Log: arithmetic_errors.h,v $
    00029  * Revision 1.4  2006/03/15 19:59:37  verdoolaege
    00030  * arith: add some missing consts
    00031  *
    00032  * Revision 1.3  2004/02/08 21:53:27  kienhuis
    00033  * Update from Fabien Coelho, via Bart Kienhuis
    00034  *
    00035  * I've updated here in the C3/Linear library the arithmetic_error
    00036  * package that I developped (with others) to handle exceptions in C.
    00037  * It adds a simple callback feature which is needed for pips here.
    00038  * If you do not use it, it should not harm;-)
    00039  *
    00040  * Revision 1.34  2003/09/03 13:59:46  coelho
    00041  * ++
    00042  *
    00043  * Revision 1.33  2003/09/03 13:35:34  coelho
    00044  * no more callback.
    00045  *
    00046  * Revision 1.32  2003/08/18 14:55:38  coelho
    00047  * callback fix.
    00048  *
    00049  * Revision 1.31  2003/08/18 14:16:45  coelho
    00050  * NULL callback added.
    00051  *
    00052  * Revision 1.30  2003/06/13 13:59:55  coelho
    00053  * hop.
    00054  *
    00055  * Revision 1.29  2000/07/27 15:01:55  coelho
    00056  * hop.
    00057  *
    00058  * Revision 1.28  2000/07/26 09:11:58  coelho
    00059  * hop.
    00060  *
    00061  * Revision 1.27  2000/07/26 09:07:32  coelho
    00062  * *** empty log message ***
    00063  *
    00064  * Revision 1.26  2000/07/26 09:06:32  coelho
    00065  * the_last_just_thrown_exception declared.
    00066  *
    00067  * Revision 1.25  2000/07/26 08:41:40  coelho
    00068  * RETHROW added.
    00069  *
    00070  * Revision 1.24  1998/10/26 14:37:48  coelho
    00071  * constants moved out.
    00072  *
    00073  * Revision 1.23  1998/10/26 14:36:13  coelho
    00074  * constants explicitely defined in .h.
    00075  *
    00076  * Revision 1.22  1998/10/24 15:18:26  coelho
    00077  * THROW macro updated to tell its source.
    00078  *
    00079  * Revision 1.21  1998/10/24 14:33:08  coelho
    00080  * parser exception added.
    00081  *
    00082  * Revision 1.20  1998/10/24 14:32:45  coelho
    00083  * simpler macros.
    00084  *
    00085  * Revision 1.19  1998/10/24 09:22:47  coelho
    00086  * size update.
    00087  *
    00088  * Revision 1.18  1998/10/24 09:21:45  coelho
    00089  * const added to constants.
    00090  *
    00091  */
    00092
    00093 #if !defined(linear_arithmetic_error_included)
    00094 #define linear_arithmetic_error_included
    00095
    00096 #include <setjmp.h>
    00097
    00098 typedef void (*exception_callback_t)(const char *, const char *, int);
    00099
    00100 /*
    00101 const unsigned int overflow_error = 1;
    00102 const unsigned int simplex_arithmetic_error = 2;
    00103 const unsigned int user_exception_error = 4;
    00104 const unsigned int parser_exception_error = 8;
    00105 const unsigned int any_exception_error = ~0;
    00106 */
    00107
    00108 /* use gnu cpp '__FUNCTION__' extension if possible.
    00109  */
    00110 #if defined(__GNUC__)
    00111 #define __CURRENT_FUNCTION_NAME__ __FUNCTION__
    00112 #else
    00113 #define __CURRENT_FUNCTION_NAME__ "<unknown>"
    00114 #endif
    00115
    00116 /* 'const' out because of cproto 4.6. FC 13/06/2003 */
    00117 #define EXCEPTION extern unsigned int
    00118
    00119 #define THROW(what) \
    00120    (throw_exception(what, __CURRENT_FUNCTION_NAME__, __FILE__, __LINE__))
    00121
    00122 #define CATCH(what)                                                     \
    00123    if (setjmp(*push_exception_on_stack(what, __CURRENT_FUNCTION_NAME__, \
    00124                                      __FILE__, __LINE__)))
    00125
    00126 #define UNCATCH(what)                                           \
    00127      (pop_exception_from_stack(what, __CURRENT_FUNCTION_NAME__, \
    00128                                __FILE__, __LINE__))
    00129
    00130 #define TRY else
    00131
    00132 extern unsigned int the_last_just_thrown_exception;
    00133 #define RETHROW() THROW(the_last_just_thrown_exception)
    00134
    00135 #endif /* linear_arithmetic_error_included */
    00136
    00137 /* end of it.
    00138  */