openMSX
Pluggable.cc
Go to the documentation of this file.
1 #include "Pluggable.hh"
2 #include "PlugException.hh"
3 #include "Connector.hh"
4 #include "unreachable.hh"
5 #include <cassert>
6 
7 using std::string;
8 
9 namespace openmsx {
10 
12 {
13  setConnector(nullptr);
14 }
15 
16 std::string_view Pluggable::getName() const
17 {
18  return "";
19 }
20 
21 void Pluggable::plug(Connector& newConnector, EmuTime::param time)
22 {
23  assert(getClass() == newConnector.getClass());
24 
25  if (connector) {
26  throw PlugException(getName(), " already plugged in ",
27  connector->getName(), '.');
28  }
29  plugHelper(newConnector, time);
30  setConnector(&newConnector);
31 }
32 
33 void Pluggable::unplug(EmuTime::param time)
34 {
35  try {
36  unplugHelper(time);
37  } catch (MSXException&) {
39  }
40  setConnector(nullptr);
41 }
42 
43 } // namespace openmsx
Represents something you can plug devices into.
Definition: Connector.hh:21
const std::string & getName() const
Name that identifies this connector.
Definition: Connector.hh:29
virtual std::string_view getClass() const =0
A Connector belong to a certain class.
Thrown when a plug action fails.
virtual void unplugHelper(EmuTime::param time)=0
void plug(Connector &connector, EmuTime::param time)
This method is called when this pluggable is inserted in a connector.
Definition: Pluggable.cc:21
void unplug(EmuTime::param time)
This method is called when this pluggable is removed from a connector.
Definition: Pluggable.cc:33
void setConnector(Connector *conn)
Definition: Pluggable.hh:58
virtual std::string_view getName() const
Name used to identify this pluggable.
Definition: Pluggable.cc:16
virtual std::string_view getClass() const =0
A pluggable belongs to a certain class.
virtual void plugHelper(Connector &newConnector, EmuTime::param time)=0
This file implemented 3 utility functions:
Definition: Autofire.cc:9
#define UNREACHABLE
Definition: unreachable.hh:38