Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
signal-blocker.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * RAII blocker for sigc++ signals.
4 *
5 * Authors:
6 * Jon A. Cruz <jon@joncruz.org>
7 *
8 * Copyright (C) 2014 Authors
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#ifndef SEEN_INKSCAPE_UTIL_SIGNAL_BLOCKER_H
14#define SEEN_INKSCAPE_UTIL_SIGNAL_BLOCKER_H
15
19template <typename T>
21{
22public:
27 [[nodiscard]] explicit SignalBlocker(T &connection)
28 : _connection{connection}
29 , _was_blocked{_connection.blocked()}
30 {
31 if (!_was_blocked) {
32 _connection.block();
33 }
34 }
35
41 {
42 if (!_was_blocked) {
43 _connection.unblock();
44 }
45 }
46
47 SignalBlocker(SignalBlocker const &) = delete;
49
50private:
52 bool const _was_blocked;
53};
54
55#endif // SEEN_INKSCAPE_UTIL_SIGNAL_BLOCKER_H
56
57/*
58 Local Variables:
59 mode:c++
60 c-file-style:"stroustrup"
61 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
62 indent-tabs-mode:nil
63 fill-column:99
64 End:
65*/
66// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
RAII blocker for sigc++ signals.
SignalBlocker(T &connection)
Creates a new instance that if the signal is currently unblocked will block it until this instance is...
SignalBlocker(SignalBlocker const &)=delete
SignalBlocker & operator=(SignalBlocker const &)=delete
bool const _was_blocked
~SignalBlocker()
Destructor that will unblock the signal if it was blocked initially by this instance.