openMSX
ProxySetting.cc
Go to the documentation of this file.
1#include "ProxySetting.hh"
4#include "Reactor.hh"
5#include "MSXMotherBoard.hh"
6#include "MSXException.hh"
7
8namespace openmsx {
9
11 : BaseSetting(name)
12 , reactor(reactor_)
13{
14}
15
16BaseSetting* ProxySetting::getSetting()
17{
18 auto* motherBoard = reactor.getMotherBoard();
19 if (!motherBoard) return nullptr;
20 auto& manager = reactor.getGlobalCommandController().getSettingsManager();
21 auto& controller = motherBoard->getMSXCommandController();
22 return manager.findSetting(controller.getPrefix(), getFullName());
23}
24
25const BaseSetting* ProxySetting::getSetting() const
26{
27 return const_cast<ProxySetting*>(this)->getSetting();
28}
29
31{
32 if (auto* setting = getSetting()) {
33 setting->setValue(value);
34 }
35}
36
37std::string_view ProxySetting::getTypeString() const
38{
39 if (const auto* setting = getSetting()) {
40 return setting->getTypeString();
41 } else {
42 throw MSXException("No setting '", getFullName(), "' on current machine.");
43 }
44}
45
46std::string_view ProxySetting::getDescription() const
47{
48 if (const auto* setting = getSetting()) {
49 return setting->getDescription();
50 } else {
51 return "proxy";
52 }
53}
54
56{
57 if (const auto* setting = getSetting()) {
58 return setting->getValue();
59 } else {
60 throw MSXException("No setting '", getFullName(), "' on current machine.");
61 }
62}
63
64std::optional<TclObject> ProxySetting::getOptionalValue() const
65{
66 if (const auto* setting = getSetting()) {
67 return setting->getOptionalValue();
68 } else {
69 return {};
70 }
71}
72
74{
75 if (const auto* setting = getSetting()) {
76 return setting->getDefaultValue();
77 } else {
78 return TclObject("proxy");
79 }
80}
81
83{
84 if (auto* setting = getSetting()) {
85 // note: not setStringDirect()
86 setting->setValue(value);
87 } else {
88 throw MSXException("No setting '", getFullName(), "' on current machine.");
89 }
90}
91
92void ProxySetting::tabCompletion(std::vector<std::string>& tokens) const
93{
94 if (const auto* setting = getSetting()) {
95 setting->tabCompletion(tokens);
96 }
97}
98
100{
101 if (const auto* setting = getSetting()) {
102 return setting->needLoadSave();
103 } else {
104 return false;
105 }
106}
107
109{
110 if (const auto* setting = getSetting()) {
111 return setting->needTransfer();
112 } else {
113 return false;
114 }
115}
116
118{
119 if (const auto* setting = getSetting()) {
120 setting->additionalInfo(result);
121 }
122}
123
124} // namespace openmsx
BaseSetting * setting
Definition: Interpreter.cc:28
std::string_view getFullName() const
Definition: Setting.hh:37
bool needLoadSave() const override
Does this setting need to be loaded or saved (settings.xml).
Definition: ProxySetting.cc:99
void additionalInfo(TclObject &result) const override
Helper method for info().
std::optional< TclObject > getOptionalValue() const override
Like getValue(), but in case of error returns an empty optional instead of throwing an exception.
Definition: ProxySetting.cc:64
TclObject getDefaultValue() const override
Get the default value of this setting.
Definition: ProxySetting.cc:73
void tabCompletion(std::vector< std::string > &tokens) const override
Complete a partly typed value.
Definition: ProxySetting.cc:92
void setValueDirect(const TclObject &value) override
Similar to setValue(), but doesn't trigger Tcl traces.
Definition: ProxySetting.cc:82
ProxySetting(Reactor &reactor, const TclObject &name)
Definition: ProxySetting.cc:10
const TclObject & getValue() const override
Get current value as a TclObject.
Definition: ProxySetting.cc:55
void setValue(const TclObject &value) override
Change the value of this setting to the given value.
Definition: ProxySetting.cc:30
std::string_view getTypeString() const override
Returns a string describing the setting type (integer, string, ..) Could be used in a GUI to pick an ...
Definition: ProxySetting.cc:37
std::string_view getDescription() const override
pure virtual methods ///
Definition: ProxySetting.cc:46
bool needTransfer() const override
Does this setting need to be transfered on reverse.
Contains the main loop of openMSX.
Definition: Reactor.hh:72
MSXMotherBoard * getMotherBoard() const
Definition: Reactor.cc:404
GlobalCommandController & getGlobalCommandController()
Definition: Reactor.hh:88
BaseSetting * findSetting(std::string_view name) const
Find the setting with given name.
This file implemented 3 utility functions:
Definition: Autofire.cc:9