summaryrefslogtreecommitdiffstats
path: root/src/helper/auto-connection.h
blob: 368db34c3b51d4e5a6cadf3cfc209754e6c73046 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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