18 #include <type_traits> 26 CallableContainer(
void);
27 virtual ~CallableContainer(
void);
28 virtual size_t getNumArgs(
void)
const = 0;
29 virtual const std::type_info &type(
const int argNo) = 0;
30 virtual Object call(
const Object *args) = 0;
35 template <
typename ValueType>
38 return this->bind(
Object(std::forward<ValueType>(val)), argNo);
46 template <
typename ReturnType,
typename FcnRType,
typename... ArgsType>
47 class CallableFunctionContainer :
public Detail::CallableContainer
50 template <
typename FcnType>
51 CallableFunctionContainer(
const FcnType &fcn):
57 size_t getNumArgs(
void)
const 59 return sizeof...(ArgsType);
62 const std::type_info &type(
const int argNo)
64 return typeR<ArgsType..., ReturnType>(argNo);
76 const std::type_info &typeR(
const int argNo)
78 if (argNo == 0)
return typeid(T);
79 return typeid(ReturnType);
83 template <
typename T0,
typename T1,
typename... Ts>
84 const std::type_info &typeR(
const int argNo)
86 if (argNo == 0)
return typeid(T0);
87 return typeR<T1, Ts...>(argNo-1);
91 template<std::size_t ...S>
97 std::is_void<ReturnType>::value,
98 std::is_same<ReturnType, FcnRType>::value,
99 std::is_reference<ReturnType>::value and
100 not std::is_const<typename std::remove_reference<ReturnType>::type>::value
101 >::call(_fcn, args[S].extract<ArgsType>()...);
105 void checkArgs(
const Object *){}
108 template <
typename FcnType,
bool isVo
id,
bool isSameR,
bool isReference>
struct CallHelper;
109 template <
typename FcnType>
struct CallHelper<FcnType, false, true, false>
111 static Object call(
const FcnType &fcn,
const ArgsType&... args)
116 template <
typename FcnType>
struct CallHelper<FcnType, false, false, false>
118 static Object call(
const FcnType &fcn,
const ArgsType&... args)
123 template <
typename FcnType>
struct CallHelper<FcnType, false, true, true>
125 static Object call(
const FcnType &fcn,
const ArgsType&... args)
130 template <
typename FcnType>
struct CallHelper<FcnType, true, true, false>
132 static Object call(
const FcnType &fcn,
const ArgsType&... args)
134 fcn(args...);
return Object();
138 std::function<FcnRType(ArgsType...)> _fcn;
141 template <
typename ClassType,
typename... ArgsType>
142 Object CallableFactoryNewWrapper(ArgsType&&... args)
144 return Object(
new ClassType(std::forward<ArgsType>(args)...));
152 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
154 _impl(new Detail::CallableFunctionContainer<ReturnType, ReturnType, ClassType &, ArgsType...>(std::mem_fn(fcn)))
159 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
161 _impl(
new Detail::CallableFunctionContainer<ReturnType, ReturnType, const ClassType &, ArgsType...>(std::mem_fn(fcn)))
166 template <
typename ReturnType,
typename... ArgsType>
168 _impl(new Detail::CallableFunctionContainer<ReturnType, ReturnType, ArgsType...>(fcn))
173 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
179 template <
typename ReturnType,
typename ClassType,
typename... ArgsType>
185 template <
typename ReturnType,
typename... ArgsType>
191 template <
typename ClassType,
typename... ArgsType>
194 return Callable(
new Detail::CallableFunctionContainer<ClassType, Object, ArgsType...>(
195 &Object::emplace<ClassType, ArgsType...>));
198 template <
typename ClassType,
typename... ArgsType>
201 return Callable(
new Detail::CallableFunctionContainer<ClassType *, Object, ArgsType...>(
202 &Detail::CallableFactoryNewWrapper<ClassType, ArgsType...>));
205 template <
typename ClassType,
typename... ArgsType>
208 using SharedType = std::shared_ptr<ClassType>;
209 return Callable(
new Detail::CallableFunctionContainer<SharedType, SharedType, ArgsType...>(
210 &std::make_shared<ClassType, ArgsType...>));
static Callable make(ReturnType(ClassType::*fcn)(ArgsType...))
Definition: CallableImpl.hpp:174
#define POTHOS_API
Definition: Config.hpp:41
Callable & bind(ValueType &&val, const size_t argNo)
Definition: CallableImpl.hpp:36
static Object make(ValueType &&value)
Definition: ObjectImpl.hpp:110
make_index_sequence< sizeof...(T)> index_sequence_for
Definition: Templates.hpp:116
Definition: Callable.hpp:30
Definition: Templates.hpp:67
Definition: ArchiveEntry.hpp:20
static Callable factoryShared(void)
Definition: CallableImpl.hpp:206
Definition: Object.hpp:47
static Callable factoryNew(void)
Definition: CallableImpl.hpp:199
static Callable factory(void)
Definition: CallableImpl.hpp:192