17 #include <type_traits>
25 CallableContainer(
void);
26 virtual ~CallableContainer(
void);
27 virtual size_t getNumArgs(
void)
const = 0;
28 virtual const std::type_info &type(
const int argNo) = 0;
29 virtual Object call(
const Object *args) = 0;
34 template <
typename ValueType>
37 return this->
bind(
Object(std::forward<ValueType>(val)), argNo);
45 template <
typename ReturnType,
typename... ArgsType>
46 class CallableFunctionContainer :
public Detail::CallableContainer
49 template <
typename FcnType>
50 CallableFunctionContainer(
const FcnType &fcn):
56 size_t getNumArgs(
void)
const
58 return sizeof...(ArgsType);
61 const std::type_info &type(
const int argNo)
63 return typeR<ArgsType..., ReturnType>(argNo);
66 Object call(
const Object *args)
68 return call(args,
typename Gens<
sizeof...(ArgsType)>::Type());
75 const std::type_info &typeR(
const int argNo)
77 if (argNo == 0)
return typeid(T);
78 return typeid(ReturnType);
82 template <
typename T0,
typename T1,
typename... Ts>
83 const std::type_info &typeR(
const int argNo)
85 if (argNo == 0)
return typeid(T0);
86 return typeR<T1, Ts...>(argNo-1);
90 template<
int...>
struct Seq {};
91 template<
int N,
int... S>
struct Gens : Gens<N-1, N-1, S...> {};
92 template<
int... S>
struct Gens<0, S...>{
typedef Seq<S...> Type; };
96 Object call(
const Object *args, Seq<S...>)
100 decltype(_fcn), std::is_void<ReturnType>::value
101 >::call(_fcn, args[S].extract<ArgsType>()...);
105 void checkArgs(
const Object *){}
108 template <
typename FcnType,
bool Condition>
struct CallHelper;
109 template <
typename FcnType>
struct CallHelper<FcnType, false>
111 static Object call(
const FcnType &fcn,
const ArgsType&... args)
116 template <
typename FcnType>
struct CallHelper<FcnType, true>
118 static Object call(
const FcnType &fcn,
const ArgsType&... args)
120 fcn(args...);
return Object();
124 std::function<ReturnType(ArgsType...)> _fcn;
127 template <
typename ClassType,
typename... ArgsType>
128 ClassType CallableFactoryWrapper(
const ArgsType&... args)
130 return ClassType(args...);
133 template <
typename ClassType,
typename... ArgsType>
134 ClassType *CallableFactoryNewWrapper(
const ArgsType&... args)
136 return new ClassType(args...);
139 template <
typename ClassType,
typename... ArgsType>
140 std::shared_ptr<ClassType> CallableFactorySharedWrapper(
const ArgsType&... args)
142 return std::shared_ptr<ClassType>(
new ClassType(args...));
150 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
152 _impl(new Detail::CallableFunctionContainer<ReturnType, ClassType &, ArgsType...>(std::mem_fn(fcn)))
157 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
159 _impl(new Detail::CallableFunctionContainer<ReturnType, const ClassType &, ArgsType...>(std::mem_fn(fcn)))
164 template <
typename ReturnType,
typename... ArgsType>
166 _impl(new Detail::CallableFunctionContainer<ReturnType, ArgsType...>(fcn))
171 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
177 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
183 template <
typename ReturnType,
typename... ArgsType>
189 template <
typename ClassType,
typename... ArgsType>
192 return Callable(&Detail::CallableFactoryWrapper<ClassType, ArgsType...>);
195 template <
typename ClassType,
typename... ArgsType>
198 return Callable(&Detail::CallableFactoryNewWrapper<ClassType, ArgsType...>);
201 template <
typename ClassType,
typename... ArgsType>
204 return Callable(&Detail::CallableFactorySharedWrapper<ClassType, ArgsType...>);
static Callable make(ReturnType(ClassType::*fcn)(ArgsType...))
Definition: CallableImpl.hpp:172
#define POTHOS_API
Definition: Config.hpp:41
Callable & bind(ValueType &&val, const size_t argNo)
Definition: CallableImpl.hpp:35
static Object make(ValueType &&value)
Definition: ObjectImpl.hpp:206
Definition: Callable.hpp:30
static Callable factoryShared(void)
Definition: CallableImpl.hpp:202
Definition: Object.hpp:55
static Callable factoryNew(void)
Definition: CallableImpl.hpp:196
static Callable factory(void)
Definition: CallableImpl.hpp:190