Physics Simulation & Visualization Tool
0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
AppSettings.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <QSettings>
4
#include <vector>
5
#include <memory>
6
#include <stdexcept>
7
#include "
settings/ISettingsGroup.h
"
8
9
class
AppSettings
{
10
public
:
11
static
AppSettings
&
getInstance
() {
12
static
AppSettings
instance;
13
return
instance;
14
}
15
16
template
<
typename
T,
typename
... Args>
17
T*
registerGroup
(Args&&... args) {
18
auto
group = std::make_unique<T>(std::forward<Args>(args)...);
19
T* ptr = group.get();
20
groups.push_back(std::move(group));
21
return
ptr;
22
}
23
24
// Not worth right now
25
// to use a map, the overhead will be more
26
// computation than just iterating through the vector and dynamic casting
27
template
<
typename
T>
28
T&
getGroup
()
const
{
29
for
(
const
auto
& group : groups) {
30
if
(
auto
* casted =
dynamic_cast<
T*
>
(group.get())) {
31
return
*casted;
32
}
33
}
34
throw
std::runtime_error(
"Settings group not found!"
);
35
}
36
37
void
load
(QSettings& settings);
38
void
save
(QSettings& settings)
const
;
39
40
private
:
41
AppSettings
() =
default
;
42
~AppSettings
() =
default
;
43
AppSettings
(
const
AppSettings
&) =
delete
;
44
AppSettings
& operator=(
const
AppSettings
&) =
delete
;
45
46
std::vector<std::unique_ptr<ISettingsGroup>> groups;
47
};
ISettingsGroup.h
AppSettings
Definition
AppSettings.h:9
AppSettings::load
void load(QSettings &settings)
Definition
AppSettings.cpp:3
AppSettings::getInstance
static AppSettings & getInstance()
Definition
AppSettings.h:11
AppSettings::getGroup
T & getGroup() const
Definition
AppSettings.h:28
AppSettings::save
void save(QSettings &settings) const
Definition
AppSettings.cpp:9
AppSettings::registerGroup
T * registerGroup(Args &&... args)
Definition
AppSettings.h:17
src
ui
AppSettings.h
Generated by
1.9.8