forked from sequitur-g2p/sequitur-g2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypes.hh
200 lines (171 loc) · 5.02 KB
/
Types.hh
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* $Id: Types.hh 1667 2007-06-02 14:32:35Z max $
*
* Copyright (c) 2004-2005 RWTH Aachen University
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 (June
* 1991) as published by the Free Software Foundation.
*
* This program 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 this program; if not, you will find it at
* http://www.gnu.org/licenses/gpl.html, or write to the Free Software
* Foundation, Inc., 51 Franlin Street, Fifth Floor, Boston, MA 02110,
* USA.
*
* Should a provision of no. 9 and 10 of the GNU General Public License
* be invalid or become invalid, a valid provision is deemed to have been
* agreed upon which comes closest to what the parties intended
* commercially. In any case guarantee/warranty shall be limited to gross
* negligent actions or intended actions or fraudulent concealment.
*/
#ifndef _CORE_TYPES_HH
#define _CORE_TYPES_HH
#include <stdint.h>
#include <string>
#include <vector>
#include <complex>
typedef int8_t s8;
typedef uint8_t u8;
typedef int16_t s16;
typedef uint16_t u16;
typedef int32_t s32;
typedef uint32_t u32;
typedef int64_t s64;
typedef uint64_t u64;
typedef float f32;
typedef double f64;
namespace Core {
/** Static information about elementary types. */
template<class T> struct Type {
/** Name to be used to represent data type. */
static const char *name;
/** Largest representable value of data type. */
static const T max;
/**
* Smallest representable value of data type.
* Note that unlike std::numeric_limits<>::min this is the most negative
* value also for floating point types.
*/
static const T min;
/**
* The difference between the smallest value greater than one and one.
*/
static const T epsilon;
/**
* Smallest representable value greater than zero.
* For all integer types this is one. For floating point
* types this is the same as std::numeric_limits<>::min or
* FLT_MIN / DBL_MIN.
*/
static const T delta;
};
template<> struct Type<f32> {
static const char *name;
static const f32 max;
static const f32 min;
static const f32 epsilon;
static const f32 delta;
};
template<> struct Type<f64> {
static const char *name;
static const f64 max;
static const f64 min;
static const f64 epsilon;
static const f64 delta;
};
#if defined(HAS_64BIT)
template<> struct Type<s64> {
static const char *name;
static const s64 max;
static const s64 min;
static const s64 epsilon;
static const s64 delta;
};
template<> struct Type<u64> {
static const char *name;
static const u64 max;
static const u64 min;
static const u64 epsilon;
static const u64 delta;
};
#endif
template<> struct Type<s32> {
static const char *name;
static const s32 max;
static const s32 min;
static const s32 epsilon;
static const s32 delta;
};
template<> struct Type<u32> {
static const char *name;
static const u32 max;
static const u32 min;
static const u32 epsilon;
static const u32 delta;
};
template<> struct Type<s16> {
static const char *name;
static const s16 max;
static const s16 min;
static const s16 epsilon;
static const s16 delta;
};
template<> struct Type<u16> {
static const char *name;
static const u16 max;
static const u16 min;
static const u16 epsilon;
static const u16 delta;
};
template<> struct Type<s8> {
static const char *name;
static const s8 max;
static const s8 min;
static const s8 epsilon;
static const s8 delta;
};
template<> struct Type<u8> {
static const char *name;
static const u8 max;
static const u8 min;
static const u8 epsilon;
static const u8 delta;
};
/**
* Use this class for naming your basic classes.
* Creating new names: by specialization.
* @see example Matrix.hh
*/
template <typename T>
class NameHelper : public std::string {
public:
NameHelper() : std::string(Type<T>::name) {}
};
template <>
class NameHelper<std::string> : public std::string {
public:
NameHelper() : std::string("string") {}
};
template <>
class NameHelper<bool> : public std::string {
public:
NameHelper() : std::string("bool") {}
};
template <typename T>
class NameHelper<std::complex<T> > : public std::string {
public:
NameHelper() : std::string(std::string("complex-") + NameHelper<T>()) {}
};
template <typename T>
class NameHelper<std::vector<T> > : public std::string {
public:
NameHelper() : std::string(std::string("vector-") + NameHelper<T>()) {}
};
} // namespace Core
#endif // _CORE_TYPES_HH