summaryrefslogtreecommitdiffstats
path: root/src/helper/auto-connection.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/helper/auto-connection.h42
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