Spinning Topp Logo BlackTopp Studios
inc
eventsubscriberslot.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _eventsubscriberslot_h
41 #define _eventsubscriberslot_h
42 
43 #include "eventarguments.h"
44 
45 namespace Mezzanine
46 {
47  class Event;
48  class EventSubscriber;
49  namespace Scripting
50  {
51  class iScript;
52  }
53  ///////////////////////////////////////////////////////////////////////////////
54  /// @brief This class represents a slot in an event that can be subscribed to via subscribers, functors, or methods.
55  /// @details
56  ///////////////////////////////////////
58  {
59  public:
60  /// @brief This enum is used to describe the type of SubscriberSlot an instance is, to be used for casting.
61  enum SlotType
62  {
63  ST_Custom = 1,
64  ST_Functor = 2,
65  ST_CFunction = 3,
66  ST_Script = 4,
67  ST_MemberFunction = 5
68  };
69  protected:
70  /// @internal
71  /// @brief A pointer to the connected event.
73  public:
74  /// @brief Class constructor.
75  /// @param Ev The event this subscriber slot belongs to.
77  /// @brief Class destructor.
78  virtual ~EventSubscriberSlot();
79 
80  ///////////////////////////////////////////////////////////////////////////////
81  // Utility
82 
83  /// @brief Gets the set of events the subscriber is subscribed to.
84  /// @return Returns a reference to the set of events this is subscribed to.
85  Event* GetEvent() const;
86  /// @brief Gets the type of subscriber slot this is.
87  /// @return Returns a SlotType enum value representing the type of subscriber slot this is.
88  virtual SlotType GetType() const = 0;
89 
90  ///////////////////////////////////////////////////////////////////////////////
91  // Internal Methods
92 
93  /// @internal
94  /// @brief Notifies this subscriber of an event being fired.
95  /// @param Args The arguments containing specific information regarding this event.
96  virtual void _NotifyEvent(EventArgumentsPtr Args) = 0;
97  };//EventSubscriberSlot
98 
99  ///////////////////////////////////////////////////////////////////////////////
100  /// @brief This is a subscriber slot class that passes on the event firing to a custom subscriber class.
101  /// @details
102  ///////////////////////////////////////
104  {
105  protected:
106  /// @internal
107  /// @brief A pointer to the custom subscriber that the event will be passed on to.
109  public:
110  /// @brief Class constructor.
111  /// @param Ev The event this subscriber slot belongs to.
112  /// @param SubScript The subscriber script to be called when the event is fired.
114  /// @brief Class destructor.
115  virtual ~CustomSubscriberSlot();
116 
117  ///////////////////////////////////////////////////////////////////////////////
118  // Utility
119 
120  /// @brief Gets a pointer to the subscriber used by this subscriber slot.
121  /// @return Returns a pointer to the custom subscriber being used in this subscriber slot.
122  EventSubscriber* GetSubscriber() const;
123  /// @copydoc EventSubscriberSlot::GetType() const
124  virtual SlotType GetType() const;
125 
126  ///////////////////////////////////////////////////////////////////////////////
127  // Internal Methods
128 
129  /// @copydoc EventSubscriberSlot::_NotifyEvent(EventArgumentsPtr Args)
130  virtual void _NotifyEvent(EventArgumentsPtr Args);
131  };// CustomSubscriberSlot
132 
133  ///////////////////////////////////////////////////////////////////////////////
134  /// @brief Basic class definition for functors used by a FunctorSubscriberSlot.
135  /// @details
136  ///////////////////////////////////////
138  {
139  public:
140  /// @brief Clsas constructor.
142  /// @brief Class destructor.
144 
145  /// @brief Executes subscriber specific functionality when the event is fired.
146  /// @param Args The arguments that describe the fired event.
147  virtual void operator()(EventArgumentsPtr Args) = 0;
148  };//FunctorEventSubscriber
149 
150  ///////////////////////////////////////////////////////////////////////////////
151  /// @brief This is a subscriber slot class that makes the appropriate call on a functor.
152  /// @details
153  ///////////////////////////////////////
155  {
156  protected:
157  /// @internal
158  /// @brief A pointer to the functor to be called when the event is fired.
160  /// @internal
161  /// @brief Stores whether or not the functor is to be deleted when this subscriber is destructed.
163  public:
164  /// @brief Class constructor.
165  /// @param Ev The event this subscriber slot belongs to.
166  /// @param Funct The Functor object to be called when the event is fired.
167  /// @param CleanUpAfter Whether or not to delete the functor when this object is deleted.
168  FunctorSubscriberSlot(Event* Ev, FunctorEventSubscriber* Funct, Boole CleanUpAfter);
169  /// @brief Class destructor.
170  virtual ~FunctorSubscriberSlot();
171 
172  ///////////////////////////////////////////////////////////////////////////////
173  // Utility
174 
175  /// @brief Gets a pointer to the functor used by this subscriber slot.
176  /// @return Returns a pointer to the functor subscriber being used in this subscriber slot.
177  FunctorEventSubscriber* GetFunctor() const;
178  /// @copydoc EventSubscriberSlot::GetType() const
179  virtual SlotType GetType() const;
180 
181  ///////////////////////////////////////////////////////////////////////////////
182  // Internal Methods
183 
184  /// @copydoc EventSubscriberSlot::_NotifyEvent(EventArgumentsPtr Args)
185  virtual void _NotifyEvent(EventArgumentsPtr Args);
186  };//FunctorSubscriberSlot
187 
188 #ifndef SWIG // This is non-sensical in a scripting language
189  ///////////////////////////////////////////////////////////////////////////////
190  /// @brief This is a subscriber slot class that triggers a Free/C-style function.
191  /// @details
192  ///////////////////////////////////////
194  {
195  public:
196  /// @brief This is a convenience typedef for a c-style method that accepts EventArguments.
197  typedef void (SubscriberFunction)(EventArgumentsPtr Args);
198  protected:
199  /// @internal
200  /// @brief A pointer to the c-style function to be called when the event is fired.
201  SubscriberFunction* Function;
202  public:
203  /// @brief Class constructor.
204  /// @param Ev The event this subscriber slot belongs to.
205  /// @param Funct The C-style function to be called when the event is fired.
206  CFunctionSubscriberSlot(Event* Ev, SubscriberFunction* Funct);
207  /// @brief Class destructor.
208  virtual ~CFunctionSubscriberSlot();
209 
210  ///////////////////////////////////////////////////////////////////////////////
211  // Utility
212 
213  /// @brief Gets a pointer to the function used by this subscriber slot.
214  /// @return Returns a pointer to the function subscriber being used in this subscriber slot.
215  SubscriberFunction* GetFunction() const;
216  /// @copydoc EventSubscriberSlot::GetType() const
217  virtual SlotType GetType() const;
218 
219  ///////////////////////////////////////////////////////////////////////////////
220  // Internal Methods
221 
222  /// @copydoc EventSubscriberSlot::_NotifyEvent(EventArgumentsPtr Args)
223  virtual void _NotifyEvent(EventArgumentsPtr Args);
224  };// CFunctionSubscriberSlot
225 #endif // \SWIG
226 
227  ///////////////////////////////////////////////////////////////////////////////
228  /// @brief This is a subscriber slot class that triggers a provided script.
229  /// @details
230  ///////////////////////////////////////
232  {
233  protected:
234  /// @internal
235  /// @brief A pointer to the script to be executed when the event is fired.
237  public:
238  /// @brief Class constructor.
239  /// @param Ev The event this subscriber slot belongs to.
240  /// @param SubScript The subscriber script to be called when the event is fired.
242  /// @brief Class destructor.
243  virtual ~ScriptSubscriberSlot();
244 
245  ///////////////////////////////////////////////////////////////////////////////
246  // Utility
247 
248  /// @brief Gets a pointer to the function used by this subscriber slot.
249  /// @return Returns a pointer to the function subscriber being used in this subscriber slot.
250  Scripting::iScript* GetScript() const;
251  /// @copydoc EventSubscriberSlot::GetType() const
252  virtual SlotType GetType() const;
253 
254  ///////////////////////////////////////////////////////////////////////////////
255  // Internal Methods
256 
257  /// @copydoc EventSubscriberSlot::_NotifyEvent(EventArgumentsPtr Args)
258  virtual void _NotifyEvent(EventArgumentsPtr Args);
259  };//ScriptSubscriberSlot
260 }//Mezzanine
261 
262 #endif
Basic class definition for functors used by a FunctorSubscriberSlot.
FunctorEventSubscriber * Functor
A pointer to the functor to be called when the event is fired.
FunctorEventSubscriber()
Clsas constructor.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
SubscriberFunction * Function
A pointer to the c-style function to be called when the event is fired.
This class represents a given event that can be subscribed to and/or fired.
Definition: event.h:52
This is a subscriber slot class that triggers a Free/C-style function.
Boole CleanUp
Stores whether or not the functor is to be deleted when this subscriber is destructed.
This is a base class for all classes that subscribe to events.
A simple reference counting pointer.
Definition: countedptr.h:70
This is a subscriber slot class that passes on the event firing to a custom subscriber class...
Event * SubbedEvent
A pointer to the connected event.
The interface for a script.
Definition: script.h:70
This is a subscriber slot class that triggers a provided script.
EventSubscriber * Subscriber
A pointer to the custom subscriber that the event will be passed on to.
This class represents a slot in an event that can be subscribed to via subscribers, functors, or methods.
This is a subscriber slot class that makes the appropriate call on a functor.
Scripting::iScript * SubscriberScript
A pointer to the script to be executed when the event is fired.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
SlotType
This enum is used to describe the type of SubscriberSlot an instance is, to be used for casting...
virtual ~FunctorEventSubscriber()
Class destructor.
virtual void operator()(EventArgumentsPtr Args)=0
Executes subscriber specific functionality when the event is fired.