OXYGENHUB
◆ main openmsx / src / Pluggable.hh
1.6 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef PLUGGABLE_HH
2
#define PLUGGABLE_HH
3
4
#include "EmuTime.hh"
5
6
#include "zstring_view.hh"
7
8
namespace openmsx {
9
10
class Connector;
11
12
class Pluggable
13
{
14
public:
15
	virtual ~Pluggable() = default;
16
17
	/** Name used to identify this pluggable.
18
	  */
19
	[[nodiscard]] virtual zstring_view getName() const;
20
21
	/** A pluggable belongs to a certain class. A pluggable only fits in
22
	  * connectors of the same class.
23
	  */
24
	[[nodiscard]] virtual zstring_view getClass() const = 0;
25
26
	/** Description for this pluggable.
27
	  */
28
	[[nodiscard]] virtual zstring_view getDescription() const = 0;
29
30
	/** This method is called when this pluggable is inserted in a
31
	  * connector.
32
	  * @throws PlugException
33
	  */
34
	void plug(Connector& connector, EmuTime time);
35
36
	/** This method is called when this pluggable is removed from a
37
	  * connector.
38
	  */
39
	void unplug(EmuTime time);
40
41
	/** Get the connector this Pluggable is plugged into. Returns nullptr
42
	  * if this Pluggable is not plugged.
43
	  */
44
	[[nodiscard]] Connector* getConnector() const { return connector; }
45
46
	/** Returns true if this pluggable is currently plugged into a connector.
47
	  * The method getConnector() can also be used, but this is more
48
	  * descriptive.
49
	  */
50
	[[nodiscard]] bool isPluggedIn() const { return getConnector() != nullptr; }
51
52
protected:
53
	Pluggable();
54
	virtual void plugHelper(Connector& newConnector, EmuTime time) = 0;
55
	/* implementations of unplugHelper() may not throw exceptions. */
56
	virtual void unplugHelper(EmuTime time) = 0;
57
58
	friend class Connector; // for de-serialization
59
	void setConnector(Connector* conn) { connector = conn; }
60
61
private:
62
	Connector* connector;
63
};
64
65
} // namespace openmsx
66
67
#endif