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