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 (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 (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
openmsx::GlobalCommandController::getSettingsManager
SettingsManager & getSettingsManager()
Definition: GlobalCommandController.hh:89
openmsx::ProxySetting::setValue
void setValue(const TclObject &value) override
Change the value of this setting to the given value.
Definition: ProxySetting.cc:33
openmsx::ProxySetting::needTransfer
bool needTransfer() const override
Does this setting need to be transfered on reverse.
Definition: ProxySetting.cc:111
openmsx::ProxySetting::setValueDirect
void setValueDirect(const TclObject &value) override
Similar to setValue(), but doesn't trigger Tcl traces.
Definition: ProxySetting.cc:85
openmsx::ProxySetting::getTypeString
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
MSXException.hh
openmsx::MSXException
Definition: MSXException.hh:9
openmsx::ProxySetting::setDontSaveValue
void setDontSaveValue(const TclObject &dontSaveValue) override
This value will never end up in the settings.xml file.
Definition: ProxySetting.cc:120
openmsx::BaseSetting::getFullName
std::string_view getFullName() const
Definition: Setting.hh:35
openmsx::ProxySetting::needLoadSave
bool needLoadSave() const override
Does this setting need to be loaded or saved (settings.xml).
Definition: ProxySetting.cc:102
openmsx::Reactor
Contains the main loop of openMSX.
Definition: Reactor.hh:66
Reactor.hh
openmsx::Reactor::getMotherBoard
MSXMotherBoard * getMotherBoard() const
Definition: Reactor.cc:368
openmsx::SettingsManager::findSetting
BaseSetting * findSetting(std::string_view name) const
Find the setting with given name.
openmsx::ProxySetting::additionalInfo
void additionalInfo(TclObject &result) const override
Helper method for info().
Definition: ProxySetting.cc:127
openmsx::BaseSetting
Definition: Setting.hh:18
openmsx::ProxySetting::getValue
const TclObject & getValue() const override
Get current value as a TclObject.
Definition: ProxySetting.cc:58
openmsx::ProxySetting::tabCompletion
void tabCompletion(std::vector< std::string > &tokens) const override
Complete a partly typed value.
Definition: ProxySetting.cc:95
openmsx::ProxySetting::getDescription
std::string_view getDescription() const override
pure virtual methods ///
Definition: ProxySetting.cc:49
openmsx::ProxySetting::ProxySetting
ProxySetting(Reactor &reactor, const TclObject &name)
Definition: ProxySetting.cc:13
openmsx::ProxySetting::getRestoreValue
TclObject getRestoreValue() const override
Get the value that will be set after a Tcl 'unset' command.
Definition: ProxySetting.cc:76
GlobalCommandController.hh
MSXCommandController.hh
openmsx::TclObject
Definition: TclObject.hh:21
ProxySetting.hh
openmsx::ProxySetting::getDefaultValue
TclObject getDefaultValue() const override
Get the default value of this setting.
Definition: ProxySetting.cc:67
openmsx::Reactor::getGlobalCommandController
GlobalCommandController & getGlobalCommandController()
Definition: Reactor.hh:83
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
MSXMotherBoard.hh