X-shooter Pipeline Reference Manual 3.8.15
xsh_error.h
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library 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: 2011-12-02 14:15:28 $
23 * $Revision: 1.15 $
24 * $Name: not supported by cvs2svn $
25 */
26
27#ifndef XSH_ERROR_H
28#define XSH_ERROR_H
29
30/*----------------------------------------------------------------------------*/
37/*----------------------------------------------------------------------------*/
40/*-----------------------------------------------------------------------------
41 Includes
42 -----------------------------------------------------------------------------*/
43#include <irplib_error.h>
44
45#include <cpl.h>
46
47/*-----------------------------------------------------------------------------
48 Defines
49 -----------------------------------------------------------------------------*/
50/* To save some key-strokes, use the irplib error handling macros
51 under different (shorter) names.
52 Additionally, irplib macros require the VA_ARGS to be enclosed in (),
53*/
54#define assure(CONDITION, ERROR_CODE, ...) \
55 irplib_error_assure(CONDITION, ERROR_CODE, (__VA_ARGS__), goto cleanup)
56
58#define assure_nomsg(BOOL, CODE) \
59 assure(BOOL, CODE, " ")
60
61/* Define check macro using error message */
62#define check_msg(COMMAND, ...) \
63 irplib_error_assure((cpl_msg_indent_more(), \
64 (COMMAND), \
65 cpl_msg_indent_less(), \
66 cpl_error_get_code() == CPL_ERROR_NONE), \
67 cpl_error_get_code(), \
68 (__VA_ARGS__), goto cleanup)
69
70/* Define check macro without error message */
71#define check(COMMAND) check_msg(COMMAND, " ")
72
73#define cknull_msg(NULLEXP, ...) \
74 cpl_error_ensure((NULLEXP) != NULL, \
75 CPL_ERROR_UNSPECIFIED, goto cleanup,__VA_ARGS__)
76
77#define cknull(NULLEXP) cknull_msg(NULLEXP," ")
78
79#define assure_mem(PTR) \
80 assure((PTR) != NULL, CPL_ERROR_ILLEGAL_OUTPUT, "Memory allocation failure!")
81/* Assertions */
82#define passure(CONDITION, ...) assure(CONDITION, CPL_ERROR_UNSPECIFIED, \
83 "Internal program error. Please report to " \
84 PACKAGE_BUGREPORT " " __VA_ARGS__)
85/* Assumes that PACKAGE_BUGREPORT contains no formatting special characters */
86
87#define xsh_error_reset() xsh_irplib_error_reset()
88
89/* Define here on which level to print
90 error messages + tracing information
91*/
92#define xsh_error_dump(level) irplib_error_dump(level, level)
93
94#define xsh_error_msg(...) \
95 if(cpl_error_get_code()!= CPL_ERROR_NULL_INPUT){\
96 irplib_error_push(cpl_error_get_code(), (__VA_ARGS__));\
97 }
98
99#define XSH_ASSURE_NOT_NULL(pointer) \
100 assure(pointer != NULL, CPL_ERROR_NULL_INPUT,\
101 "You have null pointer in input: " #pointer)
102
103#define XSH_ASSURE_NOT_NULL_MSG(pointer,msg) \
104 assure(pointer != NULL, CPL_ERROR_NULL_INPUT,\
105 "You have null pointer in input: " #pointer "\n" msg)
106
107#define XSH_ASSURE_NOT_ILLEGAL(cond) \
108 assure(cond, CPL_ERROR_ILLEGAL_INPUT,\
109 "condition failed: " #cond )
110
111#define XSH_ASSURE_NOT_ILLEGAL_MSG(cond, msg) \
112 assure(cond, CPL_ERROR_ILLEGAL_INPUT,\
113 "condition failed: " #cond "\n" msg)
114
115#define XSH_ASSURE_NOT_MISMATCH(cond) \
116 assure(cond, CPL_ERROR_TYPE_MISMATCH,\
117 "condition failed: "#cond )
118
119#define XSH_CMP_INT(A, OPERATOR, B, SUFFIX ,...)\
120 assure(A OPERATOR B, CPL_ERROR_ILLEGAL_INPUT,\
121 "assertion failed: %s %s %s : %d %s %d\n"\
122 #SUFFIX "", #A, #OPERATOR, #B , A, #OPERATOR, B __VA_ARGS__)
123
124#define XSH_CHECK_COND(A, OPERATOR, B, SUFFIX, ...)\
125 assure(A OPERATOR B, CPL_ERROR_ILLEGAL_INPUT,\
126 "assertion failed: %s %s %s\n" #SUFFIX "", #A, #OPERATOR, #B, __VA_ARGS__)
127
128#define XSH_CHECK_FRAMESET_SIZE(FRAMESET,OPERATOR,SIZE)\
129 XSH_CHECK_COND(cpl_frameset_get_size(FRAMESET),OPERATOR,SIZE,\
130 "%s","Frameset size invalid:")
131
132#define XSH_REGDEBUG( ...)\
133 xsh_msg_debug("<< REGDEBUG >> :" __VA_ARGS__)
134
135#endif