1 #pragma once
2 
3 namespace pylazperf
4 {
5 
6 // Stolen from PDAL
7 
8 template<typename E>
toNative(E e)9 constexpr typename std::underlying_type<E>::type toNative(E e)
10 {
11     return static_cast<typename std::underlying_type<E>::type>(e);
12 }
13 
14 enum class BaseType
15 {
16     None = 0x000,
17     Signed = 0x100,
18     Unsigned = 0x200,
19     Floating = 0x400
20 };
21 
22 enum Type
23 {
24     None = 0,
25     Unsigned8 = toNative(BaseType::Unsigned) | 1,
26     Signed8 = toNative(BaseType::Signed) | 1,
27     Unsigned16 = toNative(BaseType::Unsigned) | 2,
28     Signed16 = toNative(BaseType::Signed) | 2,
29     Unsigned32 = toNative(BaseType::Unsigned) | 4,
30     Signed32 = toNative(BaseType::Signed) | 4,
31     Unsigned64 = toNative(BaseType::Unsigned) | 8,
32     Signed64 = toNative(BaseType::Signed) | 8,
33     Float = toNative(BaseType::Floating) | 4,
34     Double = toNative(BaseType::Floating) | 8
35 };
36 
toName(BaseType b)37 inline std::string toName(BaseType b)
38 {
39     switch (b)
40     {
41     case BaseType::Signed:
42         return "signed";
43     case BaseType::Unsigned:
44         return "unsigned";
45     case BaseType::Floating:
46         return "floating";
47     default:
48         return "";
49     }
50 }
51 
base(Type t)52 inline BaseType base(Type t)
53 {
54     return BaseType(toNative(t) & 0xFF00);
55 }
56 
size(Type t)57 inline size_t size(Type t)
58 {
59     return t & 0xFF;
60 }
61 
interpretationName(Type dimtype)62 inline std::string interpretationName(Type dimtype)
63 {
64     switch (dimtype)
65     {
66     case Type::None:
67         return "unknown";
68     case Type::Signed8:
69         return "int8_t";
70     case Type::Signed16:
71         return "int16_t";
72     case Type::Signed32:
73         return "int32_t";
74     case Type::Signed64:
75         return "int64_t";
76     case Type::Unsigned8:
77         return "uint8_t";
78     case Type::Unsigned16:
79         return "uint16_t";
80     case Type::Unsigned32:
81         return "uint32_t";
82     case Type::Unsigned64:
83         return "uint64_t";
84     case Type::Float:
85         return "float";
86     case Type::Double:
87         return "double";
88     }
89     return "unknown";
90 }
91 
92 
93 /// Get the type corresponding to a type name.
94 /// \param s  Name of type.
95 /// \return  Corresponding type enumeration value.
type(std::string s)96 inline Type type(std::string s)
97 {
98     if (s == "int8_t" || s == "int8")
99        return Type::Signed8;
100     if (s == "int16_t" || s == "int16")
101        return Type::Signed16;
102     if (s == "int32_t" || s == "int32")
103        return Type::Signed32;
104     if (s == "int64_t" || s == "int64")
105        return Type::Signed64;
106     if (s == "uint8_t" || s == "uint8")
107         return Type::Unsigned8;
108     if (s == "uint16_t" || s == "uint16")
109         return Type::Unsigned16;
110     if (s == "uint32_t" || s == "uint32")
111         return Type::Unsigned32;
112     if (s == "uint64_t" || s == "uint64")
113         return Type::Unsigned64;
114     if (s == "float")
115         return Type::Float;
116     if (s == "double")
117         return Type::Double;
118     return Type::None;
119 }
120 
121 
122 }
123