-
Notifications
You must be signed in to change notification settings - Fork 17
/
test_new_datatype.cpp
119 lines (88 loc) · 3.94 KB
/
test_new_datatype.cpp
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
#include <iostream>
#include <mxx/env.hpp>
#include <mxx/datatypes.hpp>
#include "new_datatype.hpp"
#include "type_traits.hpp"
#include <cxx-prettyprint/prettyprint.hpp>
#include <cxxabi.h>
struct X {
char c;
double d;
int i;
static constexpr auto datatype = std::make_tuple(&X::i, &X::c, &X::d);
};
struct Y {
int i;
};
template <typename T>
typename std::enable_if<mxx::is_simple_type<T>::value, void>::type test_datatype() {
mxx::datatype dt = mxx::make_datatype<T>();
std::cout << "================================================" << std::endl;
std::cout << "Testing type: " << typeid(T).name() << std::endl;
std::cout << "Sizeof(): " << sizeof(T) << std::endl;
std::cout << "Extent: " << dt.get_extent() << std::endl;
std::cout << "True extent: " << dt.get_true_extent() << std::endl;
std::cout << "is simple: " << mxx::is_simple_type<T>::value << std::endl;
// unpack test
mxx::flat_repr r;
r.type = dt.type();
mxx::type_decoder::unpack_envelope(dt.type(), r);
std::cout << "Pictogram:" << std::endl;
r.print_pictogram();
}
template <typename T>
typename std::enable_if<!mxx::has_type_descriptor<T>::value, void>::type
test_descriptor() {
}
template <typename T>
typename std::enable_if<mxx::has_type_descriptor<T>::value, void>::type
test_descriptor() {
std::cout << "all are builtin: " << all_are<mxx::is_builtin_type, decltype(mxx::get_datatype_descriptor<T>())>::value << std::endl;
std::cout << "are all simple: " << all_are<mxx::is_simple_member, decltype(mxx::get_datatype_descriptor<T>())>::value << std::endl;
}
template <typename T>
typename std::enable_if<!mxx::is_simple_type<T>::value, void>::type test_datatype() {
std::cout << "================================================" << std::endl;
std::cout << "Testing type: " << typeid(T).name() << std::endl;
std::cout << "Sizeof(): " << sizeof(T) << std::endl;
std::cout << "is simple: " << mxx::is_simple_type<T>::value << std::endl;
std::cout << "not simple because: " << std::endl;
std::cout << "has descriptor: " << mxx::has_type_descriptor<T>::value << std::endl;
test_descriptor<T>();
}
std::string demangle(const char* name) {
int status = -4; // some arbitrary value to eliminate the compiler warning
// enable c++11 by passing the flag -std=c++11 to g++
std::unique_ptr<char, void(*)(void*)> res {
abi::__cxa_demangle(name, NULL, NULL, &status),
std::free
};
return (status==0) ? res.get() : name ;
}
int main(int argc, char *argv[]) {
mxx::env e(argc, argv);
/*
test_datatype<int>();
test_datatype<float>();
*/
test_datatype<std::pair<int, char>>();
test_datatype<std::tuple<double, char>>();
using rec_tuple = std::tuple<std::pair<int, char>, std::tuple<double, float>>;
test_datatype<rec_tuple>();
test_datatype<std::tuple<double, float>>();
test_datatype<X>();
test_datatype<Y>();
test_datatype<std::tuple<int, Y>>();
test_datatype<std::tuple<std::pair<int, int>, std::string>>();
std::cout << "all builtin: " << all_are<mxx::is_builtin_type, std::tuple<float, int, float, double>>::value << std::endl;
std::cout << "is simple type: " << mxx::is_simple_type_helper<X>::value << std::endl;
std::cout << "is simple type: " << mxx::is_simple_type<float>::value << std::endl;
std::cout << "is simple member: " << mxx::is_simple_member<float*>::value << std::endl;
std::cout << "is simple member: " << mxx::is_simple_member<double X::*>::value << std::endl;
typedef decltype(X::datatype) my_tuple;
// TODO: we have a cv issue!
std::cout << "all simple member: " << all_are<mxx::is_simple_member, std::remove_cv<my_tuple>::type>::value << std::endl;
std::cout << "all simple member: " << all_are<mxx::is_simple_member, std::tuple<int X::*, char X::*, double X::*>>::value << std::endl;
std::cout << "datatype type: " << demangle(typeid(const my_tuple).name()) << std::endl;
return 0;
}