Design Patterns
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
simple_command.h
Go to the documentation of this file.
1 // Based on "Design Patterns: Elements of Reusable Object-Oriented Software"
2 // book by Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm
3 //
4 // Created by Bartosz Rachwal. The National Institute of Advanced Industrial Science and Technology, Japan.
5 
6 #ifndef OPERATIONAL_COMMAND_SIMPLE_COMMAND_H_
7 #define OPERATIONAL_COMMAND_SIMPLE_COMMAND_H_
8 
9 #include "command_interface.h"
10 
11 namespace operational
12 {
13 namespace command
14 {
15 template<class Receiver>
17 {
18  public:
19  typedef void (Receiver::* Action)();
20 
21  SimpleCommand(Receiver* r, Action a);
22 
23  virtual void Execute() override;
24 
25  private:
26  Action action_;
27  Receiver* receiver_;
28 };
29 
30 template<class Receiver>
31 SimpleCommand<Receiver>::SimpleCommand(Receiver* receiver, Action action): action_(action), receiver_(receiver) { }
32 
33 template<class Receiver>
35 {
36  (receiver_ ->* action_)();
37 }
38 }
39 }
40 
41 #endif
42 
Definition: application.cc:10
void(Receiver::* Action)()
Definition: simple_command.h:19
virtual void Execute() override
Definition: simple_command.h:34
Definition: simple_command.h:16
SimpleCommand(Receiver *r, Action a)
Definition: simple_command.h:31
Definition: command_interface.h:13