Branch data Line data Source code
1 : : /*
2 : : * Copyright 2025 Jinwoo Sung
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * http://www.apache.org/licenses/LICENSE-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : #pragma once
18 : :
19 : : #include <memory>
20 : : #include <string>
21 : : #include <vector>
22 : :
23 : : #include "iconfig_manager.hpp"
24 : : #include "wirestead/base/visibility.hpp"
25 : :
26 : : namespace wirestead {
27 : : namespace config {
28 : :
29 : : /**
30 : : * Thread-safe configuration manager implementation
31 : : */
32 : : class WIRESTEAD_API ConfigManager : public ConfigManagerInterface {
33 : : public:
34 : : ConfigManager();
35 : : ~ConfigManager() override;
36 : :
37 : : // Move semantics
38 : : ConfigManager(ConfigManager&&) noexcept;
39 : : ConfigManager& operator=(ConfigManager&&) noexcept;
40 : :
41 : : // Non-copyable
42 : : ConfigManager(const ConfigManager&) = delete;
43 : : ConfigManager& operator=(const ConfigManager&) = delete;
44 : :
45 : : // Configuration access
46 : : std::any get(const std::string& key) const override;
47 : : std::any get(const std::string& key, const std::any& default_value) const override;
48 : : bool has(const std::string& key) const override;
49 : :
50 : : // Configuration modification
51 : : ValidationResult set(const std::string& key, const std::any& value) override;
52 : : bool remove(const std::string& key) override;
53 : : void clear() override;
54 : :
55 : : // Configuration validation
56 : : ValidationResult validate() const override;
57 : : ValidationResult validate(const std::string& key) const override;
58 : :
59 : : // Configuration registration
60 : : void register_item(const ConfigItem& item) override;
61 : : void register_validator(const std::string& key, std::function<ValidationResult(const std::any&)> validator) override;
62 : :
63 : : // Change notifications
64 : : void on_change(const std::string& key, ConfigChangeCallback callback) override;
65 : : void remove_change_callback(const std::string& key) override;
66 : :
67 : : // Configuration persistence
68 : : bool save_to_file(const std::string& filepath) const override;
69 : : bool load_from_file(const std::string& filepath) override;
70 : :
71 : : // Configuration introspection
72 : : std::vector<std::string> get_keys() const override;
73 : : ConfigType get_type(const std::string& key) const override;
74 : : std::string get_description(const std::string& key) const override;
75 : : bool is_required(const std::string& key) const override;
76 : :
77 : : private:
78 : : struct Impl;
79 : 3871 : const Impl* get_impl() const { return impl_.get(); }
80 : : Impl* get_impl() { return impl_.get(); }
81 : : std::unique_ptr<Impl> impl_;
82 : : };
83 : :
84 : : } // namespace config
85 : : } // namespace wirestead
|