-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplates_errfuncs.h
69 lines (61 loc) · 2.27 KB
/
templates_errfuncs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Author: G. Jungman */
/*
* Automatic generation of error handling versions
* of functions. Given a "func_name", these will
* create the implementations of
* func_name_e()
* func_name()
* in terms of func_name_impl().
*
* Example: MAKE_FUNC_ERRHAND(gsl_foo, (double x, double * result), (x, result))
* should expand to
*
* int gsl_foo_e(double x, double * result)
* {
* int status = gsl_foo_impl(a, result);
* if(status != GSL_SUCCESS) {
* GSL_ERROR("gsl_foo", status);
* }
* return status;
* }
*
* and MAKE_FUNC_NATURAL(gsl_foo, (double x), (x, &y))
* should expand to
*
* double gsl_foo(double x)
* {
* double y;
* int status = gsl_foo_impl(x, &y);
* if(status != GSL_SUCCESS) {
* GSL_WARNING("gsl_foo", status);
* }
* return y;
* }
*
*/
#ifndef _TEMPLATES_ERRFUNCS_H_
#define _TEMPLATES_ERRFUNCS_H_
#define NAME_IMPL(f) f ## _ ## impl
#define NAME_E(f) f ## _ ## e
#define MAKE_FUNC_ERRHAND(func, args, impl_args) \
\
int NAME_E(func) args \
{ \
int status = NAME_IMPL(func) impl_args; \
if(status != GSL_SUCCESS) { \
GSL_ERROR(#func "_e", status); \
} \
return status; \
} \
#define MAKE_FUNC_NATURAL(func, args, impl_args) \
\
double func args \
{ \
double y; \
int status = NAME_IMPL(func) impl_args; \
if(status != GSL_SUCCESS) { \
GSL_WARNING(#func, status); \
} \
return y; \
} \
#endif /* !_TEMPLATES_ERRFUNCS_H_ */