diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /src/helper/auto-connection.h | |
parent | Initial commit. (diff) | |
download | inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/helper/auto-connection.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/helper/auto-connection.h b/src/helper/auto-connection.h new file mode 100644 index 0000000..368db34 --- /dev/null +++ b/src/helper/auto-connection.h @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef SEEN_AUTO_CONNECTION_H +#define SEEN_AUTO_CONNECTION_H + +#include <sigc++/connection.h> + +namespace Inkscape { + +// class to simplify re-subsribing to connections; automates disconnecting + +class auto_connection { +public: + auto_connection(const sigc::connection& c): _connection(c) {} + + auto_connection() = default; + + ~auto_connection() { + _connection.disconnect(); + } + + auto_connection(const auto_connection&) = delete; + auto_connection& operator = (const auto_connection&) = delete; + + // re-assign + auto_connection& operator = (const sigc::connection& c) { + _connection.disconnect(); + _connection = c; + return *this; + } + + void disconnect() { + *this = sigc::connection(); + } + +private: + sigc::connection _connection; +}; + +} // namespace + +#endif |