LeechCraft  0.6.70-10870-g558588d6ec
Modular cross-platform feature rich live environment.
LeechCraft::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 LeechCraft::Util::SlotClosure< FireDestrPolicy >:
+ Collaboration diagram for LeechCraft::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 LeechCraft::Util::SlotClosureBase
virtual ~SlotClosureBase ()=default
 

Additional Inherited Members

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

Detailed Description

template<typename FireDestrPolicy>
class LeechCraft::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 100 of file slotclosure.h.

Member Typedef Documentation

◆ FunType_t

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

Definition at line 104 of file slotclosure.h.

Constructor & Destructor Documentation

◆ SlotClosure() [1/3]

template<typename FireDestrPolicy >
LeechCraft::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 126 of file slotclosure.h.

◆ SlotClosure() [2/3]

template<typename FireDestrPolicy >
LeechCraft::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 141 of file slotclosure.h.

◆ SlotClosure() [3/3]

template<typename FireDestrPolicy >
LeechCraft::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 164 of file slotclosure.h.

Member Function Documentation

◆ run()

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

Triggers the function and invokes the destroy policy.

Implements LeechCraft::Util::SlotClosureBase.

Definition at line 180 of file slotclosure.h.


The documentation for this class was generated from the following file: