aboutsummaryrefslogtreecommitdiff
path: root/src/setting.hpp
blob: 6293dd39de025eeb8396c364a5844d6bea9d52fe (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
#ifndef WANDA_setting_HPP
#define WANDA_setting_HPP

#include <gio/gio.h>

#include <cstddef>
#include <optional>
#include <string>
#include <type_traits>

#include "type_wrapper.hpp"
#include "variant.hpp"
#include <iostream>

namespace wanda {

struct setting;
using schema = type_wrapper<std::string, struct SchemaTag>;
using key = type_wrapper<std::string, struct KeyTag>;

namespace literals {
key operator""_key(char const * str, std::size_t len);
std::optional<setting> operator""_setting(char const * str, std::size_t len);
}

struct setting {
    ~setting();

    setting(setting const & other);

    template<typename TargetType> std::optional<TargetType> get(key key) const {
        auto value = variant{g_settings_get_value(m_value, key.get().c_str())};
        return value.get<TargetType>();
    }

private:
    explicit setting(schema schema);

    GSettings * m_value;

    friend std::optional<setting> literals::operator""_setting(char const *, std::size_t);
};


}


#endif