openMSX
DeviceConfig.hh
Go to the documentation of this file.
1 #ifndef DEVICECONFIG_HH
2 #define DEVICECONFIG_HH
3 
4 #include "string_view.hh"
5 #include <cassert>
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(string_view name) const;
71  const std::string& getChildData(string_view name) const;
73  string_view defaultValue) const;
74  int getChildDataAsInt(string_view name, int defaultValue = 0) const;
76  bool defaultValue = false) const;
77  const XMLElement* findChild(string_view name) const;
78  const std::string& getAttribute(string_view attName) const;
79  int getAttributeAsInt(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
int getChildDataAsInt(string_view name, int defaultValue=0) const
Definition: DeviceConfig.cc:52
Contains the main loop of openMSX.
Definition: Reactor.hh:66
const std::string & getChildData(string_view name) const
Definition: DeviceConfig.cc:43
DeviceConfig(const DeviceConfig &other, const XMLElement &devConf_)
Definition: DeviceConfig.hh:33
GlobalSettings & getGlobalSettings() const
Definition: DeviceConfig.cc:34
const XMLElement * findChild(string_view name) const
Definition: DeviceConfig.cc:61
const std::string & getAttribute(string_view attName) const
Definition: DeviceConfig.cc:65
const FileContext & getFileContext() const
Definition: DeviceConfig.cc:9
DeviceConfig(const HardwareConfig &hwConf_, const XMLElement &devConf_, const XMLElement *primary_, const XMLElement *secondary_)
Definition: DeviceConfig.hh:27
CliComm & getCliComm() const
Definition: DeviceConfig.cc:18
Reactor & getReactor() const
Definition: DeviceConfig.cc:30
bool getChildDataAsBool(string_view name, bool defaultValue=false) const
Definition: DeviceConfig.cc:56
int getAttributeAsInt(string_view attName, int defaultValue=0) const
Definition: DeviceConfig.cc:69
CommandController & getCommandController() const
Definition: DeviceConfig.cc:22
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
DeviceConfig(const HardwareConfig &hwConf_, const XMLElement &devConf_)
Definition: DeviceConfig.hh:23
const HardwareConfig & getHardwareConfig() const
Definition: DeviceConfig.hh:42
XMLElement * getSecondary() const
Definition: DeviceConfig.hh:55
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:15
XMLElement * getPrimary() const
Definition: DeviceConfig.hh:51
const XMLElement * getXML() const
Definition: DeviceConfig.hh:47
Scheduler & getScheduler() const
Definition: DeviceConfig.cc:26
This class contains settings that are used by several other class (including some singletons)...
MSXMotherBoard & getMotherBoard() const
Definition: DeviceConfig.cc:13
const XMLElement & getChild(string_view name) const
Definition: DeviceConfig.cc:39
DeviceConfig(const DeviceConfig &other, const XMLElement *devConf_)
Definition: DeviceConfig.hh:37