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 
8 namespace openmsx {
9 
11  : BaseSetting(name)
12  , reactor(reactor_)
13 {
14 }
15 
16 BaseSetting* 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 
25 const 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 
37 std::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 
46 std::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 
64 std::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 (const auto* setting = getSetting()) {
85  return setting->getRestoreValue();
86  } else {
87  return TclObject("proxy");
88  }
89 }
90 
92 {
93  if (auto* setting = getSetting()) {
94  // note: not setStringDirect()
95  setting->setValue(value);
96  } else {
97  throw MSXException("No setting '", getFullName(), "' on current machine.");
98  }
99 }
100 
101 void ProxySetting::tabCompletion(std::vector<std::string>& tokens) const
102 {
103  if (const auto* setting = getSetting()) {
104  setting->tabCompletion(tokens);
105  }
106 }
107 
109 {
110  if (const auto* setting = getSetting()) {
111  return setting->needLoadSave();
112  } else {
113  return false;
114  }
115 }
116 
118 {
119  if (const auto* setting = getSetting()) {
120  return setting->needTransfer();
121  } else {
122  return false;
123  }
124 }
125 
126 void ProxySetting::setDontSaveValue(const TclObject& dontSaveValue)
127 {
128  if (auto* setting = getSetting()) {
129  setting->setDontSaveValue(dontSaveValue);
130  }
131 }
132 
134 {
135  if (const auto* setting = getSetting()) {
136  setting->additionalInfo(result);
137  }
138 }
139 
140 } // namespace openmsx
BaseSetting * setting
Definition: Interpreter.cc:27
std::string_view getFullName() const
Definition: Setting.hh:37
bool needLoadSave() const override
Does this setting need to be loaded or saved (settings.xml).
void additionalInfo(TclObject &result) const override
Helper method for info().
void setDontSaveValue(const TclObject &dontSaveValue) override
This value will never end up in the settings.xml file.
TclObject getRestoreValue() const override
Get the value that will be set after a Tcl 'unset' command.
Definition: ProxySetting.cc:82
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.
void setValueDirect(const TclObject &value) override
Similar to setValue(), but doesn't trigger Tcl traces.
Definition: ProxySetting.cc:91
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:68
MSXMotherBoard * getMotherBoard() const
Definition: Reactor.cc:374
GlobalCommandController & getGlobalCommandController()
Definition: Reactor.hh:84
BaseSetting * findSetting(std::string_view name) const
Find the setting with given name.
This file implemented 3 utility functions:
Definition: Autofire.cc:9