35 #include <Pt/Function.h>
36 #include <Pt/Method.h>
37 #include <Pt/ConstMethod.h>
38 #include <Pt/Connectable.h>
43 class DelegateBase :
public Connectable
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();
59 _target = Connection( *
this, slot->clone() );
67 bool isConnected()
const
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) )
192 template <
typename R,
typename... As>
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() );
243 return callable->
call(args...);
253 if( ! _target.isValid() )
257 static_cast<const CallableT*
>( _target.callable() );
258 callable->
call(args...);
265 return this->
call(args...);
278 template <
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;
327 template <
typename R,
typename... As>
337 template <
typename R,
typename... As>
Core module.
Definition: Allocator.h:33
void invoke(As... args)
Invoke the slot connected to the Delegate.
Definition: Delegate.h:251
Adapter for class methods.
Definition: Method.h:48
Connectable()
Default constructor.
An interface for all callable entities.
Definition: Callable.h:48
Delegate(const Delegate &rhs)
Deeply copies the other Delegate.
Definition: Delegate.h:205
virtual bool equals(const Slot &slot) const
Returns true if two slots are equal in value.
Definition: Delegate.h:313
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
virtual const Callback * callable() const
Returns the callable converted to the type-erased Callback interface.
Definition: Delegate.h:295
Delegate()
Default Constructor.
Definition: Delegate.h:200
void disconnect()
Disconnects from current target.
Definition: Delegate.h:219
Slot * clone() const
Clone this object with new.
Definition: Delegate.h:289
void disconnect(const BasicSlot< R, As... > &slot)
Disconnects from the target.
Definition: Delegate.h:226
virtual Slot * clone() const =0
Clone this object with new.
Connection connect(const BasicSlot< R, As... > &slot)
Connects this object to the given slot and returns that Connection.
Definition: Delegate.h:212
virtual void onDisconnect(const Connection &connection)
Notifies of disconnects.
Definition: Delegate.h:307
Connectable & operator=(const Connectable &rhs)
Assignment operator.
R operator()(As... args)
Same as call()
Definition: Delegate.h:263
Wraps Delegate objects so that they can act as Slots.
Definition: Delegate.h:280
virtual void onConnect(const Connection &connection)
Notifies of connects.
Definition: Delegate.h:301
Endpoint of a signal/slot connection.
Definition: Slot.h:55
DelegateSlot(Delegate< R, As... > &delegate)
Constructs from delegate.
Definition: Delegate.h:284
DelegateSlot< R, As... > slot(Delegate< R, As... > &delegate)
Returns a slot object for the given delegate.
Definition: Delegate.h:328
R call(As... args)
Calls the slot connected to the Delegate.
Definition: Delegate.h:236
Delegates an action to a slot.
Definition: Delegate.h:194
Represents a connection between a Signal/Delegate and a slot.
Definition: Connection.h:96
Connection operator+=(Delegate< R, As... > &delegate, const BasicSlot< R, As... > &slot)
Connect a Delegate to a slot.
Definition: Delegate.h:338
virtual R call(As... args) const =0
Calls the callable entity and returns its result.