SST/macro
fxn.h
Go to the documentation of this file.
1 #ifndef FXN_H
2 #define FXN_H
3 
4 class TestFxn
5 {
6 
7  public:
8  virtual void run() = 0;
9 
10 };
11 
12 template <class Fxn>
13 class TestFxn0 :
14  public TestFxn
15 {
16  private:
17  Fxn fxn_;
18 
19  public:
20  TestFxn0(Fxn fxn)
21  : fxn_(fxn) {
22  }
23 
24  void run() {
25  (*fxn_)();
26  }
27 };
28 
29 template <class Fxn, class A>
30 class TestFxn1 :
31  public TestFxn
32 {
33  private:
34  Fxn fxn_;
35 
36  A a_;
37 
38  public:
39  TestFxn1(Fxn fxn, const A& a)
40  : fxn_(fxn), a_(a) {
41  }
42 
43  void run() {
44  (*fxn_)(a_);
45  }
46 };
47 
48 template <class Fxn, class A, class B>
49 class TestFxn2 :
50  public TestFxn
51 {
52  private:
53  Fxn fxn_;
54 
55  A a_;
56 
57  B b_;
58 
59  public:
60  TestFxn2(Fxn fxn, const A& a, const B& b)
61  : fxn_(fxn), a_(a), b_(b) {
62  }
63 
64  void run() {
65  (*fxn_)(a_, b_);
66  }
67 };
68 
69 template <class Fxn, class A, class B, class C>
70 class TestFxn3 :
71  public TestFxn
72 {
73  private:
74  Fxn fxn_;
75 
76  A a_;
77 
78  B b_;
79 
80  C c_;
81 
82  public:
83  TestFxn3(Fxn fxn, const A& a, const B& b, const C& c)
84  : fxn_(fxn), a_(a), b_(b), c_(c) {
85  }
86 
87  void run() {
88  (*fxn_)(a_, b_, c_);
89  }
90 };
91 
92 template <class Fxn, class Cls, class A>
94  public TestFxn
95 {
96  private:
97  Fxn fxn_;
98 
99  Cls* cls_;
100 
101  A a_;
102 
103  public:
104  TestMemberFxn1(Fxn fxn, Cls* cls, const A& a)
105  : fxn_(fxn), cls_(cls), a_(a) {
106  }
107 
108  void run() {
109  (cls_->*fxn_)(a_);
110  }
111 };
112 
113 template <class Fxn, class Cls, class A, class B>
115  public TestFxn
116 {
117  private:
118  Fxn fxn_;
119 
120  Cls* cls_;
121 
122  A a_;
123 
124  B b_;
125 
126  public:
127  TestMemberFxn2(Fxn fxn, Cls* cls, const A& a, const B& b)
128  : fxn_(fxn), cls_(cls), a_(a), b_(b) {
129  }
130 
131  void run() {
132  (cls_->*fxn_)(a_,b_);
133  }
134 };
135 
136 template <class Fxn, class Cls, class A, class B, class C>
138  public TestFxn
139 {
140  private:
141  Fxn fxn_;
142 
143  Cls* cls_;
144 
145  A a_;
146 
147  B b_;
148 
149  C c_;
150 
151  public:
152  TestMemberFxn3(Fxn fxn, Cls* cls, const A& a, const B& b, const C& c)
153  : fxn_(fxn), cls_(cls), a_(a), b_(b), c_(c) {
154  }
155 
156  void run() {
157  (cls_->*fxn_)(a_,b_,c_);
158  }
159 };
160 
161 template <typename Fxn>
162 TestFxn*
163 static_fxn(Fxn fxn)
164 {
165  return new TestFxn0<Fxn>(fxn);
166 }
167 
168 template <typename Fxn, class A>
169 TestFxn*
170 static_fxn(Fxn fxn, const A& a)
171 {
172  return new TestFxn1<Fxn,A>(fxn,a);
173 }
174 
175 template <typename Fxn, class A, class B>
176 TestFxn*
177 static_fxn(Fxn fxn, const A& a, const B& b)
178 {
179  return new TestFxn2<Fxn,A,B>(fxn,a,b);
180 }
181 
182 template <typename Fxn, class A, class B, class C>
183 TestFxn*
184 static_fxn(Fxn fxn, const A& a, const B& b, const C& c)
185 {
186  return new TestFxn3<Fxn,A,B,C>(fxn,a,b,c);
187 }
188 
189 
190 template <typename Fxn, class Cls, class A>
191 TestFxn*
192 member_fxn(Cls* cls, Fxn fxn, const A& a)
193 {
194  return new TestMemberFxn1<Fxn,Cls,A>(fxn,cls,a);
195 }
196 
197 template <typename Fxn, class Cls, class A, class B>
198 TestFxn*
199 member_fxn(Cls* cls, Fxn fxn, const A& a, const B& b)
200 {
201  return new TestMemberFxn2<Fxn,Cls,A,B>(fxn,cls,a,b);
202 }
203 
204 template <typename Fxn, class Cls, class A, class B, class C>
205 TestFxn*
206 member_fxn(Cls* cls, Fxn fxn, const A& a, const B& b, const C& c)
207 {
208  return new TestMemberFxn3<Fxn,Cls,A,B,C>(fxn,cls,a,b,c);
209 }
210 
211 #endif // FXN_H
212 
void run()
Definition: fxn.h:87
void run()
Definition: fxn.h:108
Fxn fxn_
Definition: fxn.h:17
TestFxn2(Fxn fxn, const A &a, const B &b)
Definition: fxn.h:60
Definition: fxn.h:4
Cls * cls_
Definition: fxn.h:99
TestMemberFxn1(Fxn fxn, Cls *cls, const A &a)
Definition: fxn.h:104
Cls * cls_
Definition: fxn.h:120
TestMemberFxn2(Fxn fxn, Cls *cls, const A &a, const B &b)
Definition: fxn.h:127
Definition: fxn.h:49
void run()
Definition: fxn.h:131
Fxn fxn_
Definition: fxn.h:97
TestFxn * static_fxn(Fxn fxn)
Definition: fxn.h:163
void run()
Definition: fxn.h:64
C c_
Definition: fxn.h:80
Fxn fxn_
Definition: fxn.h:141
TestMemberFxn3(Fxn fxn, Cls *cls, const A &a, const B &b, const C &c)
Definition: fxn.h:152
Fxn fxn_
Definition: fxn.h:53
Definition: fxn.h:70
Definition: fxn.h:30
A a_
Definition: fxn.h:55
Fxn fxn_
Definition: fxn.h:74
Fxn fxn_
Definition: fxn.h:34
TestFxn0(Fxn fxn)
Definition: fxn.h:20
void run()
Definition: fxn.h:156
virtual void run()=0
A a_
Definition: fxn.h:36
B b_
Definition: fxn.h:78
B b_
Definition: fxn.h:57
void run()
Definition: fxn.h:24
void run()
Definition: fxn.h:43
Cls * cls_
Definition: fxn.h:143
A a_
Definition: fxn.h:76
TestFxn * member_fxn(Cls *cls, Fxn fxn, const A &a)
Definition: fxn.h:192
Definition: fxn.h:13
TestFxn3(Fxn fxn, const A &a, const B &b, const C &c)
Definition: fxn.h:83
TestFxn1(Fxn fxn, const A &a)
Definition: fxn.h:39
Fxn fxn_
Definition: fxn.h:118