35#include <Pt/Function.h>
37#include <Pt/ConstMethod.h>
38#include <Pt/Connectable.h>
49 DelegateBase(
const DelegateBase& rhs)
50 { DelegateBase::operator=(rhs); }
52 DelegateBase& operator=(
const DelegateBase& other)
56 if( other._target.isValid() )
58 const Slot*
slot = other._target.slot();
69 return _target.isValid();
72 virtual void onConnectionOpen(
const Connection& c)
82 Connectable::onConnectionOpen(c);
85 virtual void onConnectionClose(
const Connection& c)
87 Connectable::onConnectionClose(c);
96 void disconnectSlot(
const Slot&
slot)
98 if( _target.isValid() && _target.slot()->equals(
slot) )
192template <
typename R,
typename... As>
196 typedef Callable<R, As...> CallableT;
207 DelegateBase::operator=(rhs);
221 DelegateBase::disconnectSlot();
228 DelegateBase::disconnectSlot(
slot);
238 if( ! _target.isValid() )
239 throw std::logic_error(
"Delegate::call(): Delegate not connected");
242 static_cast<const CallableT*
>( _target.callable() );
253 if( ! _target.isValid() )
257 static_cast<const CallableT*
>( _target.callable() );
265 return this->
call(args...);
278template <
typename R,
typename... As>
285 : _method(delegate, &
Delegate<R, As...>::call)
303 _method.object().onConnectionOpen(connection);
309 _method.object().onConnectionClose(connection);
316 return other && _method == other->_method;
327template <
typename R,
typename... As>
337template <
typename R,
typename... As>
Base type for various "slot" types.
Definition Slot.h:92
An interface for all callable entities.
Definition Callable.h:48
ConstMethod< R, ClassT, As... > callable(ClassT &object, R(BaseT::*method)(As...) const)
Returns a ConstMethod object for the given object/method pair.
Definition ConstMethod.h:161
Connection Management for Signal and Slot Objects.
Definition Connectable.h:50
Represents a connection between a Signal/Delegate and a slot.
Definition Connection.h:96
Connection()
Default Constructor.
const Connectable * sender() const
Returns the sender.
Definition Connection.h:115
R call(As... args) const
Calls the callable entity and returns its result.
Definition ConstMethod.h:77
Wraps Delegate objects so that they can act as Slots.
Definition Delegate.h:280
DelegateSlot(Delegate< R, As... > &delegate)
Constructs from delegate.
Definition Delegate.h:284
virtual bool equals(const Slot &slot) const
Returns true if two slots are equal in value.
Definition Delegate.h:313
virtual const Callback * callable() const
Returns the callable converted to the type-erased Callback interface.
Definition Delegate.h:295
virtual void onDisconnect(const Connection &connection)
Notifies of disconnects.
Definition Delegate.h:307
virtual void onConnect(const Connection &connection)
Notifies of connects.
Definition Delegate.h:301
Slot * clone() const
Clone this object with new.
Definition Delegate.h:289
Delegates an action to a slot.
Definition Delegate.h:194
Delegate()
Default Constructor.
Definition Delegate.h:200
Connection connect(const BasicSlot< R, As... > &slot)
Connects this object to the given slot and returns that Connection.
Definition Delegate.h:212
void disconnect(const BasicSlot< R, As... > &slot)
Disconnects from the target.
Definition Delegate.h:226
bool isConnected() const
Returns true if connected to a target.
Definition Delegate.h:67
void disconnect()
Disconnects from current target.
Definition Delegate.h:219
Connection operator+=(Delegate< R, As... > &delegate, const BasicSlot< R, As... > &slot)
Connect a Delegate to a slot.
Definition Delegate.h:338
R call(As... args)
Calls the slot connected to the Delegate.
Definition Delegate.h:236
void invoke(As... args)
Invoke the slot connected to the Delegate.
Definition Delegate.h:251
Delegate(const Delegate &rhs)
Deeply copies the other Delegate.
Definition Delegate.h:205
R operator()(As... args)
Same as call().
Definition Delegate.h:263
Adapter for class methods.
Definition Method.h:48
Endpoint of a signal/slot connection.
Definition Slot.h:55
ConstMethodSlot< R, ClassT, As... > slot(ClassT &object, R(BaseT::*method)(As...) const)
Returns a slot object for the given object/member pair.
Definition ConstMethod.h:172
DelegateSlot< R, As... > slot(Delegate< R, As... > &delegate)
Returns a slot object for the given delegate.
Definition Delegate.h:328
Core module.
Definition Allocator.h:33