UVES Pipeline Reference Manual  5.4.6
uves_error.h
1 /*
2  * This file is part of the ESO UVES Pipeline
3  * Copyright (C) 2004,2005 European Southern Observatory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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 General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18  */
19 
20 /*
21  * $Author: amodigli $
22  * $Date: 2010-09-24 09:32:03 $
23  * $Revision: 1.58 $
24  * $Name: not supported by cvs2svn $
25  * $Log: not supported by cvs2svn $
26  * Revision 1.56 2007/08/21 11:08:10 jmlarsen
27  * Readded checks for pre-existing error which was provided by irplib_error_assure but not by cpl_error_ensure
28  *
29  * Revision 1.55 2007/08/13 12:15:58 amodigli
30  * support of CPL4
31  *
32  * Revision 1.54 2007/06/06 08:17:33 amodigli
33  * replace tab with 4 spaces
34  *
35  * Revision 1.53 2007/01/08 16:58:52 amodigli
36  * added ck0 and cknull
37  *
38  * Revision 1.52 2006/11/06 15:19:41 jmlarsen
39  * Removed unused include directives
40  *
41  * Revision 1.51 2006/08/17 13:56:52 jmlarsen
42  * Reduced max line length
43  *
44  * Revision 1.50 2006/06/01 14:43:17 jmlarsen
45  * Added missing documentation
46  *
47  * Revision 1.49 2006/05/05 13:54:11 jmlarsen
48  * Added assure_mem
49  *
50  * Revision 1.48 2006/04/24 09:19:25 jmlarsen
51  * Minor message change
52  *
53  * Revision 1.47 2006/04/06 08:31:52 jmlarsen
54  * Dump trace on CPL_MSG_ERROR level
55  *
56  * Revision 1.46 2006/03/09 10:57:57 jmlarsen
57  * Added check_nomsg macro
58  *
59  * Revision 1.45 2006/03/03 13:54:11 jmlarsen
60  * Changed syntax of check macro
61  *
62  * Revision 1.44 2006/02/28 09:15:22 jmlarsen
63  * Minor update
64  *
65  * Revision 1.43 2006/02/23 16:07:59 jmlarsen
66  * Using irplib_assert_msg
67  *
68  * Revision 1.42 2006/02/21 14:26:54 jmlarsen
69  * Minor changes
70  *
71  * Revision 1.41 2006/02/08 07:52:16 jmlarsen
72  * Added function returning library version
73  *
74  * Revision 1.40 2006/02/03 07:46:30 jmlarsen
75  * Moved recipe implementations to ./uves directory
76  *
77  * Revision 1.39 2006/01/24 07:49:31 jmlarsen
78  * Removed spaces between backslash and newline
79  *
80  * Revision 1.38 2006/01/23 08:08:53 jmlarsen
81  * Updated documentation
82  *
83  * Revision 1.37 2005/12/19 16:17:56 jmlarsen
84  * Replaced bool -> int
85  *
86  */
87 
88 #ifndef UVES_ERROR_H
89 #define UVES_ERROR_H
90 
91 /*----------------------------------------------------------------------------*/
95 /*----------------------------------------------------------------------------*/
98 /*-----------------------------------------------------------------------------
99  Includes
100  -----------------------------------------------------------------------------*/
101 #include <uves_utils.h>
102 #include <uves_msg.h>
103 
104 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE < CPL_VERSION(4, 0, 0)
105 #include <irplib_error.h>
106 #endif
107 
108 #include <cpl_error.h>
109 
110 /*-----------------------------------------------------------------------------
111  Defines
112  -----------------------------------------------------------------------------*/
113 /* To save some key-strokes, use the irplib error handling macros
114  under different (shorter) names.
115  Additionally, irplib macros require the VA_ARGS to be enclosed in (),
116 */
117 
118 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 0, 0)
119 
122 #define assure(BOOL, CODE, ...) \
123 do { \
124  cpl_error_ensure(cpl_error_get_code() == CPL_ERROR_NONE, \
125  cpl_error_get_code(), goto cleanup, \
126  "An error occurred that was not caught: %s", \
127  cpl_error_get_where() ); \
128  cpl_error_ensure(BOOL, CODE, goto cleanup, __VA_ARGS__); \
129 } while (0)
130 
132 #define assure_nomsg(BOOL, CODE) \
133  assure(BOOL, CODE, " ")
134 
136 #define assure_mem(PTR) \
137  assure((PTR) != NULL, CPL_ERROR_ILLEGAL_OUTPUT, "Memory allocation failure!")
138 
139 #define ck0(IEXP, ...) \
140  assure((IEXP) == 0, CPL_ERROR_UNSPECIFIED, __VA_ARGS__)
141 
142 #define ck0_nomsg(IEXP) ck0(IEXP, " ")
143 
144 #define cknull(NULLEXP, ...) \
145  assure((NULLEXP) != NULL, CPL_ERROR_UNSPECIFIED, __VA_ARGS__)
146 
147 #define cknull_nomsg(NULLEXP) cknull(NULLEXP, " ")
148 
149 
151 #define check(CMD, ...) \
152  assure((uves_msg_softer(), (CMD), uves_msg_louder(), \
153  cpl_error_get_code() == CPL_ERROR_NONE), \
154  cpl_error_get_code(), __VA_ARGS__)
155 
157 #define check_nomsg(CMD) check(CMD, " ")
158 
160 #define passure(BOOL, ...) \
161  assure(BOOL, CPL_ERROR_UNSPECIFIED, \
162  "Internal error. Please report to " PACKAGE_BUGREPORT " " __VA_ARGS__ )
163  /* Assumes that PACKAGE_BUGREPORT
164  contains no formatting special characters */
165 
167 #define uves_error_reset() cpl_error_reset()
168 
169 
170 #else // if we still test CPL31
171 
172 
173 #define assure(BOOL, CODE, ...) \
174  irplib_error_assure(BOOL, CODE, (__VA_ARGS__), goto cleanup)
175 
177 #define assure_nomsg(BOOL, CODE) \
178  irplib_error_assure(BOOL, CODE, (" "), goto cleanup)
179 
181 #define assure_mem(PTR) \
182  irplib_error_assure((PTR) != NULL, CPL_ERROR_ILLEGAL_OUTPUT, \
183  ("Memory allocation failure!"), goto cleanup)
184 #define ck0(IEXP, ...) \
185  irplib_error_assure(IEXP == 0, CPL_ERROR_UNSPECIFIED, \
186  (__VA_ARGS__), goto cleanup)
187 
188 #define ck0_nomsg(IEXP) ck0(IEXP," ")
189 
190 #define cknull(NULLEXP, ...) \
191  irplib_error_assure((NULLEXP) != NULL, \
192  CPL_ERROR_UNSPECIFIED, (__VA_ARGS__), goto cleanup)
193 
194 #define cknull_nomsg(NULLEXP) cknull(NULLEXP," ")
195 
196 
198 #define check(CMD, ...) \
199  irplib_error_assure((uves_msg_softer(), (CMD), uves_msg_louder(), \
200  cpl_error_get_code() == CPL_ERROR_NONE), \
201  cpl_error_get_code(), (__VA_ARGS__), goto cleanup)
202 
204 #define check_nomsg(CMD) check(CMD, " ")
205 
207 #define passure(BOOL, ...) \
208  irplib_error_assure(BOOL, CPL_ERROR_UNSPECIFIED, \
209  ("Internal error. Please report to " \
210  PACKAGE_BUGREPORT " " __VA_ARGS__), goto cleanup)
211  /* Assumes that PACKAGE_BUGREPORT
212  contains no formatting special characters */
213 
215 #define uves_error_reset() \
216  irplib_error_reset()
217 
219 #define uves_error_dump() \
220  irplib_error_dump(CPL_MSG_ERROR, CPL_MSG_ERROR)
221 
222 #endif //end check on CPL version
223 
232 /*----------------------------------------------------------------------------*/
499 /*----------------------------------------------------------------------------*/
500 
501 #endif
502 
503 
504 
505 
506 
507 
508 
509 
510 
511 
512 
513 
514 
515 
516 
517 
518 
519 
520 
521 
522 
523 
524