aboutsummaryrefslogtreecommitdiff
path: root/src/setting.cpp
blob: 9ddbfe86f8e3e609ce7b2ddc417f8834b2d548eb (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
#include "setting.hpp"

namespace wanda {

namespace literals {
    key operator""_key(char const * str, std::size_t len) {
        return key{{str, len}};
    }

    std::optional<setting> operator""_setting(char const * str, std::size_t len) {
        auto source = g_settings_schema_source_get_default();
        auto schema = g_settings_schema_source_lookup(source, str, true);
        if(schema) {
            g_settings_schema_unref(schema);
            return setting{::wanda::schema{{str, len}}};
        }
        return std::nullopt;
    }
}

setting::setting(schema schema) : m_value{g_settings_new(schema.get().c_str())} { }

setting::setting(setting const & other) : m_value{reinterpret_cast<GSettings *>(g_object_ref(other.m_value))} { }

setting::~setting() {
    g_clear_object(&m_value);
}

}