LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
slotclosure.h
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#pragma once
10
11
#include <functional>
12
#include <QObject>
13
#include "
sllconfig.h
"
14
15
namespace
LC
16
{
17
namespace
Util
18
{
21
class
UTIL_SLL_API
SlotClosureBase
:
public
QObject
22
{
23
Q_OBJECT
24
public
:
25
using
QObject::QObject;
26
27
virtual
~SlotClosureBase
() =
default
;
28
public
Q_SLOTS:
31
virtual
void
run
() = 0;
32
};
33
78
template
<
typename
FireDestrPolicy>
79
class
SlotClosure
:
public
SlotClosureBase
80
,
public
FireDestrPolicy
81
{
82
public
:
83
using
FunType_t
= std::function<typename FireDestrPolicy::Signature_t>;
84
private
:
85
FunType_t
Func_;
86
public
:
105
SlotClosure
(
const
FunType_t
& func, QObject *parent)
106
:
SlotClosureBase
{ parent }
107
, Func_ { func }
108
{
109
}
110
120
SlotClosure
(
const
FunType_t
& func,
121
QObject *sender,
122
const
char
*signal,
123
QObject *parent)
124
:
SlotClosureBase
{ parent }
125
, Func_ { func }
126
{
127
connect (sender,
128
signal,
129
this
,
130
SLOT (
run
()));
131
}
132
143
SlotClosure
(
const
FunType_t
& func,
144
QObject *sender,
145
const
std::initializer_list<const char*>& signalsList,
146
QObject *parent)
147
:
SlotClosureBase
{ parent }
148
, Func_ { func }
149
{
150
for
(
const
auto
signal : signalsList)
151
connect (sender,
152
signal,
153
this
,
154
SLOT (
run
()));
155
}
156
159
void
run
()
override
160
{
161
FireDestrPolicy::Invoke (Func_,
this
);
162
FireDestrPolicy::Fired (
this
);
163
}
164
};
165
166
class
BasicDeletePolicy
167
{
168
protected
:
169
using
Signature_t
= void ();
170
171
void
Invoke
(
const
std::function<Signature_t>& f,
SlotClosureBase
*)
172
{
173
f ();
174
}
175
176
virtual
~BasicDeletePolicy
() =
default
;
177
};
178
181
class
DeleteLaterPolicy
:
public
BasicDeletePolicy
182
{
183
protected
:
184
static
void
Fired
(
SlotClosureBase
*base)
185
{
186
base->deleteLater ();
187
}
188
};
189
192
class
NoDeletePolicy
:
public
BasicDeletePolicy
193
{
194
protected
:
195
static
void
Fired
(
SlotClosureBase
*)
196
{
197
}
198
};
199
206
class
ChoiceDeletePolicy
207
{
208
public
:
211
enum class
Delete
212
{
215
No
,
216
219
Yes
220
};
221
protected
:
222
virtual
~ChoiceDeletePolicy
() {}
223
224
using
Signature_t
=
Delete
();
225
226
static
void
Invoke
(
const
std::function<Signature_t>& f,
SlotClosureBase
*base)
227
{
228
if
(f () ==
Delete::Yes
)
229
base->deleteLater ();
230
}
231
232
static
void
Fired
(
SlotClosureBase
*)
233
{
234
}
235
};
236
}
237
}
LC::Util::BasicDeletePolicy
Definition
slotclosure.h:167
LC::Util::BasicDeletePolicy::Signature_t
void() Signature_t
Definition
slotclosure.h:169
LC::Util::BasicDeletePolicy::~BasicDeletePolicy
virtual ~BasicDeletePolicy()=default
LC::Util::BasicDeletePolicy::Invoke
void Invoke(const std::function< Signature_t > &f, SlotClosureBase *)
Definition
slotclosure.h:171
LC::Util::ChoiceDeletePolicy
Delegates the SlotClosure deletion decision to the signal handler.
Definition
slotclosure.h:207
LC::Util::ChoiceDeletePolicy::Delete
Delete
Whether the SlotClosure shall be deleted.
Definition
slotclosure.h:212
LC::Util::ChoiceDeletePolicy::Delete::Yes
@ Yes
Delete SlotClosure after this invocation.
Definition
slotclosure.h:219
LC::Util::ChoiceDeletePolicy::Delete::No
@ No
Do not delete SlotClosure after this invocation.
Definition
slotclosure.h:215
LC::Util::ChoiceDeletePolicy::~ChoiceDeletePolicy
virtual ~ChoiceDeletePolicy()
Definition
slotclosure.h:222
LC::Util::ChoiceDeletePolicy::Invoke
static void Invoke(const std::function< Signature_t > &f, SlotClosureBase *base)
Definition
slotclosure.h:226
LC::Util::ChoiceDeletePolicy::Signature_t
Delete() Signature_t
Definition
slotclosure.h:224
LC::Util::ChoiceDeletePolicy::Fired
static void Fired(SlotClosureBase *)
Definition
slotclosure.h:232
LC::Util::DeleteLaterPolicy
Deletes a SlotClosure object after its signal has fired.
Definition
slotclosure.h:182
LC::Util::DeleteLaterPolicy::Fired
static void Fired(SlotClosureBase *base)
Definition
slotclosure.h:184
LC::Util::NoDeletePolicy
Does not delete a SlotClosure object.
Definition
slotclosure.h:193
LC::Util::NoDeletePolicy::Fired
static void Fired(SlotClosureBase *)
Definition
slotclosure.h:195
LC::Util::SlotClosureBase
Base class for SlotClosure.
Definition
slotclosure.h:22
LC::Util::SlotClosureBase::run
virtual void run()=0
Triggers the function.
LC::Util::SlotClosureBase::~SlotClosureBase
virtual ~SlotClosureBase()=default
LC::Util::SlotClosure::FunType_t
std::function< typename FireDestrPolicy::Signature_t > FunType_t
Definition
slotclosure.h:83
LC::Util::SlotClosure::run
void run() override
Triggers the function and invokes the destroy policy.
Definition
slotclosure.h:159
LC::Util::SlotClosure::SlotClosure
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 signals...
Definition
slotclosure.h:143
LC::Util::SlotClosure::SlotClosure
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.
Definition
slotclosure.h:120
LC::Util::SlotClosure::SlotClosure
SlotClosure(const FunType_t &func, QObject *parent)
Constructs a SlotClosure running a given func with the given parent as a QObject.
Definition
slotclosure.h:105
LC::Util
Definition
icoreproxy.h:34
LC
Definition
constants.h:15
sllconfig.h
UTIL_SLL_API
#define UTIL_SLL_API
Definition
sllconfig.h:16
src
util
sll
slotclosure.h
Generated by
1.17.0