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 XMLDocument;
11 class HardwareConfig;
12 class FileContext;
13 class MSXMotherBoard;
14 class CliComm;
15 class CommandController;
16 class Scheduler;
17 class Reactor;
18 class GlobalSettings;
19 
21 {
22 public:
23  DeviceConfig() = default;
24  DeviceConfig(const HardwareConfig& hwConf_, const XMLElement& devConf_)
25  : hwConf(&hwConf_), devConf(&devConf_)
26  {
27  }
28  DeviceConfig(const HardwareConfig& hwConf_, const XMLElement& devConf_,
29  const XMLElement* primary_, const XMLElement* secondary_)
30  : hwConf(&hwConf_), devConf(&devConf_)
31  , primary(primary_), secondary(secondary_)
32  {
33  }
34  DeviceConfig(const DeviceConfig& other, const XMLElement& devConf_)
35  : hwConf(other.hwConf), devConf(&devConf_)
36  {
37  }
38  DeviceConfig(const DeviceConfig& other, const XMLElement* devConf_)
39  : hwConf(other.hwConf), devConf(devConf_)
40  {
41  }
42 
43  [[nodiscard]] const HardwareConfig& getHardwareConfig() const
44  {
45  assert(hwConf);
46  return *hwConf;
47  }
48  [[nodiscard]] const XMLElement* getXML() const
49  {
50  return devConf;
51  }
52  [[nodiscard]] XMLElement* getPrimary() const
53  {
54  return const_cast<XMLElement*>(primary);
55  }
56  [[nodiscard]] XMLElement* getSecondary() const
57  {
58  return const_cast<XMLElement*>(secondary);
59  }
60 
61  // convenience methods:
62  // methods below simply delegate to HardwareConfig or XMLElement
63  [[nodiscard]] const FileContext& getFileContext() const;
64  [[nodiscard]] MSXMotherBoard& getMotherBoard() const;
65  [[nodiscard]] CliComm& getCliComm() const;
66  [[nodiscard]] CommandController& getCommandController() const;
67  [[nodiscard]] Scheduler& getScheduler() const;
68  [[nodiscard]] Reactor& getReactor() const;
69  [[nodiscard]] GlobalSettings& getGlobalSettings() const;
70  [[nodiscard]] XMLDocument& getXMLDocument();
71 
72  [[nodiscard]] const XMLElement& getChild(std::string_view name) const;
73  [[nodiscard]] std::string_view getChildData(std::string_view name) const;
74  [[nodiscard]] std::string_view getChildData(std::string_view name,
75  std::string_view defaultValue) const;
76  [[nodiscard]] int getChildDataAsInt(std::string_view name, int defaultValue) const;
77  [[nodiscard]] bool getChildDataAsBool(std::string_view name,
78  bool defaultValue = false) const;
79  [[nodiscard]] const XMLElement* findChild(std::string_view name) const;
80  [[nodiscard]] std::string_view getAttributeValue(std::string_view attName) const;
81  [[nodiscard]] int getAttributeValueAsInt(std::string_view attName, int defaultValue) const;
82 
83 private:
84  const HardwareConfig* hwConf = nullptr;
85  const XMLElement* devConf = nullptr;
86  const XMLElement* primary = nullptr;
87  const XMLElement* secondary = nullptr;
88 };
89 
90 } // namespace openmsx
91 
92 #endif
Reactor & getReactor() const
Definition: DeviceConfig.cc:30
bool getChildDataAsBool(std::string_view name, bool defaultValue=false) const
Definition: DeviceConfig.cc:61
DeviceConfig(const HardwareConfig &hwConf_, const XMLElement &devConf_, const XMLElement *primary_, const XMLElement *secondary_)
Definition: DeviceConfig.hh:28
CliComm & getCliComm() const
Definition: DeviceConfig.cc:18
XMLElement * getSecondary() const
Definition: DeviceConfig.hh:56
DeviceConfig(const HardwareConfig &hwConf_, const XMLElement &devConf_)
Definition: DeviceConfig.hh:24
const FileContext & getFileContext() const
Definition: DeviceConfig.cc:9
const XMLElement * findChild(std::string_view name) const
Definition: DeviceConfig.cc:66
DeviceConfig(const DeviceConfig &other, const XMLElement &devConf_)
Definition: DeviceConfig.hh:34
GlobalSettings & getGlobalSettings() const
Definition: DeviceConfig.cc:34
int getChildDataAsInt(std::string_view name, int defaultValue) const
Definition: DeviceConfig.cc:57
XMLDocument & getXMLDocument()
Definition: DeviceConfig.cc:38
XMLElement * getPrimary() const
Definition: DeviceConfig.hh:52
DeviceConfig(const DeviceConfig &other, const XMLElement *devConf_)
Definition: DeviceConfig.hh:38
MSXMotherBoard & getMotherBoard() const
Definition: DeviceConfig.cc:13
CommandController & getCommandController() const
Definition: DeviceConfig.cc:22
std::string_view getChildData(std::string_view name) const
Definition: DeviceConfig.cc:48
const HardwareConfig & getHardwareConfig() const
Definition: DeviceConfig.hh:43
Scheduler & getScheduler() const
Definition: DeviceConfig.cc:26
const XMLElement & getChild(std::string_view name) const
Definition: DeviceConfig.cc:44
int getAttributeValueAsInt(std::string_view attName, int defaultValue) const
Definition: DeviceConfig.cc:74
std::string_view getAttributeValue(std::string_view attName) const
Definition: DeviceConfig.cc:70
const XMLElement * getXML() const
Definition: DeviceConfig.hh:48
This class contains settings that are used by several other class (including some singletons).
Contains the main loop of openMSX.
Definition: Reactor.hh:68
This file implemented 3 utility functions:
Definition: Autofire.cc:9