Pothos  0.2.1-g9f04573d
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
ProxyImpl.tmpl.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 #for $NARGS in range($MAX_ARGS)
66 template <typename ReturnType, $expand('typename A%d', $NARGS)>
67 ReturnType Proxy::call(const std::string &name, $expand('const A%d &a%d', $NARGS)) const
68 {
69  Proxy args[$(max(1, $NARGS))];
70  #for $i in range($NARGS):
71  args[$i] = Detail::makeProxy(this->getEnvironment(), a$i);
72  #end for
73  auto handle = this->getHandle();
74  assert(handle);
75  Proxy ret = handle->call(name, args, $NARGS);
76  return Detail::convertProxy<ReturnType>(ret);
77 }
78 
79 #cond $NARGS > 0
80 template <$expand('typename A%d', $NARGS)>
81 Proxy Proxy::callProxy(const std::string &name, $expand('const A%d &a%d', $NARGS)) const
82 {
83  return this->call<Proxy, $expand('A%d', $NARGS)>(name, $expand('a%d', $NARGS));
84 }
85 
86 template <$expand('typename A%d', $NARGS)>
87 void Proxy::callVoid(const std::string &name, $expand('const A%d &a%d', $NARGS)) const
88 {
89  this->call<Proxy, $expand('A%d', $NARGS)>(name, $expand('a%d', $NARGS));
90 }
91 #end if
92 
93 #end for
94 
95 } //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