openMSX
DeviceConfig.hh
Go to the documentation of this file.
1 #ifndef DEVICECONFIG_HH
2 #define DEVICECONFIG_HH
3 
4 #include "string_ref.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:
23  : hwConf(nullptr), devConf(nullptr)
24  , primary(nullptr), secondary(nullptr)
25  {
26  }
27  DeviceConfig(const HardwareConfig& hwConf_, const XMLElement& devConf_)
28  : hwConf(&hwConf_), devConf(&devConf_)
29  , primary(nullptr), secondary(nullptr)
30  {
31  }
32  DeviceConfig(const HardwareConfig& hwConf_, const XMLElement& devConf_,
33  const XMLElement* primary_, const XMLElement* secondary_)
34  : hwConf(&hwConf_), devConf(&devConf_)
35  , primary(primary_), secondary(secondary_)
36  {
37  }
38  DeviceConfig(const DeviceConfig& other, const XMLElement& devConf_)
39  : hwConf(other.hwConf), devConf(&devConf_)
40  , primary(nullptr), secondary(nullptr)
41  {
42  }
43  DeviceConfig(const DeviceConfig& other, const XMLElement* devConf_)
44  : hwConf(other.hwConf), devConf(devConf_)
45  , primary(nullptr), secondary(nullptr)
46  {
47  }
48 
50  {
51  assert(hwConf);
52  return *hwConf;
53  }
54  const XMLElement* getXML() const
55  {
56  return devConf;
57  }
59  {
60  return const_cast<XMLElement*>(primary);
61  }
63  {
64  return const_cast<XMLElement*>(secondary);
65  }
66 
67  // convenience methods:
68  // methods below simply delegate to HardwareConfig or XMLElement
69  const FileContext& getFileContext() const;
71  CliComm& getCliComm() const;
73  Scheduler& getScheduler() const;
74  Reactor& getReactor() const;
76 
77  const XMLElement& getChild(string_ref name) const;
78  const std::string& getChildData(string_ref name) const;
80  string_ref defaultValue) const;
81  int getChildDataAsInt(string_ref name, int defaultValue = 0) const;
83  bool defaultValue = false) const;
84  const XMLElement* findChild(string_ref name) const;
85  const std::string& getAttribute(string_ref attName) const;
86  int getAttributeAsInt(string_ref attName, int defaultValue = 0) const;
87 
88 private:
89  const HardwareConfig* hwConf;
90  const XMLElement* devConf;
91  const XMLElement* primary;
92  const XMLElement* secondary;
93 };
94 
95 } // namespace openmsx
96 
97 #endif