uves_error.h

00001 /*
00002  * This file is part of the ESO UVES Pipeline
00003  * Copyright (C) 2004,2005 European Southern Observatory
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00018  */
00019 
00020 /*
00021  * $Author: jmlarsen $
00022  * $Date: 2007/08/21 11:08:10 $
00023  * $Revision: 1.56 $
00024  * $Name: uves-3_4_5 $
00025  * $Log: uves_error.h,v $
00026  * Revision 1.56  2007/08/21 11:08:10  jmlarsen
00027  * Readded checks for pre-existing error which was provided by irplib_error_assure but not by cpl_error_ensure
00028  *
00029  * Revision 1.55  2007/08/13 12:15:58  amodigli
00030  * support of CPL4
00031  *
00032  * Revision 1.54  2007/06/06 08:17:33  amodigli
00033  * replace tab with 4 spaces
00034  *
00035  * Revision 1.53  2007/01/08 16:58:52  amodigli
00036  * added ck0 and cknull
00037  *
00038  * Revision 1.52  2006/11/06 15:19:41  jmlarsen
00039  * Removed unused include directives
00040  *
00041  * Revision 1.51  2006/08/17 13:56:52  jmlarsen
00042  * Reduced max line length
00043  *
00044  * Revision 1.50  2006/06/01 14:43:17  jmlarsen
00045  * Added missing documentation
00046  *
00047  * Revision 1.49  2006/05/05 13:54:11  jmlarsen
00048  * Added assure_mem
00049  *
00050  * Revision 1.48  2006/04/24 09:19:25  jmlarsen
00051  * Minor message change
00052  *
00053  * Revision 1.47  2006/04/06 08:31:52  jmlarsen
00054  * Dump trace on CPL_MSG_ERROR level
00055  *
00056  * Revision 1.46  2006/03/09 10:57:57  jmlarsen
00057  * Added check_nomsg macro
00058  *
00059  * Revision 1.45  2006/03/03 13:54:11  jmlarsen
00060  * Changed syntax of check macro
00061  *
00062  * Revision 1.44  2006/02/28 09:15:22  jmlarsen
00063  * Minor update
00064  *
00065  * Revision 1.43  2006/02/23 16:07:59  jmlarsen
00066  * Using irplib_assert_msg
00067  *
00068  * Revision 1.42  2006/02/21 14:26:54  jmlarsen
00069  * Minor changes
00070  *
00071  * Revision 1.41  2006/02/08 07:52:16  jmlarsen
00072  * Added function returning library version
00073  *
00074  * Revision 1.40  2006/02/03 07:46:30  jmlarsen
00075  * Moved recipe implementations to ./uves directory
00076  *
00077  * Revision 1.39  2006/01/24 07:49:31  jmlarsen
00078  * Removed spaces between backslash and newline
00079  *
00080  * Revision 1.38  2006/01/23 08:08:53  jmlarsen
00081  * Updated documentation
00082  *
00083  * Revision 1.37  2005/12/19 16:17:56  jmlarsen
00084  * Replaced bool -> int
00085  *
00086  */
00087 
00088 #ifndef UVES_ERROR_H
00089 #define UVES_ERROR_H
00090 
00091 /*----------------------------------------------------------------------------*/
00095 /*----------------------------------------------------------------------------*/
00098 /*-----------------------------------------------------------------------------
00099                     Includes
00100  -----------------------------------------------------------------------------*/
00101 #include <uves_utils.h>
00102 #include <uves_msg.h>
00103 
00104 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE < CPL_VERSION(4, 0, 0)
00105 #include <irplib_error.h>
00106 #endif
00107 
00108 #include <cpl_error.h>
00109 
00110 /*-----------------------------------------------------------------------------
00111                              Defines
00112  -----------------------------------------------------------------------------*/
00113 /* To save some key-strokes, use the irplib error handling macros
00114    under different (shorter) names.
00115    Additionally, irplib macros require the VA_ARGS to be enclosed in (),
00116 */
00117 
00118 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 0, 0)
00119 
00122 #define assure(BOOL, CODE, ...) \
00123 do {                                                              \
00124     cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE,      \
00125                      cpl_error_get_code(), goto cleanup,          \
00126                      "An error occurred that was not caught: %s", \
00127                      cpl_error_get_where() );                     \
00128     cpl_error_ensure(BOOL, CODE, goto cleanup, __VA_ARGS__);      \
00129 } while (0)
00130 
00132 #define assure_nomsg(BOOL, CODE) \
00133     assure(BOOL, CODE, " ")
00134 
00136 #define assure_mem(PTR) \
00137     assure((PTR) != NULL, CPL_ERROR_ILLEGAL_OUTPUT, "Memory allocation failure!")
00138 
00139 #define ck0(IEXP, ...) \
00140     assure((IEXP) == 0, CPL_ERROR_UNSPECIFIED, __VA_ARGS__)
00141 
00142 #define ck0_nomsg(IEXP) ck0(IEXP, " ")
00143 
00144 #define cknull(NULLEXP, ...)  \
00145     assure((NULLEXP) != NULL, CPL_ERROR_UNSPECIFIED, __VA_ARGS__)
00146 
00147 #define cknull_nomsg(NULLEXP) cknull(NULLEXP, " ")
00148 
00149 
00151 #define  check(CMD, ...) \
00152     assure((uves_msg_softer(), (CMD), uves_msg_louder(),  \
00153             cpl_error_get_code() == CPL_ERROR_NONE),      \
00154             cpl_error_get_code(), __VA_ARGS__)
00155 
00157 #define  check_nomsg(CMD) check(CMD, " ")
00158 
00160 #define passure(BOOL, ...) \
00161     assure(BOOL, CPL_ERROR_UNSPECIFIED, \
00162            "Internal error. Please report to " PACKAGE_BUGREPORT " " __VA_ARGS__ )
00163            /*  Assumes that PACKAGE_BUGREPORT
00164                contains no formatting special characters  */
00165 
00167 #define uves_error_reset() cpl_error_reset()
00168 
00169 
00170 #else // if we still test CPL31
00171 
00172 
00173 #define assure(BOOL, CODE, ...) \
00174   irplib_error_assure(BOOL, CODE, (__VA_ARGS__), goto cleanup)
00175 
00177 #define assure_nomsg(BOOL, CODE) \
00178   irplib_error_assure(BOOL, CODE, (" "), goto cleanup)
00179 
00181 #define assure_mem(PTR) \
00182   irplib_error_assure((PTR) != NULL, CPL_ERROR_ILLEGAL_OUTPUT, \
00183   ("Memory allocation failure!"), goto cleanup)
00184 #define ck0(IEXP, ...) \
00185   irplib_error_assure(IEXP == 0, CPL_ERROR_UNSPECIFIED, \
00186   (__VA_ARGS__), goto cleanup)
00187 
00188 #define ck0_nomsg(IEXP) ck0(IEXP," ")
00189 
00190 #define cknull(NULLEXP, ...) \
00191   irplib_error_assure((NULLEXP) != NULL, \
00192   CPL_ERROR_UNSPECIFIED, (__VA_ARGS__), goto cleanup)
00193 
00194 #define cknull_nomsg(NULLEXP) cknull(NULLEXP," ")
00195 
00196 
00198 #define  check(CMD, ...)                                                 \
00199   irplib_error_assure((uves_msg_softer(), (CMD), uves_msg_louder(),      \
00200               cpl_error_get_code() == CPL_ERROR_NONE),       \
00201                        cpl_error_get_code(), (__VA_ARGS__), goto cleanup)
00202 
00204 #define  check_nomsg(CMD) check(CMD, " ")
00205 
00207 #define passure(BOOL, ...)                                               \
00208   irplib_error_assure(BOOL, CPL_ERROR_UNSPECIFIED,                       \
00209                      ("Internal error. Please report to "                \
00210                       PACKAGE_BUGREPORT " " __VA_ARGS__), goto cleanup)
00211                        /*  Assumes that PACKAGE_BUGREPORT
00212                contains no formatting special characters  */
00213 
00215 #define uves_error_reset()   \
00216       irplib_error_reset()
00217 
00219 #define uves_error_dump()  \
00220       irplib_error_dump(CPL_MSG_ERROR, CPL_MSG_ERROR)
00221 
00222 #endif //end check on CPL version
00223 
00232 /*----------------------------------------------------------------------------*/
00499 /*----------------------------------------------------------------------------*/
00500 
00501 #endif
00502 
00503 
00504 
00505 
00506 
00507 
00508 
00509 
00510 
00511 
00512 
00513 
00514 
00515 
00516 
00517 
00518 
00519 
00520 
00521 
00522 
00523 
00524 

Generated on Thu Nov 15 14:32:28 2007 for UVES Pipeline Reference Manual by  doxygen 1.5.1