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 using std::string;
9 using std::vector;
10 
11 namespace openmsx {
12 
14  : BaseSetting(name)
15  , reactor(reactor_)
16 {
17 }
18 
19 BaseSetting* ProxySetting::getSetting()
20 {
21  auto* motherBoard = reactor.getMotherBoard();
22  if (!motherBoard) return nullptr;
23  auto& manager = reactor.getGlobalCommandController().getSettingsManager();
24  auto& controller = motherBoard->getMSXCommandController();
25  return manager.findSetting(controller.getPrefix(), getFullName());
26 }
27 
28 const BaseSetting* ProxySetting::getSetting() const
29 {
30  return const_cast<ProxySetting*>(this)->getSetting();
31 }
32 
34 {
35  if (auto* setting = getSetting()) {
36  setting->setValue(value);
37  }
38 }
39 
40 std::string_view ProxySetting::getTypeString() const
41 {
42  if (const auto* setting = getSetting()) {
43  return setting->getTypeString();
44  } else {
45  return "proxy";
46  }
47 }
48 
49 std::string_view ProxySetting::getDescription() const
50 {
51  if (const auto* setting = getSetting()) {
52  return setting->getDescription();
53  } else {
54  return "proxy";
55  }
56 }
57 
59 {
60  if (const auto* setting = getSetting()) {
61  return setting->getValue();
62  } else {
63  throw MSXException("No setting '", getFullName(), "' on current machine.");
64  }
65 }
66 
67 std::optional<TclObject> ProxySetting::getOptionalValue() const
68 {
69  if (const auto* setting = getSetting()) {
70  return setting->getOptionalValue();
71  } else {
72  return {};
73  }
74 }
75 
77 {
78  if (const auto* setting = getSetting()) {
79  return setting->getDefaultValue();
80  } else {
81  return TclObject("proxy");
82  }
83 }
84 
86 {
87  if (const auto* setting = getSetting()) {
88  return setting->getRestoreValue();
89  } else {
90  return TclObject("proxy");
91  }
92 }
93 
95 {
96  if (auto* setting = getSetting()) {
97  // note: not setStringDirect()
98  setting->setValue(value);
99  } else {
100  throw MSXException("No setting '", getFullName(), "' on current machine.");
101  }
102 }
103 
104 void ProxySetting::tabCompletion(vector<string>& tokens) const
105 {
106  if (const auto* setting = getSetting()) {
107  setting->tabCompletion(tokens);
108  }
109 }
110 
112 {
113  if (const auto* setting = getSetting()) {
114  return setting->needLoadSave();
115  } else {
116  return false;
117  }
118 }
119 
121 {
122  if (const auto* setting = getSetting()) {
123  return setting->needTransfer();
124  } else {
125  return false;
126  }
127 }
128 
129 void ProxySetting::setDontSaveValue(const TclObject& dontSaveValue)
130 {
131  if (auto* setting = getSetting()) {
132  setting->setDontSaveValue(dontSaveValue);
133  }
134 }
135 
137 {
138  if (const auto* setting = getSetting()) {
139  setting->additionalInfo(result);
140  }
141 }
142 
143 } // namespace openmsx
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:85
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:67
TclObject getDefaultValue() const override
Get the default value of this setting.
Definition: ProxySetting.cc:76
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:94
ProxySetting(Reactor &reactor, const TclObject &name)
Definition: ProxySetting.cc:13
const TclObject & getValue() const override
Get current value as a TclObject.
Definition: ProxySetting.cc:58
void setValue(const TclObject &value) override
Change the value of this setting to the given value.
Definition: ProxySetting.cc:33
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:40
std::string_view getDescription() const override
pure virtual methods ///
Definition: ProxySetting.cc:49
bool needTransfer() const override
Does this setting need to be transfered on reverse.
Contains the main loop of openMSX.
Definition: Reactor.hh:67
MSXMotherBoard * getMotherBoard() const
Definition: Reactor.cc:377
GlobalCommandController & getGlobalCommandController()
Definition: Reactor.hh:83
BaseSetting * findSetting(std::string_view name) const
Find the setting with given name.
This file implemented 3 utility functions:
Definition: Autofire.cc:5