Chira Engine
A customizable MIT-licensed game engine.
JSONSettingsLoader.h
1 #pragma once
2 
3 #include <nlohmann/json.hpp>
4 
5 #include "ISettingsLoader.h"
6 
7 namespace chira {
8 
10 public:
11  explicit JSONSettingsLoader(std::string_view filename);
12  JSONSettingsLoader(std::string_view filename, std::string_view path, bool relative = false);
13 
14  void getValue(const std::string& name, int* value) const override;
15  void getValue(const std::string& name, double* value) const override;
16  void getValue(const std::string& name, std::string* value) const override;
17  void getValue(const std::string& name, bool* value) const override;
18 
19  void setValue(const std::string& name, int value, bool overwrite, bool save) override;
20  void setValue(const std::string& name, double value, bool overwrite, bool save) override;
21  void setValue(const std::string& name, const std::string& value, bool overwrite, bool save) override;
22  void setValue(const std::string& name, bool value, bool overwrite, bool save) override;
23 
24  [[nodiscard]] bool hasValue(const std::string& name) const override;
25 
26  void load() final;
27  void save() final;
28 private:
29  nlohmann::json settings{};
30 };
31 
32 } // namespace chira