summaryrefslogtreecommitdiffhomepage
path: root/options/connector.hpp
blob: e22cb20f6af5c81d9c5309463abe4e0cc7f8cc9d (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
43
44
45
46
47
48
49
/* Copyright (c) 2016, Stanislaw Halik <sthalik@misaki.pl>

 * Permission to use, copy, modify, and/or distribute this
 * software for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice and this permission
 * notice appear in all copies.
 */

#pragma once

#include <unordered_map>
#include <vector>

#include <QString>
#include <QMutex>

#include "compat/qhash.hpp"

#include "export.hpp"

namespace options {
    class value_;
}

namespace options::detail {

class OTR_OPTIONS_EXPORT connector
{
    friend class ::options::value_;

    using value_type = value_*;
    using value_vec = std::vector<value_type>;
    std::unordered_map<QString, value_vec> connected_values;

    void on_value_destructed(value_type val);
    void on_value_created(value_type val);

protected:
    void notify_values(const QString& name) const;
    void notify_all_values() const;
    virtual QMutex* get_mtx() const = 0;
    void set_all_to_default_();

public:
    connector();
    virtual ~connector();
};

} // ns options::detail