LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
LC::Util::SlotClosure< FireDestrPolicy > Class Template Reference

Executes a given functor upon a signal (or a list of signals). More...

#include "slotclosure.h"

+ Inheritance diagram for LC::Util::SlotClosure< FireDestrPolicy >:
+ Collaboration diagram for LC::Util::SlotClosure< FireDestrPolicy >:

Public Types

using FunType_t = std::function< typename FireDestrPolicy::Signature_t >
 

Public Member Functions

 SlotClosure (const FunType_t &func, QObject *parent)
 Constructs a SlotClosure running a given func with the given parent as a QObject. More...
 
 SlotClosure (const FunType_t &func, QObject *sender, const char *signal, QObject *parent)
 Constructs a SlotClosure running a given func with the given parent as a QObject on the given signal. More...
 
 SlotClosure (const FunType_t &func, QObject *sender, const std::initializer_list< const char * > &signalsList, QObject *parent)
 Constructs a SlotClosure running a given func with the given parent as a QObject on the given signalsList. More...
 
void run () override
 Triggers the function and invokes the destroy policy. More...
 
- Public Member Functions inherited from LC::Util::SlotClosureBase
virtual ~SlotClosureBase ()=default
 

Additional Inherited Members

- Public Slots inherited from LC::Util::SlotClosureBase

Detailed Description

template<typename FireDestrPolicy>
class LC::Util::SlotClosure< FireDestrPolicy >

Executes a given functor upon a signal (or a list of signals).

Refer to the documentation of SlotClosureBase to check constructors and their parameters.

Typical usage:

const auto reply = networkAccessManager->get (request); // say we want to handle a reply
new Util::SlotClosure<Util::DeleteLaterPolicy>
{
[reply]
{
if (reply->error () == QNetworkReply::NoError)
HandleData (reply->readAll ());
reply->deleteLater ();
},
reply,
SIGNAL (finished ()),
reply
};

Lifetime management.

The instance of this class can either be deleted after the matching signal is emitted, or when the object's parent object is deleted, or when this object is deleted explicitly by the user. The exact behavior is controlled by the FireDestrPolicy template policy.

There are two predefined policies: DeleteLaterPolicy and NoDeletePolicy.

DeleteLaterPolicy deletes the instance of this class after the signal is fired for the first time.

NoDeletePolicy does not delete the object at all. In this case the object will be deleted either explicitly by the user or when its parent QObject is deleted.

Template Parameters
FireDestrPolicyControls how the object should be destroyed in response to the watched signal.

Definition at line 91 of file slotclosure.h.

Member Typedef Documentation

◆ FunType_t

template<typename FireDestrPolicy >
using LC::Util::SlotClosure< FireDestrPolicy >::FunType_t = std::function<typename FireDestrPolicy::Signature_t>

Definition at line 95 of file slotclosure.h.

Constructor & Destructor Documentation

◆ SlotClosure() [1/3]

template<typename FireDestrPolicy >
LC::Util::SlotClosure< FireDestrPolicy >::SlotClosure ( const FunType_t func,
QObject *  parent 
)
inline

Constructs a SlotClosure running a given func with the given parent as a QObject.

This constructor does not automatically connect to any signals. Thus, all interesting signals should be manually connected to the construct object's run() slot:

const auto closure = new SlotClosure<DeleteLaterPolicy> { someFunc, parent };
connect (object,
SIGNAL (triggered ()),
closure,
SLOT (run ()));
Parameters
[in]funcThe function to run when a connected signal is fired.
[in]parentThe parent object of this SlotClosure.

Definition at line 117 of file slotclosure.h.

◆ SlotClosure() [2/3]

template<typename FireDestrPolicy >
LC::Util::SlotClosure< FireDestrPolicy >::SlotClosure ( const FunType_t func,
QObject *  sender,
const char *  signal,
QObject *  parent 
)
inline

Constructs a SlotClosure running a given func with the given parent as a QObject on the given signal.

Parameters
[in]funcThe function to run when a matching signal is fired.
[in]senderThe sender of the signal to connect to.
[in]signalThe signal that should trigger the func.
[in]parentThe parent object of this SlotClosure.

Definition at line 132 of file slotclosure.h.

◆ SlotClosure() [3/3]

template<typename FireDestrPolicy >
LC::Util::SlotClosure< FireDestrPolicy >::SlotClosure ( const FunType_t func,
QObject *  sender,
const std::initializer_list< const char * > &  signalsList,
QObject *  parent 
)
inline

Constructs a SlotClosure running a given func with the given parent as a QObject on the given signalsList.

Parameters
[in]funcThe function to run when a matching signal is fired.
[in]senderThe sender of the signal to connect to.
[in]signalsListThe list of signals, any of which triggers the func.
[in]parentThe parent object of this SlotClosure.

Definition at line 155 of file slotclosure.h.

Member Function Documentation

◆ run()

template<typename FireDestrPolicy >
void LC::Util::SlotClosure< FireDestrPolicy >::run ( )
inlineoverridevirtual

Triggers the function and invokes the destroy policy.

Implements LC::Util::SlotClosureBase.

Definition at line 171 of file slotclosure.h.

References LC::Util::oral::sph::f.


The documentation for this class was generated from the following file:
LC::Util::SlotClosure::run
void run() override
Triggers the function and invokes the destroy policy.
Definition: slotclosure.h:171