@@ -200,21 +200,73 @@ class flxDescriptor
200
200
bool _titleAlloc;
201
201
};
202
202
203
- typedef enum
203
+ // typedef enum
204
+ // {
205
+ // flxTypeNone = 0,
206
+ // flxTypeBool,
207
+ // flxTypeInt8,
208
+ // flxTypeInt16,
209
+ // flxTypeInt32,
210
+ // flxTypeUInt8,
211
+ // flxTypeUInt16,
212
+ // flxTypeUInt32,
213
+ // flxTypeFloat,
214
+ // flxTypeDouble,
215
+ // flxTypeString
216
+ // } flxDataType_t;
217
+
218
+ // The number used for the datatype codes is based on the sizeof() value and other attributes determined at compile
219
+ // time. This is something picked up from the NVS system of esp32 - solid hack.
220
+ enum flxDataType_t : std::uint8_t
221
+ {
222
+ flxTypeNone = 0x00 ,
223
+ flxTypeBool = 0x0A ,
224
+ flxTypeInt8 = 0x11 ,
225
+ flxTypeUInt8 = 0x01 ,
226
+ flxTypeInt16 = 0x12 ,
227
+ flxTypeUInt16 = 0x02 ,
228
+ flxTypeInt32 = 0x14 ,
229
+ flxTypeUInt32 = 0x04 ,
230
+ flxTypeFloat = 0x24 ,
231
+ flxTypeDouble = 0x28 ,
232
+ flxTypeString = 0x21
233
+ };
234
+
235
+ template <typename T, typename std::enable_if<std::is_integral<T>::value, void *>::type = nullptr >
236
+ constexpr flxDataType_t flxGetTypeOf ()
237
+ {
238
+ return std::is_same<T, bool >::value
239
+ ? flxTypeBool
240
+ : (static_cast <flxDataType_t>(((std::is_signed<T>::value) ? 0x10 : 0x00 ) | sizeof (T)));
241
+ }
242
+
243
+ template <typename T, typename std::enable_if<std::is_floating_point<T>::value, void *>::type = nullptr >
244
+ constexpr flxDataType_t flxGetTypeOf ()
204
245
{
205
- flxTypeNone = 0 ,
206
- flxTypeBool,
207
- flxTypeInt8,
208
- flxTypeInt16,
209
- flxTypeInt32,
210
- flxTypeUInt8,
211
- flxTypeUInt16,
212
- flxTypeUInt32,
213
- flxTypeFloat,
214
- flxTypeDouble,
215
- flxTypeString
216
- } flxDataType_t;
246
+ return static_cast <flxDataType_t>(0x20 | sizeof (T));
247
+ }
248
+ template <typename T, typename std::enable_if<std::is_same<char *, T>::value, void *>::type = nullptr >
249
+ constexpr flxDataType_t flxGetTypeOf ()
250
+ {
251
+ return flxTypeString;
252
+ }
253
+
254
+ template <typename T, typename std::enable_if<std::is_same<const char *, T>::value, void *>::type = nullptr >
255
+ constexpr flxDataType_t flxGetTypeOf ()
256
+ {
257
+ return flxTypeString;
258
+ }
217
259
260
+ template <typename T, typename std::enable_if<std::is_same<std::string, T>::value, void *>::type = nullptr >
261
+ constexpr flxDataType_t flxGetTypeOf ()
262
+ {
263
+ return flxTypeString;
264
+ }
265
+
266
+ template <typename T> constexpr flxDataType_t flxGetTypeOf (const T &)
267
+ {
268
+ return flxGetTypeOf<T>();
269
+ }
218
270
// helpful data types
219
271
typedef union {
220
272
bool b;
0 commit comments