Pothos  0.2.1-g9f04573d
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
CallInterfaceImpl.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 #include <Pothos/Config.hpp>
16 #include <utility> //std::forward
17 
18 namespace Pothos {
19 
20 /***********************************************************************
21  * Templated call gateways with 0 args
22  **********************************************************************/
23 template <typename ReturnType>
24 ReturnType CallInterface::call() const
25 {
26  Object r = this->callObject();
27  try
28  {
29  return r.convert<ReturnType>();
30  }
31  catch(const Exception &ex)
32  {
33  throw CallableReturnError("Pothos::Callable::call()", ex);
34  }
35 }
36 
37 
38 /***********************************************************************
39  * Templated call gateways with 1 args
40  **********************************************************************/
41 template <typename ReturnType, typename A0>
42 ReturnType CallInterface::call(A0 &&a0) const
43 {
44  Object r = this->callObject(std::forward<A0>(a0));
45  try
46  {
47  return r.convert<ReturnType>();
48  }
49  catch(const Exception &ex)
50  {
51  throw CallableReturnError("Pothos::Callable::call()", ex);
52  }
53 }
54 
55 template <typename A0>
57 {
58  Object args[1];
59  args[0] = Object(std::forward<A0>(a0));
60  return this->opaqueCall(args, 1);
61 }
62 
63 template <typename A0>
64 void CallInterface::callVoid(A0 &&a0) const
65 {
66  this->callObject(std::forward<A0>(a0));
67 }
68 
69 /***********************************************************************
70  * Templated call gateways with 2 args
71  **********************************************************************/
72 template <typename ReturnType, typename A0, typename A1>
73 ReturnType CallInterface::call(A0 &&a0, A1 &&a1) const
74 {
75  Object r = this->callObject(std::forward<A0>(a0), std::forward<A1>(a1));
76  try
77  {
78  return r.convert<ReturnType>();
79  }
80  catch(const Exception &ex)
81  {
82  throw CallableReturnError("Pothos::Callable::call()", ex);
83  }
84 }
85 
86 template <typename A0, typename A1>
87 Object CallInterface::callObject(A0 &&a0, A1 &&a1) const
88 {
89  Object args[2];
90  args[0] = Object(std::forward<A0>(a0));
91  args[1] = Object(std::forward<A1>(a1));
92  return this->opaqueCall(args, 2);
93 }
94 
95 template <typename A0, typename A1>
96 void CallInterface::callVoid(A0 &&a0, A1 &&a1) const
97 {
98  this->callObject(std::forward<A0>(a0), std::forward<A1>(a1));
99 }
100 
101 /***********************************************************************
102  * Templated call gateways with 3 args
103  **********************************************************************/
104 template <typename ReturnType, typename A0, typename A1, typename A2>
105 ReturnType CallInterface::call(A0 &&a0, A1 &&a1, A2 &&a2) const
106 {
107  Object r = this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2));
108  try
109  {
110  return r.convert<ReturnType>();
111  }
112  catch(const Exception &ex)
113  {
114  throw CallableReturnError("Pothos::Callable::call()", ex);
115  }
116 }
117 
118 template <typename A0, typename A1, typename A2>
119 Object CallInterface::callObject(A0 &&a0, A1 &&a1, A2 &&a2) const
120 {
121  Object args[3];
122  args[0] = Object(std::forward<A0>(a0));
123  args[1] = Object(std::forward<A1>(a1));
124  args[2] = Object(std::forward<A2>(a2));
125  return this->opaqueCall(args, 3);
126 }
127 
128 template <typename A0, typename A1, typename A2>
129 void CallInterface::callVoid(A0 &&a0, A1 &&a1, A2 &&a2) const
130 {
131  this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2));
132 }
133 
134 /***********************************************************************
135  * Templated call gateways with 4 args
136  **********************************************************************/
137 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3>
138 ReturnType CallInterface::call(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3) const
139 {
140  Object r = this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3));
141  try
142  {
143  return r.convert<ReturnType>();
144  }
145  catch(const Exception &ex)
146  {
147  throw CallableReturnError("Pothos::Callable::call()", ex);
148  }
149 }
150 
151 template <typename A0, typename A1, typename A2, typename A3>
152 Object CallInterface::callObject(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3) const
153 {
154  Object args[4];
155  args[0] = Object(std::forward<A0>(a0));
156  args[1] = Object(std::forward<A1>(a1));
157  args[2] = Object(std::forward<A2>(a2));
158  args[3] = Object(std::forward<A3>(a3));
159  return this->opaqueCall(args, 4);
160 }
161 
162 template <typename A0, typename A1, typename A2, typename A3>
163 void CallInterface::callVoid(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3) const
164 {
165  this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3));
166 }
167 
168 /***********************************************************************
169  * Templated call gateways with 5 args
170  **********************************************************************/
171 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4>
172 ReturnType CallInterface::call(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4) const
173 {
174  Object r = this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4));
175  try
176  {
177  return r.convert<ReturnType>();
178  }
179  catch(const Exception &ex)
180  {
181  throw CallableReturnError("Pothos::Callable::call()", ex);
182  }
183 }
184 
185 template <typename A0, typename A1, typename A2, typename A3, typename A4>
186 Object CallInterface::callObject(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4) const
187 {
188  Object args[5];
189  args[0] = Object(std::forward<A0>(a0));
190  args[1] = Object(std::forward<A1>(a1));
191  args[2] = Object(std::forward<A2>(a2));
192  args[3] = Object(std::forward<A3>(a3));
193  args[4] = Object(std::forward<A4>(a4));
194  return this->opaqueCall(args, 5);
195 }
196 
197 template <typename A0, typename A1, typename A2, typename A3, typename A4>
198 void CallInterface::callVoid(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4) const
199 {
200  this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4));
201 }
202 
203 /***********************************************************************
204  * Templated call gateways with 6 args
205  **********************************************************************/
206 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5>
207 ReturnType CallInterface::call(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5) const
208 {
209  Object r = this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), std::forward<A5>(a5));
210  try
211  {
212  return r.convert<ReturnType>();
213  }
214  catch(const Exception &ex)
215  {
216  throw CallableReturnError("Pothos::Callable::call()", ex);
217  }
218 }
219 
220 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5>
221 Object CallInterface::callObject(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5) const
222 {
223  Object args[6];
224  args[0] = Object(std::forward<A0>(a0));
225  args[1] = Object(std::forward<A1>(a1));
226  args[2] = Object(std::forward<A2>(a2));
227  args[3] = Object(std::forward<A3>(a3));
228  args[4] = Object(std::forward<A4>(a4));
229  args[5] = Object(std::forward<A5>(a5));
230  return this->opaqueCall(args, 6);
231 }
232 
233 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5>
234 void CallInterface::callVoid(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5) const
235 {
236  this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), std::forward<A5>(a5));
237 }
238 
239 /***********************************************************************
240  * Templated call gateways with 7 args
241  **********************************************************************/
242 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
243 ReturnType CallInterface::call(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5, A6 &&a6) const
244 {
245  Object r = this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), std::forward<A5>(a5), std::forward<A6>(a6));
246  try
247  {
248  return r.convert<ReturnType>();
249  }
250  catch(const Exception &ex)
251  {
252  throw CallableReturnError("Pothos::Callable::call()", ex);
253  }
254 }
255 
256 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
257 Object CallInterface::callObject(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5, A6 &&a6) const
258 {
259  Object args[7];
260  args[0] = Object(std::forward<A0>(a0));
261  args[1] = Object(std::forward<A1>(a1));
262  args[2] = Object(std::forward<A2>(a2));
263  args[3] = Object(std::forward<A3>(a3));
264  args[4] = Object(std::forward<A4>(a4));
265  args[5] = Object(std::forward<A5>(a5));
266  args[6] = Object(std::forward<A6>(a6));
267  return this->opaqueCall(args, 7);
268 }
269 
270 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
271 void CallInterface::callVoid(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5, A6 &&a6) const
272 {
273  this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), std::forward<A5>(a5), std::forward<A6>(a6));
274 }
275 
276 /***********************************************************************
277  * Templated call gateways with 8 args
278  **********************************************************************/
279 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
280 ReturnType CallInterface::call(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5, A6 &&a6, A7 &&a7) const
281 {
282  Object r = this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), std::forward<A5>(a5), std::forward<A6>(a6), std::forward<A7>(a7));
283  try
284  {
285  return r.convert<ReturnType>();
286  }
287  catch(const Exception &ex)
288  {
289  throw CallableReturnError("Pothos::Callable::call()", ex);
290  }
291 }
292 
293 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
294 Object CallInterface::callObject(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5, A6 &&a6, A7 &&a7) const
295 {
296  Object args[8];
297  args[0] = Object(std::forward<A0>(a0));
298  args[1] = Object(std::forward<A1>(a1));
299  args[2] = Object(std::forward<A2>(a2));
300  args[3] = Object(std::forward<A3>(a3));
301  args[4] = Object(std::forward<A4>(a4));
302  args[5] = Object(std::forward<A5>(a5));
303  args[6] = Object(std::forward<A6>(a6));
304  args[7] = Object(std::forward<A7>(a7));
305  return this->opaqueCall(args, 8);
306 }
307 
308 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
309 void CallInterface::callVoid(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5, A6 &&a6, A7 &&a7) const
310 {
311  this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), std::forward<A5>(a5), std::forward<A6>(a6), std::forward<A7>(a7));
312 }
313 
314 /***********************************************************************
315  * Templated call gateways with 9 args
316  **********************************************************************/
317 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
318 ReturnType CallInterface::call(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5, A6 &&a6, A7 &&a7, A8 &&a8) const
319 {
320  Object r = this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), std::forward<A5>(a5), std::forward<A6>(a6), std::forward<A7>(a7), std::forward<A8>(a8));
321  try
322  {
323  return r.convert<ReturnType>();
324  }
325  catch(const Exception &ex)
326  {
327  throw CallableReturnError("Pothos::Callable::call()", ex);
328  }
329 }
330 
331 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
332 Object CallInterface::callObject(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5, A6 &&a6, A7 &&a7, A8 &&a8) const
333 {
334  Object args[9];
335  args[0] = Object(std::forward<A0>(a0));
336  args[1] = Object(std::forward<A1>(a1));
337  args[2] = Object(std::forward<A2>(a2));
338  args[3] = Object(std::forward<A3>(a3));
339  args[4] = Object(std::forward<A4>(a4));
340  args[5] = Object(std::forward<A5>(a5));
341  args[6] = Object(std::forward<A6>(a6));
342  args[7] = Object(std::forward<A7>(a7));
343  args[8] = Object(std::forward<A8>(a8));
344  return this->opaqueCall(args, 9);
345 }
346 
347 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
348 void CallInterface::callVoid(A0 &&a0, A1 &&a1, A2 &&a2, A3 &&a3, A4 &&a4, A5 &&a5, A6 &&a6, A7 &&a7, A8 &&a8) const
349 {
350  this->callObject(std::forward<A0>(a0), std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), std::forward<A5>(a5), std::forward<A6>(a6), std::forward<A7>(a7), std::forward<A8>(a8));
351 }
352 
353 } //namespace Pothos
virtual Object opaqueCall(const Object *inputArgs, const size_t numArgs) const =0
ReturnType call() const
Call a bound method/function with a return type and 0 args.
Definition: CallInterfaceImpl.hpp:24
Object callObject() const
Call a bound method/function with an Object return and 0 args.
Definition: CallInterface.tmpl.hpp:57
void callVoid() const
Call a bound method/function with a void return and 0 args.
Definition: CallInterface.tmpl.hpp:62
Definition: Object.hpp:55
ValueType convert(void) const
Definition: ObjectImpl.hpp:227
Definition: Exception.hpp:65