Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/common/layered_settings_interface.cpp
4212 views
1
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#include "layered_settings_interface.h"
5
#include "common/assert.h"
6
#include <unordered_set>
7
8
LayeredSettingsInterface::LayeredSettingsInterface() = default;
9
10
LayeredSettingsInterface::~LayeredSettingsInterface() = default;
11
12
bool LayeredSettingsInterface::IsEmpty()
13
{
14
return false;
15
}
16
17
bool LayeredSettingsInterface::GetIntValue(const char* section, const char* key, s32* value) const
18
{
19
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
20
{
21
if (SettingsInterface* sif = m_layers[layer]; sif != nullptr)
22
{
23
if (sif->GetIntValue(section, key, value))
24
return true;
25
}
26
}
27
28
return false;
29
}
30
31
bool LayeredSettingsInterface::GetUIntValue(const char* section, const char* key, u32* value) const
32
{
33
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
34
{
35
if (SettingsInterface* sif = m_layers[layer]; sif != nullptr)
36
{
37
if (sif->GetUIntValue(section, key, value))
38
return true;
39
}
40
}
41
42
return false;
43
}
44
45
bool LayeredSettingsInterface::GetFloatValue(const char* section, const char* key, float* value) const
46
{
47
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
48
{
49
if (SettingsInterface* sif = m_layers[layer]; sif != nullptr)
50
{
51
if (sif->GetFloatValue(section, key, value))
52
return true;
53
}
54
}
55
56
return false;
57
}
58
59
bool LayeredSettingsInterface::GetDoubleValue(const char* section, const char* key, double* value) const
60
{
61
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
62
{
63
if (SettingsInterface* sif = m_layers[layer]; sif != nullptr)
64
{
65
if (sif->GetDoubleValue(section, key, value))
66
return true;
67
}
68
}
69
70
return false;
71
}
72
73
bool LayeredSettingsInterface::GetBoolValue(const char* section, const char* key, bool* value) const
74
{
75
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
76
{
77
if (SettingsInterface* sif = m_layers[layer]; sif != nullptr)
78
{
79
if (sif->GetBoolValue(section, key, value))
80
return true;
81
}
82
}
83
84
return false;
85
}
86
87
bool LayeredSettingsInterface::GetStringValue(const char* section, const char* key, std::string* value) const
88
{
89
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
90
{
91
if (SettingsInterface* sif = m_layers[layer]; sif != nullptr)
92
{
93
if (sif->GetStringValue(section, key, value))
94
return true;
95
}
96
}
97
98
return false;
99
}
100
101
bool LayeredSettingsInterface::GetStringValue(const char* section, const char* key, SmallStringBase* value) const
102
{
103
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
104
{
105
if (SettingsInterface* sif = m_layers[layer]; sif != nullptr)
106
{
107
if (sif->GetStringValue(section, key, value))
108
return true;
109
}
110
}
111
112
return false;
113
}
114
115
void LayeredSettingsInterface::SetIntValue(const char* section, const char* key, int value)
116
{
117
Panic("Attempt to call SetIntValue() on layered settings interface");
118
}
119
120
void LayeredSettingsInterface::SetUIntValue(const char* section, const char* key, u32 value)
121
{
122
Panic("Attempt to call SetUIntValue() on layered settings interface");
123
}
124
125
void LayeredSettingsInterface::SetFloatValue(const char* section, const char* key, float value)
126
{
127
Panic("Attempt to call SetFloatValue() on layered settings interface");
128
}
129
130
void LayeredSettingsInterface::SetDoubleValue(const char* section, const char* key, double value)
131
{
132
Panic("Attempt to call SetDoubleValue() on layered settings interface");
133
}
134
135
void LayeredSettingsInterface::SetBoolValue(const char* section, const char* key, bool value)
136
{
137
Panic("Attempt to call SetBoolValue() on layered settings interface");
138
}
139
140
void LayeredSettingsInterface::SetStringValue(const char* section, const char* key, const char* value)
141
{
142
Panic("Attempt to call SetStringValue() on layered settings interface");
143
}
144
145
bool LayeredSettingsInterface::ContainsValue(const char* section, const char* key) const
146
{
147
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
148
{
149
if (SettingsInterface* sif = m_layers[layer]; sif != nullptr)
150
{
151
if (sif->ContainsValue(section, key))
152
return true;
153
}
154
}
155
return false;
156
}
157
158
void LayeredSettingsInterface::DeleteValue(const char* section, const char* key)
159
{
160
Panic("Attempt to call DeleteValue() on layered settings interface");
161
}
162
163
void LayeredSettingsInterface::ClearSection(const char* section)
164
{
165
Panic("Attempt to call ClearSection() on layered settings interface");
166
}
167
168
void LayeredSettingsInterface::RemoveSection(const char* section)
169
{
170
Panic("Attempt to call RemoveSection() on layered settings interface");
171
}
172
173
void LayeredSettingsInterface::RemoveEmptySections()
174
{
175
Panic("Attempt to call RemoveEmptySections() on layered settings interface");
176
}
177
178
std::vector<std::string> LayeredSettingsInterface::GetStringList(const char* section, const char* key) const
179
{
180
std::vector<std::string> ret;
181
182
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
183
{
184
if (SettingsInterface* sif = m_layers[layer]; sif != nullptr)
185
{
186
ret = sif->GetStringList(section, key);
187
if (!ret.empty())
188
break;
189
}
190
}
191
192
return ret;
193
}
194
195
void LayeredSettingsInterface::SetStringList(const char* section, const char* key,
196
const std::vector<std::string>& items)
197
{
198
Panic("Attempt to call SetStringList() on layered settings interface");
199
}
200
201
bool LayeredSettingsInterface::RemoveFromStringList(const char* section, const char* key, const char* item)
202
{
203
Panic("Attempt to call RemoveFromStringList() on layered settings interface");
204
}
205
206
bool LayeredSettingsInterface::AddToStringList(const char* section, const char* key, const char* item)
207
{
208
Panic("Attempt to call AddToStringList() on layered settings interface");
209
}
210
211
std::vector<std::pair<std::string, std::string>> LayeredSettingsInterface::GetKeyValueList(const char* section) const
212
{
213
std::unordered_set<std::string_view> seen;
214
std::vector<std::pair<std::string, std::string>> ret;
215
for (u32 layer = FIRST_LAYER; layer <= LAST_LAYER; layer++)
216
{
217
if (SettingsInterface* sif = m_layers[layer])
218
{
219
const size_t newly_added_begin = ret.size();
220
std::vector<std::pair<std::string, std::string>> entries = sif->GetKeyValueList(section);
221
for (std::pair<std::string, std::string>& entry : entries)
222
{
223
if (seen.find(entry.first) != seen.end())
224
continue;
225
ret.push_back(std::move(entry));
226
}
227
228
// Mark keys as seen after processing all entries in case the layer has multiple entries for a specific key
229
for (auto cur = ret.begin() + newly_added_begin, end = ret.end(); cur < end; cur++)
230
seen.insert(cur->first);
231
}
232
}
233
234
return ret;
235
}
236
237
void LayeredSettingsInterface::SetKeyValueList(const char* section,
238
const std::vector<std::pair<std::string, std::string>>& items)
239
{
240
Panic("Attempt to call SetKeyValueList() on layered settings interface");
241
}
242
243