-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathPrimitives.cpp
41 lines (33 loc) · 1.17 KB
/
Primitives.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
#include "Reflect.h"
namespace reflect {
//--------------------------------------------------------
// A type descriptor for int
//--------------------------------------------------------
struct TypeDescriptor_Int : TypeDescriptor {
TypeDescriptor_Int() : TypeDescriptor{"int", sizeof(int)} {
}
virtual void dump(const void* obj, int /* unused */) const override {
std::cout << "int{" << *(const int*) obj << "}";
}
};
template <>
TypeDescriptor* getPrimitiveDescriptor<int>() {
static TypeDescriptor_Int typeDesc;
return &typeDesc;
}
//--------------------------------------------------------
// A type descriptor for std::string
//--------------------------------------------------------
struct TypeDescriptor_StdString : TypeDescriptor {
TypeDescriptor_StdString() : TypeDescriptor{"std::string", sizeof(std::string)} {
}
virtual void dump(const void* obj, int /* unused */) const override {
std::cout << "std::string{\"" << *(const std::string*) obj << "\"}";
}
};
template <>
TypeDescriptor* getPrimitiveDescriptor<std::string>() {
static TypeDescriptor_StdString typeDesc;
return &typeDesc;
}
} // namespace reflect