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>
8
10public:
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
40private:
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};
void load(QSettings &settings)
static AppSettings & getInstance()
Definition AppSettings.h:11
T & getGroup() const
Definition AppSettings.h:28
void save(QSettings &settings) const
T * registerGroup(Args &&... args)
Definition AppSettings.h:17