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 
41 {
42  if (auto* setting = getSetting()) {
43  return setting->getTypeString();
44  } else {
45  return "proxy";
46  }
47 }
48 
50 {
51  if (auto* setting = getSetting()) {
52  return setting->getDescription();
53  } else {
54  return "proxy";
55  }
56 }
57 
59 {
60  if (auto* setting = getSetting()) {
61  return setting->getValue();
62  } else {
63  throw MSXException("No setting '", getFullName(), "' on current machine.");
64  }
65 }
66 
68 {
69  if (auto* setting = getSetting()) {
70  return setting->getDefaultValue();
71  } else {
72  return TclObject("proxy");
73  }
74 }
75 
77 {
78  if (auto* setting = getSetting()) {
79  return setting->getRestoreValue();
80  } else {
81  return TclObject("proxy");
82  }
83 }
84 
86 {
87  if (auto* setting = getSetting()) {
88  // note: not setStringDirect()
89  setting->setValue(value);
90  } else {
91  throw MSXException("No setting '", getFullName(), "' on current machine.");
92  }
93 }
94 
95 void ProxySetting::tabCompletion(vector<string>& tokens) const
96 {
97  if (auto* setting = getSetting()) {
98  setting->tabCompletion(tokens);
99  }
100 }
101 
103 {
104  if (auto* setting = getSetting()) {
105  return setting->needLoadSave();
106  } else {
107  return false;
108  }
109 }
110 
112 {
113  if (auto* setting = getSetting()) {
114  return setting->needTransfer();
115  } else {
116  return false;
117  }
118 }
119 
120 void ProxySetting::setDontSaveValue(const TclObject& dontSaveValue)
121 {
122  if (auto* setting = getSetting()) {
123  setting->setDontSaveValue(dontSaveValue);
124  }
125 }
126 
128 {
129  if (auto* setting = getSetting()) {
130  setting->additionalInfo(result);
131  }
132 }
133 
134 } // namespace openmsx
const TclObject & getValue() const override
Get current value as a TclObject.
Definition: ProxySetting.cc:58
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
Contains the main loop of openMSX.
Definition: Reactor.hh:66
GlobalCommandController & getGlobalCommandController()
Definition: Reactor.hh:83
void setValueDirect(const TclObject &value) override
Similar to setValue(), but doesn&#39;t trigger Tcl traces.
Definition: ProxySetting.cc:85
TclObject getDefaultValue() const override
Get the default value of this setting.
Definition: ProxySetting.cc:67
MSXMotherBoard * getMotherBoard() const
Definition: Reactor.cc:366
string_view getDescription() const override
pure virtual methods ///
Definition: ProxySetting.cc:49
ProxySetting(Reactor &reactor, const TclObject &name)
Definition: ProxySetting.cc:13
string_view getFullName() const
Definition: Setting.hh:34
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void additionalInfo(TclObject &result) const override
Helper method for info().
void setValue(const TclObject &value) override
Change the value of this setting to the given value.
Definition: ProxySetting.cc:33
void tabCompletion(std::vector< std::string > &tokens) const override
Complete a partly typed value.
Definition: ProxySetting.cc:95
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
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 &#39;unset&#39; command.
Definition: ProxySetting.cc:76
bool needLoadSave() const override
Does this setting need to be loaded or saved (settings.xml).
bool needTransfer() const override
Does this setting need to be transfered on reverse.
BaseSetting * findSetting(string_view name) const
Find the setting with given name.