| 1 |
#ifndef USERSETTINGS_HH |
| 2 |
#define USERSETTINGS_HH |
| 3 |
|
| 4 |
#include "Command.hh" |
| 5 |
#include "Setting.hh" |
| 6 |
|
| 7 |
#include "outer.hh" |
| 8 |
|
| 9 |
#include <memory> |
| 10 |
#include <ranges> |
| 11 |
#include <string_view> |
| 12 |
#include <vector> |
| 13 |
|
| 14 |
namespace openmsx { |
| 15 |
|
| 16 |
class UserSettings |
| 17 |
{ |
| 18 |
public: |
| 19 |
struct Info { |
| 20 |
std::unique_ptr<Setting> setting; |
| 21 |
StringStorage description; |
| 22 |
}; |
| 23 |
using Settings = std::vector<Info>; |
| 24 |
|
| 25 |
explicit UserSettings(CommandController& commandController); |
| 26 |
|
| 27 |
void addSetting(Info&& info); |
| 28 |
void deleteSetting(Setting& setting); |
| 29 |
[[nodiscard]] Setting* findSetting(std::string_view name) const; |
| 30 |
|
| 31 |
private: |
| 32 |
class Cmd final : public Command { |
| 33 |
public: |
| 34 |
explicit Cmd(CommandController& commandController); |
| 35 |
void execute(std::span<const TclObject> tokens, |
| 36 |
TclObject& result) override; |
| 37 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 38 |
void tabCompletion(std::vector<std::string>& tokens) const override; |
| 39 |
|
| 40 |
private: |
| 41 |
void create (std::span<const TclObject> tokens, TclObject& result); |
| 42 |
void destroy(std::span<const TclObject> tokens, TclObject& result); |
| 43 |
void info (std::span<const TclObject> tokens, TclObject& result) const; |
| 44 |
|
| 45 |
[[nodiscard]] Info createString (std::span<const TclObject> tokens) const; |
| 46 |
[[nodiscard]] Info createBoolean(std::span<const TclObject> tokens) const; |
| 47 |
[[nodiscard]] Info createInteger(std::span<const TclObject> tokens) const; |
| 48 |
[[nodiscard]] Info createFloat (std::span<const TclObject> tokens) const; |
| 49 |
[[nodiscard]] Info createEnum (std::span<const TclObject> tokens) const; |
| 50 |
|
| 51 |
[[nodiscard]] auto getSettingNames() const { |
| 52 |
return std::views::transform( |
| 53 |
OUTER(UserSettings, userSettingCommand).settings, |
| 54 |
[](const auto& info) { return info.setting->getFullName(); }); |
| 55 |
} |
| 56 |
} userSettingCommand; |
| 57 |
|
| 58 |
Settings settings; |
| 59 |
}; |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
#endif |