Crazy Eddie's GUI System  0.8.7
SubscriberSlot.h
1 /************************************************************************
2  created: Tue Feb 28 2006
3  author: Paul D Turner <paul@cegui.org.uk>
4 *************************************************************************/
5 /***************************************************************************
6  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  ***************************************************************************/
27 #ifndef _CEGUISubscriberSlot_h_
28 #define _CEGUISubscriberSlot_h_
29 
30 #include "CEGUI/Base.h"
31 #include "CEGUI/FreeFunctionSlot.h"
32 #include "CEGUI/FunctorCopySlot.h"
33 #include "CEGUI/FunctorReferenceSlot.h"
34 #include "CEGUI/FunctorPointerSlot.h"
35 #include "CEGUI/MemberFunctionSlot.h"
36 #include "CEGUI/FunctorReferenceBinder.h"
37 
38 // Start of CEGUI namespace section
39 namespace CEGUI
40 {
41 
51 class CEGUIEXPORT SubscriberSlot :
52  public AllocatedObject<SubscriberSlot>
53 {
54 public:
60 
66 
75  d_functor_impl(CEGUI_NEW_AO FreeFunctionSlotVoid(func))
76  {}
77 
86  d_functor_impl(CEGUI_NEW_AO FreeFunctionSlotNoArgs(func))
87  {}
88 
97  d_functor_impl(CEGUI_NEW_AO FreeFunctionSlotVoidNoArgs(func))
98  {}
99 
106 
113  bool operator()(const EventArgs& args) const
114  {
115  return (*d_functor_impl)(args);
116  }
117 
122  bool connected() const
123  {
124  return d_functor_impl != 0;
125  }
126 
132  void cleanup();
133 
134  // templatised constructors
139  template<typename T>
140  SubscriberSlot(bool (T::*function)(const EventArgs&), T* obj) :
141  d_functor_impl(new MemberFunctionSlot<T>(function, obj))
142  {}
143 
148  template<typename T>
149  SubscriberSlot(void (T::*function)(const EventArgs&), T* obj) :
150  d_functor_impl(new MemberFunctionSlotVoid<T>(function, obj))
151  {}
152 
157  template<typename T>
158  SubscriberSlot(bool (T::*function)(), T* obj) :
159  d_functor_impl(new MemberFunctionSlotNoArgs<T>(function, obj))
160  {}
161 
166  template<typename T>
167  SubscriberSlot(void (T::*function)(), T* obj) :
168  d_functor_impl(new MemberFunctionSlotVoidNoArgs<T>(function, obj))
169  {}
170 
175  template<typename T>
177  d_functor_impl(new FunctorReferenceSlot<T>(binder.d_functor))
178  {}
179 
184  template<typename T>
185  SubscriberSlot(const T& functor) :
186  d_functor_impl(new FunctorCopySlot<T>(functor))
187  {}
188 
193  template<typename T>
194  SubscriberSlot(T* functor) :
195  d_functor_impl(new FunctorPointerSlot<T>(functor))
196  {}
197 
198 private:
200  SlotFunctorBase* d_functor_impl;
201 };
202 
203 } // End of CEGUI namespace section
204 
205 #endif // end of guard _CEGUISubscriberSlot_h_
CEGUI::SubscriberSlot
SubscriberSlot class which is used when subscribing to events.
Definition: SubscriberSlot.h:53
CEGUI::SubscriberSlot::~SubscriberSlot
~SubscriberSlot()
Destructor. Note this is non-virtual, which should be telling you not to sub-class!
CEGUI::SubscriberSlot::connected
bool connected() const
Returns whether the SubscriberSlot is internally connected (bound).
Definition: SubscriberSlot.h:122
CEGUI::SubscriberSlot::cleanup
void cleanup()
Disconnects the slot internally and performs any required cleanup operations.
CEGUI::FunctorPointerSlot
Slot template class that creates a functor that calls back via a functor object pointer.
Definition: FunctorPointerSlot.h:42
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(FreeFunctionSlotNoArgs::SlotFunction *func)
Creates a SubscriberSlot that is bound to a free function.
Definition: SubscriberSlot.h:85
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(void(T::*function)(), T *obj)
Creates a SubscriberSlot that is bound to a member function.
Definition: SubscriberSlot.h:167
CEGUI::FunctorReferenceSlot
Slot template class that creates a functor that calls back via a functor object reference.
Definition: FunctorReferenceSlot.h:42
CEGUI::FreeFunctionSlotVoidNoArgs
Slot functor class that calls back via a free function pointer. This variant ignores passed EventArgs...
Definition: FreeFunctionSlot.h:124
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot()
Default constructor. Creates a SubscriberSlot with no bound slot.
CEGUI::FreeFunctionSlotVoid
Slot functor class that calls back via a free function pointer. This variant doesn't require a handle...
Definition: FreeFunctionSlot.h:69
CEGUI::MemberFunctionSlotVoidNoArgs
Slot template class that creates a functor that calls back via a class member function....
Definition: MemberFunctionSlot.h:134
CEGUI
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
CEGUI::AllocatedObject
Definition: MemoryAllocatedObject.h:110
CEGUI::MemberFunctionSlotVoid
Slot template class that creates a functor that calls back via a class member function....
Definition: MemberFunctionSlot.h:73
CEGUI::FunctorReferenceBinder
Class that enables the creation of a reference binding for a functor object to be used as a callback ...
Definition: FunctorReferenceBinder.h:42
CEGUI::FreeFunctionSlotVoidNoArgs::SlotFunction
void() SlotFunction()
Slot function type.
Definition: FreeFunctionSlot.h:127
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(FreeFunctionSlot::SlotFunction *func)
Creates a SubscriberSlot that is bound to a free function.
CEGUI::FunctorCopySlot
Slot template class that creates a functor that calls back via a copy of a functor object.
Definition: FunctorCopySlot.h:260
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(FreeFunctionSlotVoidNoArgs::SlotFunction *func)
Creates a SubscriberSlot that is bound to a free function.
Definition: SubscriberSlot.h:96
CEGUI::MemberFunctionSlot
Slot template class that creates a functor that calls back via a class member function.
Definition: MemberFunctionSlot.h:42
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(void(T::*function)(const EventArgs &), T *obj)
Creates a SubscriberSlot that is bound to a member function.
Definition: SubscriberSlot.h:149
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(const T &functor)
Creates a SubscriberSlot that is bound to a copy of a functor object.
Definition: SubscriberSlot.h:185
CEGUI::FreeFunctionSlotNoArgs::SlotFunction
bool() SlotFunction()
Slot function type.
Definition: FreeFunctionSlot.h:98
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(T *functor)
Creates a SubscriberSlot that is bound to a functor pointer.
Definition: SubscriberSlot.h:194
CEGUI::MemberFunctionSlotNoArgs
Slot template class that creates a functor that calls back via a class member function....
Definition: MemberFunctionSlot.h:102
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(bool(T::*function)(), T *obj)
Creates a SubscriberSlot that is bound to a member function.
Definition: SubscriberSlot.h:158
CEGUI::SubscriberSlot::operator()
bool operator()(const EventArgs &args) const
Invokes the slot functor that is bound to this Subscriber. Returns whatever the slot returns,...
Definition: SubscriberSlot.h:113
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(FreeFunctionSlotVoid::SlotFunction *func)
Creates a SubscriberSlot that is bound to a free function.
Definition: SubscriberSlot.h:74
CEGUI::FreeFunctionSlotVoid::SlotFunction
void() SlotFunction(const EventArgs &)
Slot function type.
Definition: FreeFunctionSlot.h:72
CEGUI::FreeFunctionSlotNoArgs
Slot functor class that calls back via a free function pointer. This variant ignores passed EventArgs...
Definition: FreeFunctionSlot.h:95
CEGUI::SlotFunctorBase
Defines abstract interface which will be used when constructing various functor objects that bind slo...
Definition: SlotFunctorBase.h:44
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(const FunctorReferenceBinder< T > &binder)
Creates a SubscriberSlot that is bound to a functor object reference.
Definition: SubscriberSlot.h:176
CEGUI::FreeFunctionSlot::SlotFunction
bool() SlotFunction(const EventArgs &)
Slot function type.
Definition: FreeFunctionSlot.h:44
CEGUI::EventArgs
Base class used as the argument to all subscribers Event object.
Definition: EventArgs.h:51
CEGUI::SubscriberSlot::SubscriberSlot
SubscriberSlot(bool(T::*function)(const EventArgs &), T *obj)
Creates a SubscriberSlot that is bound to a member function.
Definition: SubscriberSlot.h:140