openMSX
DeviceConfig.hh
Go to the documentation of this file.
1 #ifndef DEVICECONFIG_HH
2 #define DEVICECONFIG_HH
3 
4 #include <cassert>
5 #include <string_view>
6 
7 namespace openmsx {
8 
9 class XMLElement;
10 class HardwareConfig;
11 class FileContext;
12 class MSXMotherBoard;
13 class CliComm;
14 class CommandController;
15 class Scheduler;
16 class Reactor;
17 class GlobalSettings;
18 
20 {
21 public:
22  DeviceConfig() = default;
23  DeviceConfig(const HardwareConfig& hwConf_, const XMLElement& devConf_)
24  : hwConf(&hwConf_), devConf(&devConf_)
25  {
26  }
27  DeviceConfig(const HardwareConfig& hwConf_, const XMLElement& devConf_,
28  const XMLElement* primary_, const XMLElement* secondary_)
29  : hwConf(&hwConf_), devConf(&devConf_)
30  , primary(primary_), secondary(secondary_)
31  {
32  }
33  DeviceConfig(const DeviceConfig& other, const XMLElement& devConf_)
34  : hwConf(other.hwConf), devConf(&devConf_)
35  {
36  }
37  DeviceConfig(const DeviceConfig& other, const XMLElement* devConf_)
38  : hwConf(other.hwConf), devConf(devConf_)
39  {
40  }
41 
43  {
44  assert(hwConf);
45  return *hwConf;
46  }
47  const XMLElement* getXML() const
48  {
49  return devConf;
50  }
52  {
53  return const_cast<XMLElement*>(primary);
54  }
56  {
57  return const_cast<XMLElement*>(secondary);
58  }
59 
60  // convenience methods:
61  // methods below simply delegate to HardwareConfig or XMLElement
62  const FileContext& getFileContext() const;
64  CliComm& getCliComm() const;
66  Scheduler& getScheduler() const;
67  Reactor& getReactor() const;
69 
70  const XMLElement& getChild(std::string_view name) const;
71  const std::string& getChildData(std::string_view name) const;
72  std::string_view getChildData(std::string_view name,
73  std::string_view defaultValue) const;
74  int getChildDataAsInt(std::string_view name, int defaultValue = 0) const;
75  bool getChildDataAsBool(std::string_view name,
76  bool defaultValue = false) const;
77  const XMLElement* findChild(std::string_view name) const;
78  const std::string& getAttribute(std::string_view attName) const;
79  int getAttributeAsInt(std::string_view attName, int defaultValue = 0) const;
80 
81 private:
82  const HardwareConfig* hwConf = nullptr;
83  const XMLElement* devConf = nullptr;
84  const XMLElement* primary = nullptr;
85  const XMLElement* secondary = nullptr;
86 };
87 
88 } // namespace openmsx
89 
90 #endif
openmsx::HardwareConfig
HardwareConfig
Definition: HardwareConfig.cc:459
openmsx::DeviceConfig::getScheduler
Scheduler & getScheduler() const
Definition: DeviceConfig.cc:26
openmsx::DeviceConfig::DeviceConfig
DeviceConfig(const HardwareConfig &hwConf_, const XMLElement &devConf_, const XMLElement *primary_, const XMLElement *secondary_)
Definition: DeviceConfig.hh:27
openmsx::Scheduler
Definition: Scheduler.hh:33
openmsx::CommandController
Definition: CommandController.hh:17
openmsx::DeviceConfig
Definition: DeviceConfig.hh:19
openmsx::DeviceConfig::getMotherBoard
MSXMotherBoard & getMotherBoard() const
Definition: DeviceConfig.cc:13
openmsx::XMLElement
XMLElement
Definition: XMLElement.cc:348
openmsx::DeviceConfig::getPrimary
XMLElement * getPrimary() const
Definition: DeviceConfig.hh:51
openmsx::DeviceConfig::findChild
const XMLElement * findChild(std::string_view name) const
Definition: DeviceConfig.cc:61
openmsx::DeviceConfig::getChild
const XMLElement & getChild(std::string_view name) const
Definition: DeviceConfig.cc:39
openmsx::DeviceConfig::getReactor
Reactor & getReactor() const
Definition: DeviceConfig.cc:30
openmsx::DeviceConfig::DeviceConfig
DeviceConfig(const DeviceConfig &other, const XMLElement *devConf_)
Definition: DeviceConfig.hh:37
openmsx::FileContext
Definition: FileContext.hh:9
openmsx::DeviceConfig::getCliComm
CliComm & getCliComm() const
Definition: DeviceConfig.cc:18
openmsx::Reactor
Contains the main loop of openMSX.
Definition: Reactor.hh:66
openmsx::DeviceConfig::getAttribute
const std::string & getAttribute(std::string_view attName) const
Definition: DeviceConfig.cc:65
openmsx::DeviceConfig::DeviceConfig
DeviceConfig(const DeviceConfig &other, const XMLElement &devConf_)
Definition: DeviceConfig.hh:33
openmsx::XMLElement
Definition: XMLElement.hh:15
openmsx::DeviceConfig::DeviceConfig
DeviceConfig(const HardwareConfig &hwConf_, const XMLElement &devConf_)
Definition: DeviceConfig.hh:23
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:59
openmsx::DeviceConfig::getChildData
const std::string & getChildData(std::string_view name) const
Definition: DeviceConfig.cc:43
openmsx::FileContext
FileContext
Definition: FileContext.cc:120
openmsx::DeviceConfig::getHardwareConfig
const HardwareConfig & getHardwareConfig() const
Definition: DeviceConfig.hh:42
openmsx::DeviceConfig::getGlobalSettings
GlobalSettings & getGlobalSettings() const
Definition: DeviceConfig.cc:34
openmsx::DeviceConfig::getAttributeAsInt
int getAttributeAsInt(std::string_view attName, int defaultValue=0) const
Definition: DeviceConfig.cc:69
openmsx::DeviceConfig::DeviceConfig
DeviceConfig()=default
openmsx::GlobalSettings
This class contains settings that are used by several other class (including some singletons).
Definition: GlobalSettings.hh:24
openmsx::DeviceConfig::getXML
const XMLElement * getXML() const
Definition: DeviceConfig.hh:47
openmsx::DeviceConfig::getChildDataAsInt
int getChildDataAsInt(std::string_view name, int defaultValue=0) const
Definition: DeviceConfig.cc:52
openmsx::DeviceConfig::getCommandController
CommandController & getCommandController() const
Definition: DeviceConfig.cc:22
openmsx::CliComm
Definition: CliComm.hh:10
openmsx::HardwareConfig
Definition: HardwareConfig.hh:21
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:133
openmsx::DeviceConfig::getFileContext
const FileContext & getFileContext() const
Definition: DeviceConfig.cc:9
openmsx::DeviceConfig::getSecondary
XMLElement * getSecondary() const
Definition: DeviceConfig.hh:55
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::DeviceConfig::getChildDataAsBool
bool getChildDataAsBool(std::string_view name, bool defaultValue=false) const
Definition: DeviceConfig.cc:56