prepare a rc1 and add a publish target to publish the documentation.
[hkl.git] / hkl / hkl-macros.h
blob913596412c8f0e88a4aa30a4c753b402c33eac02
1 /* This file is part of the hkl library.
3 * The hkl library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * The hkl library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2003-2010 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
22 #ifndef __HKL_MACROS_H__
23 #define __HKL_MACROS_H__
25 #include <stdlib.h>
26 #include <gsl/gsl_math.h>
28 /* Guard C code in headers, while including them from C++ */
29 #ifdef __cplusplus
30 # define HKL_BEGIN_DECLS extern "C" {
31 # define HKL_END_DECLS }
32 #else
33 # define HKL_BEGIN_DECLS
34 # define HKL_END_DECLS
35 #endif
37 /* add the win32 portability part */
38 #if _MSC_VER
39 # include <float.h>
40 # define INFINITY DBL_MAX
41 # define M_PI 3.14159265358979323846264338328
42 # define M_PI_2 1.57079632679489661923132169164
43 # define strdup _strdup
44 # include <malloc.h>
45 # define __inline__
47 # include <stdarg.h>
48 extern int vasprintf(char **strp, const char *fmt, va_list ap);
49 #endif
51 /* common part */
52 #define HKL_MAJOR 2
53 #define HKL_MINOR 3
54 #define HKL_PATCH 0
56 #define HKL_VERSION (HKL_MAJOR * 10000 + HKL_MINOR * 100 + HKL_PATCH)
58 #define HKL_TRUE 1
59 #define HKL_FALSE 0
61 #define HKL_SUCCESS 0
62 #define HKL_FAIL -1
64 #define HKL_TINY 1e-7
65 #define HKL_EPSILON 1e-6
66 #define HKL_DEGTORAD (M_PI/180.)
67 #define HKL_RADTODEG (180./M_PI)
69 /* tau = 2pi or 1 */
70 #define HKL_TAU (2. * M_PI)
71 /* #define HKL_TAU 1 */
73 /* specific part for the eulerian -> kappa conversion */
74 #define HKL_EULERIAN_KAPPA_SOLUTION 1
76 /* the assert method */
77 #if !defined(NDEBUG) && !_MSC_VER
78 # include <execinfo.h>
79 # include <assert.h>
80 # define hkl_assert(x) do{ if (!(x)) {hkl_printbt(); assert(x); } } while(0)
81 #else
82 # define hkl_assert(x)
83 #endif
85 /* use for the printf format methods took from glib */
86 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
87 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
89 /* use for the hkl_list */
90 #define alloc_nr(x) (((x)+16)*3/2)
93 * Realloc the buffer pointed at by variable 'x' so that it can hold
94 * at least 'nr' entries; the number of entries currently allocated
95 * is 'alloc', using the standard growing factor alloc_nr() macro.
97 * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
99 #define ALLOC_GROW(x, nr, alloc) \
100 do { \
101 if ((nr) > alloc) { \
102 if (alloc_nr(alloc) < (nr)) \
103 alloc = (nr); \
104 else \
105 alloc = alloc_nr(alloc); \
106 x = realloc((x), alloc * sizeof(*(x))); \
108 } while(0)
110 #ifdef __GNUC__
111 # define NORETURN __attribute__((__noreturn__))
112 #else
113 # define NORETURN
114 # ifndef __attribute__
115 # define __attribute__(x)
116 # endif
117 #endif
119 HKL_BEGIN_DECLS
121 extern void hkl_printbt(void);
123 void *_hkl_malloc(int size, const char *error);
125 HKL_END_DECLS
127 /* malloc method */
128 #define HKL_MALLOC(type) _hkl_malloc(sizeof(type), "Can not allocate memory for a " #type)
130 #endif