HoverRace  2.0
ControlAction.h
Go to the documentation of this file.
1 
2 // ControlAction.h
3 //
4 // Copyright (c) 2010 Ryan Curtin.
5 // Copyright (c) 2015-2016 Michael Imamura.
6 //
7 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
8 // you may not use this file except in compliance with the License.
9 //
10 // A copy of the license should have been attached to the package from which
11 // you have taken this file. If you can not find the license you can not use
12 // this file.
13 //
14 //
15 // The author makes no representations about the suitability of
16 // this software for any purpose. It is provided "as is" "AS IS",
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
18 // implied.
19 //
20 // See the License for the specific language governing permissions
21 // and limitations under the License.
22 //
23 
24 #pragma once
25 
26 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
27 # ifdef MR_ENGINE
28 # define MR_DllDeclare __declspec( dllexport )
29 # else
30 # define MR_DllDeclare __declspec( dllimport )
31 # endif
32 #else
33 # define MR_DllDeclare
34 #endif
35 
36 namespace HoverRace {
37 namespace Control {
38 
49 template<class T>
51 {
52 public:
54  ControlAction(const std::string &name, int listOrder) :
55  name(name), listOrder(listOrder) { }
56  virtual ~ControlAction() { }
57 
58  virtual void operator()(T eventValue) = 0;
59 
60  const std::string &GetName() const noexcept { return name; }
61  int GetListOrder() const noexcept { return listOrder; }
62 
63 protected:
64  std::string name;
65  int listOrder;
66 };
67 using ControlActionPtr = std::shared_ptr<ControlAction<int>>;
68 
69 template<class T>
70 std::ostream &operator<<(std::ostream &os, const ControlAction<T> &action)
71 {
72  os << action.GetName();
73  return os;
74 }
75 
82 {
84 
85 public:
86  BlankAction() : SUPER() { }
87  BlankAction(const std::string &name, int listOrder) :
88  SUPER(name, listOrder) { }
89  virtual ~BlankAction() { }
90 
91  virtual void operator()(int) { }
92 };
93 
94 } // namespace Control
95 } // namespace HoverRace
96 
97 #undef MR_DllDeclare
std::string name
Definition: ControlAction.h:64
virtual void operator()(int)
Definition: ControlAction.h:91
int listOrder
Definition: ControlAction.h:65
BlankAction()
Definition: ControlAction.h:86
std::shared_ptr< ControlAction< int >> ControlActionPtr
Definition: ControlAction.h:67
Abstract base class which allows us a simple reference to arbitrary functors of type ControlActionImp...
Definition: ControlAction.h:50
BlankAction(const std::string &name, int listOrder)
Definition: ControlAction.h:87
ControlAction(const std::string &name, int listOrder)
Definition: ControlAction.h:54
virtual ~BlankAction()
Definition: ControlAction.h:89
#define MR_DllDeclare
Definition: ControlAction.h:33
ControlAction()
Definition: ControlAction.h:53
virtual void operator()(T eventValue)=0
Definition: Announcement.h:24
const std::string & GetName() const noexcept
Definition: ControlAction.h:60
int GetListOrder() const noexcept
Definition: ControlAction.h:61
virtual ~ControlAction()
Definition: ControlAction.h:56
An action performer that does absolutely nothing.
Definition: ControlAction.h:81