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);
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);
93 template<
int...>
struct Seq {};
94 template<
int N,
int... S>
struct Gens : Gens<N-1, N-1, S...> {};
95 template<
int... S>
struct Gens<0, S...>{
typedef Seq<S...> Type; };
104 decltype(_fcn), std::is_void<ReturnType>::value
105 >::call(_fcn, args[S].extract<ArgsType>()...);
109 void checkArgs(
const Object *){}
112 template <
typename FcnType,
bool Condition>
struct CallHelper;
113 template <
typename FcnType>
struct CallHelper<FcnType, false>
115 static Object call(
const FcnType &fcn,
const ArgsType&... args)
120 template <
typename FcnType>
struct CallHelper<FcnType, true>
122 static Object call(
const FcnType &fcn,
const ArgsType&... args)
124 fcn(args...);
return Object();
128 std::function<ReturnType(ArgsType...)> _fcn;
131 template <
typename ClassType,
typename... ArgsType>
132 ClassType CallableFactoryWrapper(
const ArgsType&... args)
134 return ClassType(args...);
137 template <
typename ClassType,
typename... ArgsType>
138 ClassType *CallableFactoryNewWrapper(
const ArgsType&... args)
140 return new ClassType(args...);
143 template <
typename ClassType,
typename... ArgsType>
144 std::shared_ptr<ClassType> CallableFactorySharedWrapper(
const ArgsType&... args)
146 return std::shared_ptr<ClassType>(
new ClassType(args...));
154 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
156 _impl(new Detail::CallableFunctionContainer<ReturnType, ClassType &, ArgsType...>(std::mem_fn(fcn)))
161 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
163 _impl(
new Detail::CallableFunctionContainer<ReturnType, const ClassType &, ArgsType...>(std::mem_fn(fcn)))
168 template <
typename ReturnType,
typename... ArgsType>
170 _impl(new Detail::CallableFunctionContainer<ReturnType, ArgsType...>(fcn))
175 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
181 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
187 template <
typename ReturnType,
typename... ArgsType>
193 template <
typename ClassType,
typename... ArgsType>
196 return Callable(&Detail::CallableFactoryWrapper<ClassType, ArgsType...>);
199 template <
typename ClassType,
typename... ArgsType>
202 return Callable(&Detail::CallableFactoryNewWrapper<ClassType, ArgsType...>);
205 template <
typename ClassType,
typename... ArgsType>
208 return Callable(&Detail::CallableFactorySharedWrapper<ClassType, ArgsType...>);
static Callable make(ReturnType(ClassType::*fcn)(ArgsType...))
Definition: CallableImpl.hpp:176
#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
Definition: Testing.hpp:134
static Callable factoryShared(void)
Definition: CallableImpl.hpp:206
Definition: Object.hpp:55
static Callable factoryNew(void)
Definition: CallableImpl.hpp:200
static Callable factory(void)
Definition: CallableImpl.hpp:194