openMSX
UserSettings.hh
Go to the documentation of this file.
1#ifndef USERSETTINGS_HH
2#define USERSETTINGS_HH
3
4#include "Command.hh"
5
6#include "outer.hh"
7#include "view.hh"
8
9#include <memory>
10#include <string_view>
11#include <vector>
12
13namespace openmsx {
14
15class Setting;
16
18{
19public:
20 struct Info {
21 std::unique_ptr<Setting> setting;
22 StringStorage description; // because setting doesn't take ownership
23 };
24 using Settings = std::vector<Info>;
25
26 explicit UserSettings(CommandController& commandController);
27
28 void addSetting(Info&& info);
30 [[nodiscard]] Setting* findSetting(std::string_view name) const;
31
32private:
33 class Cmd final : public Command {
34 public:
35 explicit Cmd(CommandController& commandController);
36 void execute(std::span<const TclObject> tokens,
37 TclObject& result) override;
38 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
39 void tabCompletion(std::vector<std::string>& tokens) const override;
40
41 private:
42 void create (std::span<const TclObject> tokens, TclObject& result);
43 void destroy(std::span<const TclObject> tokens, TclObject& result);
44 void info (std::span<const TclObject> tokens, TclObject& result) const;
45
46 [[nodiscard]] Info createString (std::span<const TclObject> tokens) const;
47 [[nodiscard]] Info createBoolean(std::span<const TclObject> tokens) const;
48 [[nodiscard]] Info createInteger(std::span<const TclObject> tokens) const;
49 [[nodiscard]] Info createFloat (std::span<const TclObject> tokens) const;
50 [[nodiscard]] Info createEnum (std::span<const TclObject> tokens) const;
51
52 [[nodiscard]] auto getSettingNames() const {
53 return view::transform(
54 OUTER(UserSettings, userSettingCommand).settings,
55 [](const auto& info) { return info.setting->getFullName(); });
56 }
57 } userSettingCommand;
58
59 Settings settings; // unordered
60};
61
62} // namespace openmsx
63
64#endif
BaseSetting * setting
std::unique_ptr< char, FreeStringStorage > StringStorage
void deleteSetting(Setting &setting)
void addSetting(Info &&info)
Setting * findSetting(std::string_view name) const
std::vector< Info > Settings
This file implemented 3 utility functions:
Definition Autofire.cc:11
constexpr auto transform(Range &&range, UnaryOp op)
Definition view.hh:520
#define OUTER(type, member)
Definition outer.hh:42
std::unique_ptr< Setting > setting