-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_inheritance.cpp
52 lines (41 loc) · 1.3 KB
/
test_inheritance.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
#include "Inheritance.hpp"
#include "SerializationMacros.hpp"
#include <iostream>
using namespace mutils;
struct A : public InheritByteRepresentable {
virtual ~A() = default;
};
struct B: public A, public ByteRepresentable {
const int data;
B(int data):data(data){}
INHERIT_SERIALIZATION_SUPPORT(B,A,9846,data);
};
template<typename, typename> struct D : public InheritByteRepresentable{
};
template<typename T>
struct C: public D<T,int>, public ByteRepresentable{
const int data;
C(int data):data(data){}
INHERIT_SERIALIZATION_SUPPORT(C,A,98467,data);
};
template<typename Y> using Dindirect = D<Y,int>;
int main(){
B b{234};
C<int> c{23423};
auto ig = InheritGroup<InheritPairAbs1<Dindirect, C, 98467> >::add_class(b);
DeserializationManager<DECT(ig)> dsm{&ig};
A& ab = b;
D<int,int>& ac = c;
char bbuf[256];
char cbuf[256];
ab.inherit_to_bytes(bbuf);
ac.inherit_to_bytes(cbuf);
auto ab2 = inherit_from_bytes<A>(&dsm,bbuf);
auto ac2 = inherit_from_bytes<Dindirect<int>>(&dsm,cbuf);
assert(inherit_from_bytes<Dindirect<int>>(&dsm,cbuf));
assert(ab2);
assert(ac2);
assert(dynamic_cast<B*>(ab2.get())->data == b.data);
assert(dynamic_cast<C<int>*>(ac2.get())->data == c.data);
std::cout << dynamic_cast<C<int>*>(ac2.get())->data << " " << dynamic_cast<B*>(ab2.get())->data << std::endl;
}