Sayonara Player
Loading...
Searching...
No Matches
Settings.h
1/* Settings.h */
2
3/* Copyright (C) 2011-2024 Michael Lugmair (Lucio Carreras)
4 *
5 * This file is part of sayonara player
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20#pragma once
21#ifndef SAYONARA_PLAYER_SETTINGS_H
22#define SAYONARA_PLAYER_SETTINGS_H
23
24#include "Utils/Settings/SettingKey.h"
25#include "Utils/Settings/Setting.h"
26#include "Utils/Settings/SettingNotifier.h"
27#include "Utils/Singleton.h"
28
29#include <array>
30#include <cassert>
31
32#define GetSetting(x) Settings::instance()->get<x>()
33#define SetSetting(x, y) Settings::instance()->set<x>(y)
34#define ListenSetting(x, y) Set::listen<x>(this, &y)
35#define ListenSettingNoCall(x, y) Set::listen<x>(this, &y, false)
36
37using SettingArray = std::array<AbstrSetting*, static_cast<unsigned int>(SettingKey::Num_Setting_Keys)>;
38
40{
41 SINGLETON(Settings)
42 PIMPL(Settings)
43
44 public:
45 [[nodiscard]] AbstrSetting* setting(SettingKey keyIndex) const;
46
47 const SettingArray& settings();
48
49 void registerSetting(AbstrSetting* s);
50
51 bool checkSettings();
52
53 template<typename KeyClass>
54 const typename KeyClass::Data& get() const
55 {
56 using SettingPtr = Setting<KeyClass>*;
57 auto* s = static_cast<SettingPtr>(setting(KeyClass::key));
58 assert(s);
59 return s->value();
60 }
61
62 template<typename KeyClass>
63 void set(const typename KeyClass::Data& val)
64 {
65 using SettingPtr = Setting<KeyClass>*;
66 auto* s = static_cast<SettingPtr>(setting(KeyClass::key));
67 assert(s);
68 if(s->assignValue(val))
69 {
71 }
72 }
73
74 template<typename KeyClass>
75 void shout() const
76 {
77 auto* settingNotifier = SettingNotifier<KeyClass>::instance();
78 settingNotifier->valueChanged();
79 }
80
81 void applyFixes();
82};
83
84#endif // SAYONARA_PLAYER_SETTINGS_H
Definition: Setting.h:30
Definition: SettingNotifier.h:50
Definition: Setting.h:61
Definition: Settings.h:40