This repository has been archived by the owner on Jul 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DValue.hpp
72 lines (60 loc) · 1.38 KB
/
DValue.hpp
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
#ifndef __DVALUE_HPP_
#define __DVALUE_HPP_
#include <stdio.h>
#include <iostream>
#include <stdint.h>
// DValue provides a general purpose, Distributed Value type
// (typedef, struct, union, and basic OOP magic)
enum DVType {
d_uint8,
d_uint16,
d_uint32,
d_uint64,
d_int8,
d_int16,
d_int32,
d_int64,
d_float32,
d_string,
};
enum DVHighType {
dh_uint,
dh_int,
dh_string,
dh_double,
};
typedef struct {
DVType d_type;
DVHighType d_hightype;
union {
uint64_t v_uint;
int64_t v_int;
double v_double;
};
// TODO: optimize not having a huge string in here
std::string v_string; // declared out of the union due to compiler internals
} DValue;
// generic constructor method for DValue
#define DValue_init_generic(typename, hightypename, valuefield, value) \
{ \
DValue ret; \
ret.d_type = typename; \
ret.d_hightype = hightypename; \
ret.valuefield = value; \
return ret; \
}
// type constructor table. pile of macros. deal with it
#define $(fancyStr) dstring(fancyStr)
DValue dstring(std::string str);
DValue duint8(uint8_t v);
DValue duint16(uint16_t v);
DValue duint32(uint32_t v);
DValue duint64(uint64_t v);
DValue dint8(int8_t v);
DValue dint16(int16_t v);
DValue dint32(int32_t v);
DValue dint64(int64_t v);
DValue dfloat32(float v);
// typeless printf, basically
void dprint(DValue v);
#endif