26 template<
class Ret=void,
class... Params>
30 template<
class Ret,
class... Params>
33 virtual ~CallerBase() { }
34 virtual CallerBase* Copy()
const = 0;
35 virtual Ret operator()(Params... params)
const = 0;
36 Caller<Ret, Params...> ToCaller() {
37 return Caller<Ret, Params...>(*this);
52 template<
class C,
class Ret=void,
class... Params>
55 template<
class Functor,
class Ret=void,
class... Params>
58 template<
class Ret=void,
class... Params>
77 template<
class Ret,
class... Params>
81 RC::APtr<CallerBase<Ret, Params...>> ptr;
93 template<
class Ret2,
class... Params2>
97 "Attempted to copy-construct Callers with mismatched parameters");
104 Caller(C*
object, Ret (C::*func)(Params...)) {
105 *
this = MemberCaller<C, Ret, Params...>(object, func);
110 Caller(C&
object, Ret (C::*func)(Params...)) {
111 *
this = MemberCaller<C, Ret, Params...>(&object, func);
119 template<
class C,
class... OneFewerParams>
120 Caller(Ret (C::*func)(OneFewerParams...)) {
121 *
this =
Caller<Ret, C&, OneFewerParams...>(std::mem_fn(func));
128 template<
class Functor>
130 *
this = FunctorCaller<Functor, Ret, Params...>(func);
137 Caller(
const CallerBase<Ret, Params...>& caller_base) {
138 ptr = caller_base.Copy();
142 ptr = caller_base.Copy();
154 virtual Ret
operator()(Params... params)
const {
return (*ptr)(params...); }
157 bool IsSet() {
return ptr.IsSet(); }
161 template<
class TupleType>
162 inline Ret
Use(TupleType tup) {
return tup.Apply(*
this); }
169 template<
class... Args>
170 auto Bind(Args... args) -> decltype(std::bind(*
this, args...)) {
171 return std::bind(*
this, args...);
177 template<
class C,
class Ret,
class... Params>
178 class MemberCaller :
public CallerBase<Ret, Params...> {
180 MemberCaller(C* obj, Ret (C::*func)(Params...)) : obj(obj), func(func) { }
181 virtual Ret operator()(Params... params)
const {
182 return (obj->*func)(params...);
184 virtual CallerBase<Ret, Params...>* Copy()
const {
185 return new MemberCaller<C, Ret, Params...>(obj, func);
190 Ret (C::*func)(Params...);
194 template<
class Functor,
class Ret,
class... Params>
195 class FunctorCaller :
public CallerBase<Ret, Params...> {
197 FunctorCaller(Functor func) : func(func) { }
199 virtual Ret operator()(Params... params)
const {
return func(params...); }
200 virtual CallerBase<Ret, Params...>* Copy()
const {
201 return new FunctorCaller<Functor, Ret, Params...>(func);
212 template<
class Ret,
class... Params,
class Ret2,
class... Params2>
213 class FunctorCaller<Ret (*)(Params...), Ret2, Params2...>
214 :
public StaticCaller<Ret2, Params2...> {
216 FunctorCaller(Ret (*func)(Params...))
217 : StaticCaller<Ret2, Params2...>(func) { }
221 template<
class Ret,
class... Params>
222 class StaticCaller :
public CallerBase<Ret, Params...> {
224 StaticCaller(Ret (*func)(Params...)) : func(func) { }
225 virtual Ret operator()(Params... params)
const {
226 return (*func)(params...);
228 virtual CallerBase<Ret, Params...>* Copy()
const {
229 return new StaticCaller<Ret, Params...>(func);
233 Ret (*func)(Params...);
240 template<
class C,
class Ret,
class... Params>
242 return MemberCaller<C, Ret, Params...>(obj, func);
247 template<
class C,
class Ret,
class... Params>
249 return MemberCaller<C, Ret, Params...>(&obj, func);
254 template<
class C,
class Ret,
class... Params>
257 return Caller<Ret, C&, Params...>(std::mem_fn(func));
262 template<
class Ret,
class... Params>
264 return StaticCaller<Ret, Params...>(func);
273 template<
class Ret,
class... Params,
class Functor>
275 return FunctorCaller<Functor, Ret, Params...>(func);
281 template<
class C,
class MemberFunc>
290 template<
class C,
class MemberFunc>
299 template<
class C,
class MemberFunc>
319 template<
class... Types>
321 : caller(new
Caller<Types...>(new_caller)) {
326 template<
class Ret,
class... Params>
328 caller =
new decltype(
MakeCaller(func))(func);
334 template<
class... Types>
336 return caller.As<
Caller<Types...>>();
339 template<
class... Types>
341 return caller.As<
Caller<Types...>>();
346 template<
class... Types>
348 return caller.CanCast<
Caller<Types...>>();
A reference counting ptr that is auto-deleted as the last copy leaves scope.
The version information and configuration settings for RC Lib.
A reference counting pointer that revokes (NULLs) all copies when one set to AutoRevoke(true) leaves ...
A reference counting ptr that auto-deletes what it points to when the last copy leaves scope or is ot...
Definition: APtr.h:39
A general purpose function class which can refer to any static method, member method,...
Definition: Caller.h:78
Caller(C *object, Ret(C::*func)(Params...))
Construct a Caller to a member function of a specific object.
Definition: Caller.h:104
Caller(C &object, Ret(C::*func)(Params...))
Construct a Caller to a member function of a specific object.
Definition: Caller.h:110
Caller()
Default constructor, refers to no function.
Definition: Caller.h:85
Caller(const Caller &other)
Copy constructor.
Definition: Caller.h:87
virtual Ret operator()(Params... params) const
Call the referenced function.
Definition: Caller.h:154
auto Bind(Args... args) -> decltype(std::bind(*this, args...))
Return a functor with arguments bound using syntax identical to std::bind.
Definition: Caller.h:170
Caller(Ret(C::*func)(OneFewerParams...))
Construct a Caller to a member function, where the inserted first parameter is a reference to the obj...
Definition: Caller.h:120
bool IsSet()
True if a function was set.
Definition: Caller.h:157
Caller(Functor func)
Construct a Caller to any general functor.
Definition: Caller.h:129
virtual ~Caller()
Destructor.
Definition: Caller.h:134
Ret Use(TupleType tup)
Call the referenced function with the parameters given as RC::Tuple tup.
Definition: Caller.h:162
Caller & operator=(const Caller< Ret, Params... > &other)
Assign a Caller of identical type.
Definition: Caller.h:148
A typeless container for a Caller, which has methods for dynamically casting it to the correct type.
Definition: Caller.h:309
DynCaller(Ret(*func)(Params...))
Creates a Caller referring to the given static function, and then wraps it.
Definition: Caller.h:327
bool CanCast() const
True if this can cast to a Caller with the specified template parameters.
Definition: Caller.h:347
Caller< Types... > & As()
Dynamically casts to the Caller of the specified template parameters, or throws ErrorMsgCast if it fa...
Definition: Caller.h:335
const Caller< Types... > & As() const
Const version of As().
Definition: Caller.h:340
DynCaller()
Default constructor, contains no Caller.
Definition: Caller.h:316
DynCaller(Caller< Types... > new_caller)
Construct a DynCaller which wraps new_caller.
Definition: Caller.h:320
A safe pointer class that throws an RC::ErrorMsgNull if a null dereference is attempted.
Definition: Ptr.h:31
A reference counting pointer that revokes (NULLs) all copies when one set to AutoRevoke(true) leaves ...
Definition: RevPtr.h:45
The base class of Caller without return type or parameters specified.
Definition: Caller.h:45
Caller< Ret, Params... > MakeFunctor(Functor func)
A special generator for functors, which requires specifying the return type and arguments.
Definition: Caller.h:274
Caller< Ret, Params... > MakeCaller(C *obj, Ret(C::*func)(Params...))
Generates a Caller for the member function of the given object, with type inference.
Definition: Caller.h:241