openMSX
Probe.hh
Go to the documentation of this file.
1#ifndef PROBE_HH
2#define PROBE_HH
3
5#include "Subject.hh"
6#include "strCat.hh"
7#include <string>
8
9namespace openmsx {
10
11class Debugger;
12
13class ProbeBase : public Subject<ProbeBase>
14{
15public:
16 ProbeBase(const ProbeBase&) = delete;
17 ProbeBase& operator=(const ProbeBase&) = delete;
18
19 [[nodiscard]] const std::string& getName() const { return name; }
20 [[nodiscard]] std::string_view getDescription() const { return description; }
21 [[nodiscard]] virtual std::string getValue() const = 0;
22
23protected:
24 ProbeBase(Debugger& debugger, std::string name,
25 static_string_view description);
26 ~ProbeBase();
27
28private:
29 Debugger& debugger;
30 const std::string name;
31 const static_string_view description;
32};
33
34
35template<typename T> class Probe final : public ProbeBase
36{
37public:
38 Probe(Debugger& debugger, std::string name,
39 static_string_view description, T t);
40
41 Probe& operator=(const T& newValue) {
42 if (value != newValue) {
43 value = newValue;
44 notify();
45 }
46 return *this;
47 }
48
49 [[nodiscard]] operator const T&() const {
50 return value;
51 }
52
53private:
54 [[nodiscard]] std::string getValue() const override;
55
56 T value;
57};
58
59template<typename T>
60Probe<T>::Probe(Debugger& debugger_, std::string name_,
61 static_string_view description_, T t)
62 : ProbeBase(debugger_, std::move(name_), std::move(description_))
63 , value(std::move(t))
64{
65}
66
67template<typename T>
68std::string Probe<T>::getValue() const
69{
70 return strCat(value);
71}
72
73// specialization for void
74template<> class Probe<void> final : public ProbeBase
75{
76public:
77 Probe(Debugger& debugger, std::string name, static_string_view description);
78 void signal();
79
80private:
81 [[nodiscard]] std::string getValue() const override;
82};
83
84} // namespace openmsx
85
86#endif
TclObject t
virtual std::string getValue() const =0
ProbeBase & operator=(const ProbeBase &)=delete
const std::string & getName() const
Definition Probe.hh:19
ProbeBase(const ProbeBase &)=delete
std::string_view getDescription() const
Definition Probe.hh:20
Probe(Debugger &debugger, std::string name, static_string_view description, T t)
Definition Probe.hh:60
Probe & operator=(const T &newValue)
Definition Probe.hh:41
Generic Gang-of-Four Subject class of the Observer pattern, templatized edition.
Definition Subject.hh:18
static_string_view
This file implemented 3 utility functions:
Definition Autofire.cc:9
STL namespace.
std::string strCat()
Definition strCat.hh:703