Pothos  0.2.1-g9f04573d
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
ProxyImpl.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 #include <Pothos/Config.hpp>
14 #include <Pothos/Proxy/Proxy.hpp>
15 #include <Pothos/Proxy/Handle.hpp>
17 #include <type_traits> //enable_if
18 #include <cassert>
19 
20 namespace Pothos {
21 
22 template <typename ValueType>
23 ValueType Proxy::convert(void) const
24 {
25  return this->getEnvironment()->convertProxyToObject(*this).convert<ValueType>();
26 }
27 
28 namespace Detail {
29 
30 /***********************************************************************
31  * convertProxy either converts a proxy to a desired type
32  * or returns a proxy if the requested type was a proxy
33  **********************************************************************/
34 template <typename T>
35 typename std::enable_if<!std::is_same<T, Proxy>::value, T>::type
36 convertProxy(const Proxy &p)
37 {
38  return p.convert<T>();
39 }
40 
41 template <typename T>
42 typename std::enable_if<std::is_same<T, Proxy>::value, T>::type
43 convertProxy(const Proxy &p)
44 {
45  return p;
46 }
47 
48 /***********************************************************************
49  * makeProxy either makes a proxy from an arbitrary type
50  * or returns a proxy if the type is already a proxy
51  **********************************************************************/
52 template <typename T>
53 Proxy makeProxy(const ProxyEnvironment::Sptr &env, const T &value)
54 {
55  return env->makeProxy(value);
56 }
57 
58 inline Proxy makeProxy(const ProxyEnvironment::Sptr &, const Proxy &value)
59 {
60  return value;
61 }
62 
63 } //namespace Detail
64 
65 template <typename ReturnType>
66 ReturnType Proxy::call(const std::string &name) const
67 {
68  Proxy args[1];
69  auto handle = this->getHandle();
70  assert(handle);
71  Proxy ret = handle->call(name, args, 0);
72  return Detail::convertProxy<ReturnType>(ret);
73 }
74 
75 
76 template <typename ReturnType, typename A0>
77 ReturnType Proxy::call(const std::string &name, const A0 &a0) const
78 {
79  Proxy args[1];
80  args[0] = Detail::makeProxy(this->getEnvironment(), a0);
81  auto handle = this->getHandle();
82  assert(handle);
83  Proxy ret = handle->call(name, args, 1);
84  return Detail::convertProxy<ReturnType>(ret);
85 }
86 
87 template <typename A0>
88 Proxy Proxy::callProxy(const std::string &name, const A0 &a0) const
89 {
90  return this->call<Proxy, A0>(name, a0);
91 }
92 
93 template <typename A0>
94 void Proxy::callVoid(const std::string &name, const A0 &a0) const
95 {
96  this->call<Proxy, A0>(name, a0);
97 }
98 
99 template <typename ReturnType, typename A0, typename A1>
100 ReturnType Proxy::call(const std::string &name, const A0 &a0, const A1 &a1) const
101 {
102  Proxy args[2];
103  args[0] = Detail::makeProxy(this->getEnvironment(), a0);
104  args[1] = Detail::makeProxy(this->getEnvironment(), a1);
105  auto handle = this->getHandle();
106  assert(handle);
107  Proxy ret = handle->call(name, args, 2);
108  return Detail::convertProxy<ReturnType>(ret);
109 }
110 
111 template <typename A0, typename A1>
112 Proxy Proxy::callProxy(const std::string &name, const A0 &a0, const A1 &a1) const
113 {
114  return this->call<Proxy, A0, A1>(name, a0, a1);
115 }
116 
117 template <typename A0, typename A1>
118 void Proxy::callVoid(const std::string &name, const A0 &a0, const A1 &a1) const
119 {
120  this->call<Proxy, A0, A1>(name, a0, a1);
121 }
122 
123 template <typename ReturnType, typename A0, typename A1, typename A2>
124 ReturnType Proxy::call(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2) const
125 {
126  Proxy args[3];
127  args[0] = Detail::makeProxy(this->getEnvironment(), a0);
128  args[1] = Detail::makeProxy(this->getEnvironment(), a1);
129  args[2] = Detail::makeProxy(this->getEnvironment(), a2);
130  auto handle = this->getHandle();
131  assert(handle);
132  Proxy ret = handle->call(name, args, 3);
133  return Detail::convertProxy<ReturnType>(ret);
134 }
135 
136 template <typename A0, typename A1, typename A2>
137 Proxy Proxy::callProxy(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2) const
138 {
139  return this->call<Proxy, A0, A1, A2>(name, a0, a1, a2);
140 }
141 
142 template <typename A0, typename A1, typename A2>
143 void Proxy::callVoid(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2) const
144 {
145  this->call<Proxy, A0, A1, A2>(name, a0, a1, a2);
146 }
147 
148 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3>
149 ReturnType Proxy::call(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3) const
150 {
151  Proxy args[4];
152  args[0] = Detail::makeProxy(this->getEnvironment(), a0);
153  args[1] = Detail::makeProxy(this->getEnvironment(), a1);
154  args[2] = Detail::makeProxy(this->getEnvironment(), a2);
155  args[3] = Detail::makeProxy(this->getEnvironment(), a3);
156  auto handle = this->getHandle();
157  assert(handle);
158  Proxy ret = handle->call(name, args, 4);
159  return Detail::convertProxy<ReturnType>(ret);
160 }
161 
162 template <typename A0, typename A1, typename A2, typename A3>
163 Proxy Proxy::callProxy(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3) const
164 {
165  return this->call<Proxy, A0, A1, A2, A3>(name, a0, a1, a2, a3);
166 }
167 
168 template <typename A0, typename A1, typename A2, typename A3>
169 void Proxy::callVoid(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3) const
170 {
171  this->call<Proxy, A0, A1, A2, A3>(name, a0, a1, a2, a3);
172 }
173 
174 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4>
175 ReturnType Proxy::call(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) const
176 {
177  Proxy args[5];
178  args[0] = Detail::makeProxy(this->getEnvironment(), a0);
179  args[1] = Detail::makeProxy(this->getEnvironment(), a1);
180  args[2] = Detail::makeProxy(this->getEnvironment(), a2);
181  args[3] = Detail::makeProxy(this->getEnvironment(), a3);
182  args[4] = Detail::makeProxy(this->getEnvironment(), a4);
183  auto handle = this->getHandle();
184  assert(handle);
185  Proxy ret = handle->call(name, args, 5);
186  return Detail::convertProxy<ReturnType>(ret);
187 }
188 
189 template <typename A0, typename A1, typename A2, typename A3, typename A4>
190 Proxy Proxy::callProxy(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) const
191 {
192  return this->call<Proxy, A0, A1, A2, A3, A4>(name, a0, a1, a2, a3, a4);
193 }
194 
195 template <typename A0, typename A1, typename A2, typename A3, typename A4>
196 void Proxy::callVoid(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) const
197 {
198  this->call<Proxy, A0, A1, A2, A3, A4>(name, a0, a1, a2, a3, a4);
199 }
200 
201 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5>
202 ReturnType Proxy::call(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) const
203 {
204  Proxy args[6];
205  args[0] = Detail::makeProxy(this->getEnvironment(), a0);
206  args[1] = Detail::makeProxy(this->getEnvironment(), a1);
207  args[2] = Detail::makeProxy(this->getEnvironment(), a2);
208  args[3] = Detail::makeProxy(this->getEnvironment(), a3);
209  args[4] = Detail::makeProxy(this->getEnvironment(), a4);
210  args[5] = Detail::makeProxy(this->getEnvironment(), a5);
211  auto handle = this->getHandle();
212  assert(handle);
213  Proxy ret = handle->call(name, args, 6);
214  return Detail::convertProxy<ReturnType>(ret);
215 }
216 
217 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5>
218 Proxy Proxy::callProxy(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) const
219 {
220  return this->call<Proxy, A0, A1, A2, A3, A4, A5>(name, a0, a1, a2, a3, a4, a5);
221 }
222 
223 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5>
224 void Proxy::callVoid(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) const
225 {
226  this->call<Proxy, A0, A1, A2, A3, A4, A5>(name, a0, a1, a2, a3, a4, a5);
227 }
228 
229 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
230 ReturnType Proxy::call(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6) const
231 {
232  Proxy args[7];
233  args[0] = Detail::makeProxy(this->getEnvironment(), a0);
234  args[1] = Detail::makeProxy(this->getEnvironment(), a1);
235  args[2] = Detail::makeProxy(this->getEnvironment(), a2);
236  args[3] = Detail::makeProxy(this->getEnvironment(), a3);
237  args[4] = Detail::makeProxy(this->getEnvironment(), a4);
238  args[5] = Detail::makeProxy(this->getEnvironment(), a5);
239  args[6] = Detail::makeProxy(this->getEnvironment(), a6);
240  auto handle = this->getHandle();
241  assert(handle);
242  Proxy ret = handle->call(name, args, 7);
243  return Detail::convertProxy<ReturnType>(ret);
244 }
245 
246 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
247 Proxy Proxy::callProxy(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6) const
248 {
249  return this->call<Proxy, A0, A1, A2, A3, A4, A5, A6>(name, a0, a1, a2, a3, a4, a5, a6);
250 }
251 
252 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
253 void Proxy::callVoid(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6) const
254 {
255  this->call<Proxy, A0, A1, A2, A3, A4, A5, A6>(name, a0, a1, a2, a3, a4, a5, a6);
256 }
257 
258 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
259 ReturnType Proxy::call(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7) const
260 {
261  Proxy args[8];
262  args[0] = Detail::makeProxy(this->getEnvironment(), a0);
263  args[1] = Detail::makeProxy(this->getEnvironment(), a1);
264  args[2] = Detail::makeProxy(this->getEnvironment(), a2);
265  args[3] = Detail::makeProxy(this->getEnvironment(), a3);
266  args[4] = Detail::makeProxy(this->getEnvironment(), a4);
267  args[5] = Detail::makeProxy(this->getEnvironment(), a5);
268  args[6] = Detail::makeProxy(this->getEnvironment(), a6);
269  args[7] = Detail::makeProxy(this->getEnvironment(), a7);
270  auto handle = this->getHandle();
271  assert(handle);
272  Proxy ret = handle->call(name, args, 8);
273  return Detail::convertProxy<ReturnType>(ret);
274 }
275 
276 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
277 Proxy Proxy::callProxy(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7) const
278 {
279  return this->call<Proxy, A0, A1, A2, A3, A4, A5, A6, A7>(name, a0, a1, a2, a3, a4, a5, a6, a7);
280 }
281 
282 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
283 void Proxy::callVoid(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7) const
284 {
285  this->call<Proxy, A0, A1, A2, A3, A4, A5, A6, A7>(name, a0, a1, a2, a3, a4, a5, a6, a7);
286 }
287 
288 template <typename ReturnType, typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
289 ReturnType Proxy::call(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8) const
290 {
291  Proxy args[9];
292  args[0] = Detail::makeProxy(this->getEnvironment(), a0);
293  args[1] = Detail::makeProxy(this->getEnvironment(), a1);
294  args[2] = Detail::makeProxy(this->getEnvironment(), a2);
295  args[3] = Detail::makeProxy(this->getEnvironment(), a3);
296  args[4] = Detail::makeProxy(this->getEnvironment(), a4);
297  args[5] = Detail::makeProxy(this->getEnvironment(), a5);
298  args[6] = Detail::makeProxy(this->getEnvironment(), a6);
299  args[7] = Detail::makeProxy(this->getEnvironment(), a7);
300  args[8] = Detail::makeProxy(this->getEnvironment(), a8);
301  auto handle = this->getHandle();
302  assert(handle);
303  Proxy ret = handle->call(name, args, 9);
304  return Detail::convertProxy<ReturnType>(ret);
305 }
306 
307 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
308 Proxy Proxy::callProxy(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8) const
309 {
310  return this->call<Proxy, A0, A1, A2, A3, A4, A5, A6, A7, A8>(name, a0, a1, a2, a3, a4, a5, a6, a7, a8);
311 }
312 
313 template <typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
314 void Proxy::callVoid(const std::string &name, const A0 &a0, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8) const
315 {
316  this->call<Proxy, A0, A1, A2, A3, A4, A5, A6, A7, A8>(name, a0, a1, a2, a3, a4, a5, a6, a7, a8);
317 }
318 
319 
320 } //namespace Pothos
ReturnType call(const std::string &name) const
Call a method with a return type and 0 args.
Definition: ProxyImpl.hpp:66
std::shared_ptr< ProxyEnvironment > Sptr
Definition: Environment.hpp:45
std::shared_ptr< ProxyEnvironment > getEnvironment(void) const
void callVoid(const std::string &name) const
Call a method with a void return and 0 args.
Definition: Proxy.hpp:240
Proxy callProxy(const std::string &name) const
Call a method with a Proxy return and 0 args.
Definition: Proxy.hpp:235
std::shared_ptr< ProxyHandle > getHandle(void) const
Get the handle held in this proxy object.
ValueType convert(void) const
Definition: ProxyImpl.hpp:23
Definition: Proxy.hpp:27