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