Repo-Init
 
Loading...
Searching...
No Matches
ConfigParser.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <string>
5#include <unordered_map>
6
12 private:
13 std::filesystem::path _configPath;
14 std::unordered_map<std::string, std::string> _configMap;
15 bool _isValid = false;
16 std::string _lastError;
17
18 // JSON helpers
19 bool readJson();
20 void writeJson() const;
21
22 public:
27 explicit ConfigParser(std::filesystem::path configPath);
28
33 bool isValid() const { return _isValid; }
34
39 const std::string &getLastError() const { return _lastError; }
40
48 std::string get(const std::string &key) const;
49
54 const std::unordered_map<std::string, std::string> &getConfigMap() const { return _configMap; }
55
62 void set(const std::string &key, const std::string_view &value);
63
69 void remove(const std::string &key);
70
74 void save() const;
75
80 bool load();
81};
std::unordered_map< std::string, std::string > _configMap
void set(const std::string &key, const std::string_view &value)
std::string get(const std::string &key) const
void writeJson() const
void remove(const std::string &key)
const std::string & getLastError() const
void save() const
ConfigParser(std::filesystem::path configPath)
bool isValid() const
std::filesystem::path _configPath
const std::unordered_map< std::string, std::string > & getConfigMap() const
std::string _lastError