| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #pragma once
- #include <string>
- #include <unordered_map>
- #include <variant>
- #include <vector>
- namespace lumacs {
- /// Configuration value type
- using ConfigValue = std::variant<bool, int, std::string>;
- /// Global configuration manager
- class Config {
- public:
- Config();
- /// Set a configuration value
- void set(const std::string& key, const ConfigValue& value);
- /// Get a configuration value
- template<typename T>
- T get(const std::string& key, const T& default_value = T{}) const {
- auto it = values_.find(key);
- if (it == values_.end()) {
- return default_value;
- }
- try {
- return std::get<T>(it->second);
- } catch (const std::bad_variant_access&) {
- return default_value;
- }
- }
- /// Check if a key exists
- bool has(const std::string& key) const;
- /// Get all keys
- std::vector<std::string> keys() const;
- private:
- std::unordered_map<std::string, ConfigValue> values_;
- void set_defaults();
- };
- } // namespace lumacs
|