OXYGENHUB
◆ main openmsx / src / settings / SettingsManager.hh
2.6 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef SETTINGSMANAGER_HH
2
#define SETTINGSMANAGER_HH
3
4
#include "Command.hh"
5
#include "InfoTopic.hh"
6
#include "Setting.hh"
7
#include "TclObject.hh"
8
9
#include "hash_set.hh"
10
11
#include <string_view>
12
13
namespace openmsx {
14
15
class SettingsConfig;
16
class GlobalCommandController;
17
18
/** Manages all settings.
19
  */
20
class SettingsManager
21
{
22
public:
23
	explicit SettingsManager(GlobalCommandController& commandController);
24
	SettingsManager(const SettingsManager&) = delete;
25
	SettingsManager(SettingsManager&&) = delete;
26
	SettingsManager& operator=(const SettingsManager&) = delete;
27
	SettingsManager& operator=(SettingsManager&&) = delete;
28
	~SettingsManager();
29
30
	/** Find the setting with given name.
31
	  * @return The requested setting or nullptr.
32
	  */
33
	[[nodiscard]] BaseSetting* findSetting(std::string_view name) const;
34
	[[nodiscard]] BaseSetting* findSetting(std::string_view prefix, std::string_view baseName) const;
35
36
	void loadSettings(const SettingsConfig& config) const;
37
38
	void registerSetting  (BaseSetting& setting);
39
	void unregisterSetting(BaseSetting& setting);
40
41
	[[nodiscard]] const auto& getAllSettings() const { return settings; }
42
43
private:
44
	[[nodiscard]] BaseSetting& getByName(std::string_view cmd, std::string_view name) const;
45
	[[nodiscard]] std::vector<std::string> getTabSettingNames() const;
46
47
private:
48
	struct SettingInfo final : InfoTopic {
49
		explicit SettingInfo(InfoCommand& openMSXInfoCommand);
50
		void execute(std::span<const TclObject> tokens,
51
			     TclObject& result) const override;
52
		[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
53
		void tabCompletion(std::vector<std::string>& tokens) const override;
54
	} settingInfo;
55
56
	struct SetCompleter final : CommandCompleter {
57
		explicit SetCompleter(CommandController& commandController);
58
		[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
59
		void tabCompletion(std::vector<std::string>& tokens) const override;
60
	} setCompleter;
61
62
	class SettingCompleter final : public CommandCompleter {
63
	public:
64
		SettingCompleter(CommandController& commandController,
65
				 SettingsManager& manager,
66
				 const std::string& name);
67
		[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
68
		void tabCompletion(std::vector<std::string>& tokens) const override;
69
	private:
70
		SettingsManager& manager;
71
	};
72
	SettingCompleter incrCompleter;
73
	SettingCompleter unsetCompleter;
74
75
	struct NameFromSetting {
76
		[[nodiscard]] const TclObject& operator()(const BaseSetting* s) const {
77
			return s->getFullNameObj();
78
		}
79
	};
80
	hash_set<BaseSetting*, NameFromSetting, XXTclHasher> settings;
81
};
82
83
} // namespace openmsx
84
85
#endif