MeVisLab Toolbox Reference
mlBackgroundTaskMethodCallMessage.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2009, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_BACKGROUND_TASK_METHOD_CALL_MESSAGE_H
14 #define ML_BACKGROUND_TASK_METHOD_CALL_MESSAGE_H
15 
16 // Local includes
19 #include "mlBackgroundTask.h"
20 #include <mlArgumentList.h>
21 
22 ML_START_NAMESPACE
23 
26 template<class Object, class Method, class ArgumentList>
28 public:
29  BackgroundTaskMethodCallMessage(Object* object, Method method, const ArgumentList& args):
31  _object(object), _method(method), _args(args) {
32  setReceiverHelper(object);
33  }
34 
35  void execute() override {
36  if (!sender() || sender()->hasOwner()) {
37  MLCallMethodWithArguments(_object, _method, _args);
38  }
39  }
40 
41 private:
42  // only set receiver if object has the correct type
43  void setReceiverHelper(BackgroundTaskMessageReceiver* receiverArg) {
44  setReceiver(receiverArg);
45  }
46 
47  void setReceiverHelper(void*) {};
48 
49  Object* _object;
50  Method _method;
51  ArgumentList _args;
52 };
53 
55 template<class Object, class Method>
56 inline BackgroundTaskMessage* NewBackgroundTaskMethodCall(Object* object, Method method) {
58 }
59 
61 template<class Object, class Method, class Arg1>
62 inline BackgroundTaskMessage* NewBackgroundTaskMethodCall(Object* object, Method method, const Arg1& arg1) {
64 }
65 
67 template<class Object, class Method, class Arg1, class Arg2>
68 inline BackgroundTaskMessage* NewBackgroundTaskMethodCall(Object* object, Method method, const Arg1& arg1, const Arg2& arg2) {
70 }
71 
73 template<class Object, class Method, class Arg1, class Arg2, class Arg3>
74 inline BackgroundTaskMessage* NewBackgroundTaskMethodCall(Object* object, Method method, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) {
76 }
77 
79 template<class Object, class Method, class Arg1, class Arg2, class Arg3, class Arg4>
80 inline BackgroundTaskMessage* NewBackgroundTaskMethodCall(Object* object, Method method, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4) {
82 }
83 
85 template<class Object, class Method, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
86 inline BackgroundTaskMessage* NewBackgroundTaskMethodCall(Object* object, Method method, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) {
88 }
89 
90 ML_END_NAMESPACE
91 
92 #endif
93 
94 
The background task receiver is a light-weight base class which can be inherited (e....
The base class of all background messages.
a generic message that allows to call the member function method on a given object,...
BackgroundTaskMethodCallMessage(Object *object, Method method, const ArgumentList &args)
void execute() override
execute message when it is delivered (reimplement in subclasses)
ArgumentList0 MLGenerateArgumentList()
Creates argument list with 0 arguments.
BackgroundTaskMessage * NewBackgroundTaskMethodCall(Object *object, Method method, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
create new method call with 5 arguments
void MLCallMethodWithArguments(Object *object, Method method, const ArgumentList0 &)
Calls a method on given object with 0 arguments.