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:
44 // Out-of-line: pimpl member holds an incomplete type here, so unique_ptr's
45 // deleter can't be instantiated until Impl is complete in the .cpp.
47
48 // Prevent copying but allow moving
49 ConfigManager(const ConfigManager&) = delete;
53
58 bool Load();
59
64 bool Save();
65
69 void Reset();
70
74 [[nodiscard]] bool ConfigFileExists() const;
75
79 [[nodiscard]] std::filesystem::path GetConfigPath() const;
80
81 // Window settings
82 void SetWindowPosition(int x, int y);
83 void SetWindowSize(int width, int height);
84 [[nodiscard]] std::optional<std::pair<int, int>> GetWindowPosition() const;
85 [[nodiscard]] std::optional<std::pair<int, int>> GetWindowSize() const;
86 void SetWindowMaximized(bool maximized);
87 [[nodiscard]] bool GetWindowMaximized() const;
88
89 // Theme settings
90 void SetTheme(const std::string& theme);
91 [[nodiscard]] std::string GetTheme() const;
92
93 // Recent files
94 void AddRecentFile(const std::string& filepath);
95 [[nodiscard]] std::vector<std::string> GetRecentFiles() const;
96 void ClearRecentFiles();
97 void SetMaxRecentFiles(size_t max);
98
99 // Generic settings (string key-value pairs)
100 void SetString(const std::string& key, const std::string& value);
101 [[nodiscard]] std::optional<std::string> GetString(const std::string& key) const;
102
103 void SetInt(const std::string& key, int value);
104 [[nodiscard]] std::optional<int> GetInt(const std::string& key) const;
105
106 void SetBool(const std::string& key, bool value);
107 [[nodiscard]] std::optional<bool> GetBool(const std::string& key) const;
108
109 void SetFloat(const std::string& key, float value);
110 [[nodiscard]] std::optional<float> GetFloat(const std::string& key) const;
111
112 // Check if key exists
113 [[nodiscard]] bool HasKey(const std::string& key) const;
114
115 // Remove key
116 void RemoveKey(const std::string& key);
117
118 // Get all keys
119 [[nodiscard]] std::vector<std::string> GetAllKeys() const;
120
121private:
122 struct Impl;
123 std::unique_ptr<Impl> m_impl;
124
125 // Helper to get config directory
126 static std::filesystem::path GetConfigDirectory();
127
128 // Helper to ensure config directory exists
129 static bool EnsureConfigDirectoryExists();
130};
131
132} // 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.