36 #include <Pt/Function.h>
37 #include <Pt/Method.h>
38 #include <Pt/ConstMethod.h>
39 #include <Pt/Connectable.h>
44 class PT_API SignalBase :
public Connectable
49 Sentry(SignalBase* signal);
55 bool operator!()
const
56 {
return _signal == 0; }
65 SignalBase& operator=(
const SignalBase& other);
67 virtual void onConnectionOpen(
const Connection& c);
69 virtual void onConnectionClose(
const Connection& c);
72 void disconnectSlots();
74 void disconnectSlot(
const Slot&);
82 #include <Pt/Signal.tpp>
84 struct PT_API CompareEventTypeInfo
86 bool operator()(
const std::type_info* t1,
87 const std::type_info* t2 )
const;
91 class PT_API Signal<const Pt::Event&> :
public Connectable
92 ,
protected NonCopyable
96 Sentry(Signal* signal);
102 bool operator!()
const
103 {
return _signal == 0; }
115 virtual ~IEventRoute() {}
120 const InvokableT* invokable =
static_cast<const InvokableT*
>( _target.slot()->callable() );
134 template <
typename EventT>
135 class EventRoute :
public IEventRoute
139 : IEventRoute(target)
144 typedef Invokable<const Pt::Event&> InvokableT;
145 const InvokableT* invokable =
static_cast<const InvokableT*
>( connection().slot()->callable() );
147 const EventT&
event =
static_cast<const EventT&
>(ev);
148 invokable->invoke(event);
152 typedef std::multimap<
const std::type_info*,
154 CompareEventTypeInfo > RouteMap;
163 template <
typename EventT>
167 EventT* selectAddRouteOverload = 0;
168 this->addRoute(conn, selectAddRouteOverload);
174 template <
typename R,
typename EventT>
177 this->removeRoute(slot);
180 virtual void onConnectionOpen(
const Connection& c);
182 virtual void onConnectionClose(
const Connection& c);
185 void addRoute(Connection& conn,
const Pt::Event*)
187 this->addRoute( 0,
new IEventRoute(conn) );
190 template <
typename EventT>
191 void addRoute(Connection& conn,
const EventT*)
193 const std::type_info& ti =
typeid(EventT);
194 this->addRoute( &ti,
new EventRoute<EventT>(conn) );
197 void addRoute(
const std::type_info* ti, IEventRoute* route);
199 void removeRoute(
const Slot& slot);
201 void removeRoute(
const std::type_info* ti,
const Slot& slot);
211 template <
typename R,
class EventT>
212 Connection operator +=(Signal<const Pt::Event&>& signal,
const BasicSlot<R, EventT>& slot)
214 return signal.connect( slot );
217 template <
typename R>
218 Connection operator +=(Signal<const Pt::Event&>& signal,
const BasicSlot<R, const Pt::Event&>& slot)
220 return signal.connect( slot );
224 template <
typename R,
class EventT>
225 void operator -=(Signal<const Pt::Event&>& signal,
const BasicSlot<R, EventT>& slot)
227 signal.disconnect( slot );
230 template <
typename R>
231 void operator -=(Signal<const Pt::Event&>& signal,
const BasicSlot<R, const Pt::Event&>& slot)
233 signal.disconnect( slot );
Interface for invokable entities.
Definition: Invokable.h:36
bool isValid() const
Returns true if not closed.
Definition: Connection.h:106
virtual void invoke(ARGUMENTS) const =0
Invokes the invokable entity with the given arguments.
Base class for all event types.
Definition: Event.h:49
Represents a connection between a Signal/Delegate and a slot.
Definition: Connection.h:90
virtual Slot * clone() const =0
Clone this object with new.
Base type for various "slot" types.
Definition: Slot.h:47