tbx  0.7.5
command.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 
26 #ifndef TBX_COMMAND_H
27 #define TBX_COMMAND_H
28 
29 #include "listener.h"
30 
31 namespace tbx
32 {
36  class Command : public Listener
37  {
38  public:
39  Command() {}
40  virtual ~Command() {};
41 
45  virtual void execute() = 0;
46  };
47 
48 
52  template<class T> class CommandMethod : public Command
53  {
54  T *_call;
55  void (T::*_method)();
56 
57  public:
65  CommandMethod(T *call, void (T::*method)()) : _call(call), _method(method) {}
66 
70  virtual void execute()
71  {
72  (_call->*_method)();
73  }
74  };
75 }
76 
77 #endif
78 
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
Base class for commands in tbx.
Definition: command.h:36
Template to create a command that calls a member function.
Definition: command.h:52
virtual void execute()=0
This method is call to execute the command.
Base class for all toolbox event listeners.
Definition: listener.h:33
CommandMethod(T *call, void(T::*method)())
Construct the Command method for the given object and method on it.
Definition: command.h:65
virtual void execute()
Calls the method on the object given in the constructor.
Definition: command.h:70