34 #ifndef PLANCK_DATATYPES_H 35 #define PLANCK_DATATYPES_H 45 template <
typename T,
bool equalSize>
struct sizeChooserHelper__
46 {
typedef void TYPE; };
48 template <
typename T>
struct sizeChooserHelper__<T,true>
51 template <
typename T1,
typename T2,
typename T3>
struct sizeChooserHelper2__
54 template <
typename T2,
typename T3>
struct sizeChooserHelper2__ <void, T2, T3>
57 template <
typename T3>
struct sizeChooserHelper2__ <void, void, T3>
60 template <>
struct sizeChooserHelper2__ <void, void, void>
63 template <
int sz,
typename T1,
typename T2=
char,
typename T3=
char>
66 typedef typename sizeChooserHelper2__
67 <
typename sizeChooserHelper__<T1,sizeof(T1)==sz>::TYPE,
68 typename sizeChooserHelper__<T2,sizeof(T2)==sz>::TYPE,
69 typename sizeChooserHelper__<T3,sizeof(T3)==sz>::TYPE >::TYPE TYPE;
72 #if (__cplusplus>=201103L) 77 typedef uint8_t uint8;
79 typedef int16_t int16;
80 typedef uint16_t uint16;
82 typedef int32_t int32;
83 typedef uint32_t uint32;
85 typedef int64_t int64;
86 typedef uint64_t uint64;
90 typedef signed char int8;
91 typedef unsigned char uint8;
93 typedef sizeChooser__<2, short, int>::TYPE
95 typedef sizeChooser__<2, unsigned short, unsigned int>::TYPE
98 typedef sizeChooser__<4, int, long, short>::TYPE
100 typedef sizeChooser__<4, unsigned int, unsigned long, unsigned short>::TYPE
103 typedef sizeChooser__<8, long, long long>::TYPE
105 typedef sizeChooser__<8, unsigned long, unsigned long long>::TYPE
110 typedef sizeChooser__<4, float, double>::TYPE
112 typedef sizeChooser__<8, double, long double>::TYPE
134 PLANCK_INVALID = -1 };
139 template<>
inline PDT planckType<int8> () {
return PLANCK_INT8; }
140 template<>
inline PDT planckType<uint8> () {
return PLANCK_UINT8; }
141 template<>
inline PDT planckType<int16> () {
return PLANCK_INT16; }
142 template<>
inline PDT planckType<uint16> () {
return PLANCK_UINT16; }
143 template<>
inline PDT planckType<int32> () {
return PLANCK_INT32; }
144 template<>
inline PDT planckType<uint32> () {
return PLANCK_UINT32; }
145 template<>
inline PDT planckType<int64> () {
return PLANCK_INT64; }
146 template<>
inline PDT planckType<uint64> () {
return PLANCK_UINT64; }
147 template<>
inline PDT planckType<float32> () {
return PLANCK_FLOAT32;}
148 template<>
inline PDT planckType<float64> () {
return PLANCK_FLOAT64;}
149 template<>
inline PDT planckType<bool> () {
return PLANCK_BOOL; }
150 template<>
inline PDT planckType<std::string>() {
return PLANCK_STRING; }
160 case PLANCK_STRING :
return 1;
162 case PLANCK_UINT16 :
return 2;
165 case PLANCK_FLOAT32:
return 4;
168 case PLANCK_FLOAT64:
return 8;
177 if (type==
"FLOAT64")
return PLANCK_FLOAT64;
178 if (type==
"FLOAT32")
return PLANCK_FLOAT32;
179 if (type==
"INT8")
return PLANCK_INT8;
180 if (type==
"UINT8")
return PLANCK_UINT8;
181 if (type==
"INT16")
return PLANCK_INT16;
182 if (type==
"UINT16")
return PLANCK_UINT16;
183 if (type==
"INT32")
return PLANCK_INT32;
184 if (type==
"UINT32")
return PLANCK_UINT32;
185 if (type==
"INT64")
return PLANCK_INT64;
186 if (type==
"UINT64")
return PLANCK_UINT64;
187 if (type==
"BOOL")
return PLANCK_BOOL;
188 if (type==
"STRING")
return PLANCK_STRING;
189 planck_fail (
"string2type: unknown data type '"+type+
"'");
197 case PLANCK_INT8 :
return "INT8";
198 case PLANCK_UINT8 :
return "UINT8";
199 case PLANCK_INT16 :
return "INT16";
200 case PLANCK_UINT16 :
return "UINT16";
201 case PLANCK_INT32 :
return "INT32";
202 case PLANCK_UINT32 :
return "UINT32";
203 case PLANCK_INT64 :
return "INT64";
204 case PLANCK_UINT64 :
return "UINT64";
205 case PLANCK_FLOAT32:
return "FLOAT32";
206 case PLANCK_FLOAT64:
return "FLOAT64";
207 case PLANCK_BOOL :
return "BOOL";
208 case PLANCK_STRING :
return "STRING";
210 planck_fail (
"type2string: unsupported data type");
217 template<>
inline const char *type2typename<signed char> ()
218 {
return "signed char"; }
219 template<>
inline const char *type2typename<unsigned char> ()
220 {
return "unsigned char"; }
221 template<>
inline const char *type2typename<short> ()
223 template<>
inline const char *type2typename<unsigned short> ()
224 {
return "unsigned short"; }
225 template<>
inline const char *type2typename<int> ()
227 template<>
inline const char *type2typename<unsigned int> ()
228 {
return "unsigned int"; }
229 template<>
inline const char *type2typename<long> ()
231 template<>
inline const char *type2typename<unsigned long> ()
232 {
return "unsigned long"; }
233 template<>
inline const char *type2typename<long long> ()
234 {
return "long long"; }
235 template<>
inline const char *type2typename<unsigned long long> ()
236 {
return "unsigned long long"; }
237 template<>
inline const char *type2typename<float> ()
239 template<>
inline const char *type2typename<double> ()
241 template<>
inline const char *type2typename<long double> ()
242 {
return "long double"; }
243 template<>
inline const char *type2typename<bool> ()
245 template<>
inline const char *type2typename<std::string> ()
246 {
return "std::string"; }
272 template<>
inline NDT nativeType<char> () {
return NAT_CHAR; }
273 template<>
inline NDT nativeType<signed char> () {
return NAT_SCHAR; }
274 template<>
inline NDT nativeType<unsigned char> () {
return NAT_UCHAR; }
275 template<>
inline NDT nativeType<short> () {
return NAT_SHORT; }
276 template<>
inline NDT nativeType<unsigned short> () {
return NAT_USHORT; }
277 template<>
inline NDT nativeType<int> () {
return NAT_INT; }
278 template<>
inline NDT nativeType<unsigned int> () {
return NAT_UINT; }
279 template<>
inline NDT nativeType<long> () {
return NAT_LONG; }
280 template<>
inline NDT nativeType<unsigned long> () {
return NAT_ULONG; }
281 template<>
inline NDT nativeType<long long> () {
return NAT_LONGLONG; }
282 template<>
inline NDT nativeType<unsigned long long>() {
return NAT_ULONGLONG; }
283 template<>
inline NDT nativeType<float> () {
return NAT_FLOAT; }
284 template<>
inline NDT nativeType<double> () {
return NAT_DOUBLE; }
285 template<>
inline NDT nativeType<long double> () {
return NAT_LONGDOUBLE;}
286 template<>
inline NDT nativeType<fcomplex> () {
return NAT_FCMPLX; }
287 template<>
inline NDT nativeType<dcomplex> () {
return NAT_DCMPLX; }
288 template<>
inline NDT nativeType<bool> () {
return NAT_BOOL; }
289 template<>
inline NDT nativeType<std::string> () {
return NAT_STRING; }
298 case NAT_UCHAR :
return sizeof(char);
300 case NAT_USHORT :
return sizeof(short);
302 case NAT_UINT :
return sizeof(int);
304 case NAT_ULONG :
return sizeof(long);
306 case NAT_ULONGLONG :
return sizeof(
long long);
307 case NAT_FLOAT :
return sizeof(float);
308 case NAT_DOUBLE :
return sizeof(double);
309 case NAT_LONGDOUBLE:
return sizeof(
long double);
310 case NAT_FCMPLX :
return sizeof(fcomplex);
311 case NAT_DCMPLX :
return sizeof(dcomplex);
312 case NAT_BOOL :
return sizeof(bool);
PDT string2type(const std::string &type)
const char * type2typename()
const char * type2string(PDT type)