-
Notifications
You must be signed in to change notification settings - Fork 0
/
joint3.cc
83 lines (66 loc) · 1.89 KB
/
joint3.cc
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
#include<iostream>
#include<memory>
#include<vector>
using namespace std;
#define DRAKE_IMPORT_IMPLEMENTATION(Class, Method, T, ReturnT) \
ReturnT Method(Context<T>& ctx) override { \
cout << __PRETTY_FUNCTION__ << endl; \
return Class##Implementation<T>::GetTransform(ctx); \
}
template<class T>
class Context {
public:
};
// Interface for a single type
template<typename T>
class JointInterface {
public:
virtual T GetTransform(Context<T>& ctx) = 0;
};
#define JOINT_IMPORT_IMPLEMENTATIONS(DerivedJoint, T) \
DRAKE_IMPORT_IMPLEMENTATION(DerivedJoint, GetTransform, T, T);
// Interface for multiple types
class Joint: public JointInterface<int>, JointInterface<double> {
public:
virtual ~Joint() {}
};
// Implementation for a single type
template<typename T>
class RevoluteJointImplementation: public JointInterface<T> {
public:
RevoluteJointImplementation() {
cout << __PRETTY_FUNCTION__ << endl;
}
~RevoluteJointImplementation() {
cout << __PRETTY_FUNCTION__ << endl;
}
T GetTransform(Context<T>& ctx) override {
cout << __PRETTY_FUNCTION__ << endl;
return T();
}
};
#define REVOLUTE_JOINT_IMPORT_IMPLEMENTATIONS() \
JOINT_IMPORT_IMPLEMENTATIONS(RevoluteJoint, int); \
JOINT_IMPORT_IMPLEMENTATIONS(RevoluteJoint, double);
// Implementation for multiple types
class RevoluteJoint: public Joint, RevoluteJointImplementation<int>, RevoluteJointImplementation<double> {
public:
RevoluteJoint() {
cout << __PRETTY_FUNCTION__ << endl;
}
~RevoluteJoint() {
cout << __PRETTY_FUNCTION__ << endl;
}
REVOLUTE_JOINT_IMPORT_IMPLEMENTATIONS();
};
int main()
{
RevoluteJoint* j = new RevoluteJoint();
std::vector<std::unique_ptr<Joint>> joints_owner;
joints_owner.push_back(std::unique_ptr<Joint>(j));
Context<double> cd;
Context<int> ci;
j->GetTransform(cd);
j->GetTransform(ci);
return 0;
}