openMSX
Pluggable.hh
Go to the documentation of this file.
1 #ifndef PLUGGABLE_HH
2 #define PLUGGABLE_HH
3 
4 #include "EmuTime.hh"
5 #include "string_ref.hh"
6 
7 namespace openmsx {
8 
9 class Connector;
10 
11 class Pluggable
12 {
13 public:
14  virtual ~Pluggable() {}
15 
18  virtual const std::string& getName() const;
19 
23  virtual string_ref getClass() const = 0;
24 
27  virtual string_ref getDescription() const = 0;
28 
33  void plug(Connector& connector, EmuTime::param time);
34 
38  void unplug(EmuTime::param time);
39 
43  Connector* getConnector() const { return connector; }
44 
49  bool isPluggedIn() const { return getConnector() != nullptr; }
50 
51 protected:
52  Pluggable();
53  virtual void plugHelper(Connector& newConnector, EmuTime::param time) = 0;
54  /* implementations of unplugHelper() may not throw exceptions. */
55  virtual void unplugHelper(EmuTime::param time) = 0;
56 
57  friend class Connector; // for de-serialization
58  void setConnector(Connector* conn) { connector = conn; }
59 
60 private:
61  Connector* connector;
62 };
63 
64 } // namespace openmsx
65 
66 #endif
Represents something you can plug devices into.
Definition: Connector.hh:20
Connector * getConnector() const
Get the connector this Pluggable is plugged into.
Definition: Pluggable.hh:43
void setConnector(Connector *conn)
Definition: Pluggable.hh:58
bool isPluggedIn() const
Returns true if this pluggable is currently plugged into a connector.
Definition: Pluggable.hh:49
virtual string_ref getClass() const =0
A pluggable belongs to a certain class.
virtual string_ref getDescription() const =0
Description for this pluggable.
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
virtual ~Pluggable()
Definition: Pluggable.hh:14
virtual void unplugHelper(EmuTime::param time)=0
void unplug(EmuTime::param time)
This method is called when this pluggable is removed from a conector.
Definition: Pluggable.cc:34
void plug(Connector &connector, EmuTime::param time)
This method is called when this pluggable is inserted in a connector.
Definition: Pluggable.cc:22
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
virtual const std::string & getName() const
Name used to identify this pluggable.
Definition: Pluggable.cc:16
virtual void plugHelper(Connector &newConnector, EmuTime::param time)=0