From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- src/helper/auto-connection.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/helper/auto-connection.h (limited to 'src/helper/auto-connection.h') 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 + +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 -- cgit v1.2.3