MetaImGUI 1.0.0
ImGui Application Template for C++20
Loading...
Searching...
No Matches
ConfigManager.h
Go to the documentation of this file.
1/*
2 MetaImGUI
3 Copyright (C) 2026 A P Nicholson
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#include <filesystem>
22#include <map>
23#include <memory>
24#include <optional>
25#include <string>
26#include <vector>
27
28namespace MetaImGUI {
29
42public:
45
46 // Prevent copying but allow moving
47 ConfigManager(const ConfigManager&) = delete;
51
56 bool Load();
57
62 bool Save();
63
67 void Reset();
68
72 [[nodiscard]] bool ConfigFileExists() const;
73
77 [[nodiscard]] std::filesystem::path GetConfigPath() const;
78
79 // Window settings
80 void SetWindowPosition(int x, int y);
81 void SetWindowSize(int width, int height);
82 [[nodiscard]] std::optional<std::pair<int, int>> GetWindowPosition() const;
83 [[nodiscard]] std::optional<std::pair<int, int>> GetWindowSize() const;
84 void SetWindowMaximized(bool maximized);
85 [[nodiscard]] bool GetWindowMaximized() const;
86
87 // Theme settings
88 void SetTheme(const std::string& theme);
89 [[nodiscard]] std::string GetTheme() const;
90
91 // Recent files
92 void AddRecentFile(const std::string& filepath);
93 [[nodiscard]] std::vector<std::string> GetRecentFiles() const;
94 void ClearRecentFiles();
95 void SetMaxRecentFiles(size_t max);
96
97 // Generic settings (string key-value pairs)
98 void SetString(const std::string& key, const std::string& value);
99 [[nodiscard]] std::optional<std::string> GetString(const std::string& key) const;
100
101 void SetInt(const std::string& key, int value);
102 [[nodiscard]] std::optional<int> GetInt(const std::string& key) const;
103
104 void SetBool(const std::string& key, bool value);
105 [[nodiscard]] std::optional<bool> GetBool(const std::string& key) const;
106
107 void SetFloat(const std::string& key, float value);
108 [[nodiscard]] std::optional<float> GetFloat(const std::string& key) const;
109
110 // Check if key exists
111 [[nodiscard]] bool HasKey(const std::string& key) const;
112
113 // Remove key
114 void RemoveKey(const std::string& key);
115
116 // Get all keys
117 [[nodiscard]] std::vector<std::string> GetAllKeys() const;
118
119private:
120 struct Impl;
121 std::unique_ptr<Impl> m_impl;
122
123 // Helper to get config directory
124 static std::filesystem::path GetConfigDirectory();
125
126 // Helper to ensure config directory exists
127 static bool EnsureConfigDirectoryExists();
128};
129
130} // namespace MetaImGUI
Configuration manager for persistent application settings.
void Reset()
Reset configuration to defaults.
bool Save()
Save configuration to disk.
void SetWindowMaximized(bool maximized)
ConfigManager(const ConfigManager &)=delete
void SetBool(const std::string &key, bool value)
void AddRecentFile(const std::string &filepath)
std::optional< bool > GetBool(const std::string &key) const
std::optional< int > GetInt(const std::string &key) const
std::optional< float > GetFloat(const std::string &key) const
void SetString(const std::string &key, const std::string &value)
void SetFloat(const std::string &key, float value)
ConfigManager & operator=(ConfigManager &&)=default
std::optional< std::pair< int, int > > GetWindowSize() const
std::vector< std::string > GetAllKeys() const
std::optional< std::string > GetString(const std::string &key) const
ConfigManager & operator=(const ConfigManager &)=delete
void RemoveKey(const std::string &key)
std::string GetTheme() const
bool ConfigFileExists() const
Check if configuration file exists.
void SetMaxRecentFiles(size_t max)
bool HasKey(const std::string &key) const
bool Load()
Load configuration from disk.
void SetTheme(const std::string &theme)
ConfigManager(ConfigManager &&)=default
void SetWindowPosition(int x, int y)
void SetWindowSize(int width, int height)
std::vector< std::string > GetRecentFiles() const
void SetInt(const std::string &key, int value)
std::optional< std::pair< int, int > > GetWindowPosition() const
std::filesystem::path GetConfigPath() const
Get configuration file path.