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
const XMLElement & getChild(string_ref name) const
Definition: DeviceConfig.cc:39
Contains the main loop of openMSX.
Definition: Reactor.hh:63
bool getChildDataAsBool(string_ref name, bool defaultValue=false) const
Definition: DeviceConfig.cc:56
DeviceConfig(const DeviceConfig &other, const XMLElement &devConf_)
Definition: DeviceConfig.hh:38
GlobalSettings & getGlobalSettings() const
Definition: DeviceConfig.cc:34
int getAttributeAsInt(string_ref attName, int defaultValue=0) const
Definition: DeviceConfig.cc:69
int getChildDataAsInt(string_ref name, int defaultValue=0) const
Definition: DeviceConfig.cc:52
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
const FileContext & getFileContext() const
Definition: DeviceConfig.cc:9
const XMLElement * findChild(string_ref name) const
Definition: DeviceConfig.cc:61
DeviceConfig(const HardwareConfig &hwConf_, const XMLElement &devConf_, const XMLElement *primary_, const XMLElement *secondary_)
Definition: DeviceConfig.hh:32
CliComm & getCliComm() const
Definition: DeviceConfig.cc:18
Reactor & getReactor() const
Definition: DeviceConfig.cc:30
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:27
const HardwareConfig & getHardwareConfig() const
Definition: DeviceConfig.hh:49
const std::string & getChildData(string_ref name) const
Definition: DeviceConfig.cc:43
XMLElement * getSecondary() const
Definition: DeviceConfig.hh:62
XMLElement * getPrimary() const
Definition: DeviceConfig.hh:58
const XMLElement * getXML() const
Definition: DeviceConfig.hh:54
Scheduler & getScheduler() const
Definition: DeviceConfig.cc:26
const std::string & getAttribute(string_ref attName) const
Definition: DeviceConfig.cc:65
This class contains settings that are used by several other class (including some singletons)...
MSXMotherBoard & getMotherBoard() const
Definition: DeviceConfig.cc:13
DeviceConfig(const DeviceConfig &other, const XMLElement *devConf_)
Definition: DeviceConfig.hh:43