forked from MRtrix3/mrtrix3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.h
128 lines (100 loc) · 3.99 KB
/
types.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Copyright 2008 Brain Research Institute, Melbourne, Australia
Written by J-Donald Tournier, 27/06/08.
This file is part of MRtrix.
MRtrix is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MRtrix is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MRtrix. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __mrtrix_types_h__
#define __mrtrix_types_h__
#include <stdint.h>
#include <complex>
/*! \defgroup VLA Variable-length array macros
*
* The reason for defining these macros at all is that VLAs are not part of the
* C++ standard, and not available on all compilers. Regardless of the
* availability of VLAs, they should be avoided if possible since they run the
* risk of overrunning the stack if the length of the array is large, or if the
* function is called recursively. They can be used safely in cases where the
* size of the array is expected to be small, and the function will not be
* called recursively, and in these cases may avoid the overhead of allocation
* that might be incurred by the use of e.g. a std::vector.
*/
//! \{
/*! \def VLA
* define a variable-length array (VLA) if supported by the compiler, or a
* std::vector otherwise. This may have performance implications in the latter
* case if this forms part of a tight loop.
* \sa VLA_MAX
*/
/*! \def VLA_MAX
* define a variable-length array if supported by the compiler, or a
* fixed-length array of size \a max otherwise. This may have performance
* implications in the latter case if this forms part of a tight loop.
* \note this should not be used in recursive functions, unless the maximum
* number of calls is known to be small. Large amounts of recursion will run
* the risk of overrunning the stack.
* \sa VLA
*/
#ifdef MRTRIX_NO_VLA
# define VLA(name, type, num) \
std::vector<type> __vla__ ## name(num); \
type* name = &__vla__ ## name[0]
# define VLA_MAX(name, type, num, max) type name[max]
#else
# define VLA(name, type, num) type name[num]
# define VLA_MAX(name, type, num, max) type name[num]
#endif
/*! \def NON_POD_VLA
* define a variable-length array of non-POD data if supported by the compiler,
* or a std::vector otherwise. This may have performance implications in the
* latter case if this forms part of a tight loop.
* \sa VLA_MAX
*/
/*! \def NON_POD_VLA_MAX
* define a variable-length array of non-POD data if supported by the compiler,
* or a fixed-length array of size \a max otherwise. This may have performance
* implications in the latter case if this forms part of a tight loop.
* \note this should not be used in recursive functions, unless the maximum
* number of calls is known to be small. Large amounts of recursion will run
* the risk of overrunning the stack.
* \sa VLA
*/
#ifdef MRTRIX_NO_NON_POD_VLA
# define NON_POD_VLA(name, type, num) \
std::vector<type> __vla__ ## name(num); \
type* name = &__vla__ ## name[0]
# define NON_POD_VLA_MAX(name, type, num, max) type name[max]
#else
# define NON_POD_VLA(name, type, num) type name[num]
# define NON_POD_VLA_MAX(name, type, num, max) type name[num]
#endif
//! \}
namespace MR
{
typedef float float32;
typedef double float64;
typedef std::complex<double> cdouble;
typedef std::complex<float> cfloat;
template <typename T>
struct container_cast : public T {
template <typename U>
container_cast (const U& x) :
T (x.begin(), x.end()) { }
};
}
namespace std
{
inline uint8_t abs (uint8_t x) { return x; }
inline uint16_t abs (uint16_t x) { return x; }
inline uint32_t abs (uint32_t x) { return x; }
}
#endif