openMSX
CliComm.hh
Go to the documentation of this file.
1#ifndef CLICOMM_HH
2#define CLICOMM_HH
3
4#include "strCat.hh"
5#include <array>
6#include <span>
7#include <string_view>
8
9namespace openmsx {
10
12{
13public:
14 enum LogLevel {
17 LOGLEVEL_ERROR, // ERROR may give preprocessor name clashes
19 NUM_LEVELS // must be last
20 };
33 NUM_UPDATES // must be last
34 };
35
36 virtual void log(LogLevel level, std::string_view message) = 0;
37 virtual void update(UpdateType type, std::string_view name,
38 std::string_view value) = 0;
41 virtual void updateFiltered(UpdateType type, std::string_view name,
42 std::string_view value) = 0;
43
44 // convenience methods (shortcuts for log())
45 void printInfo (std::string_view message);
46 void printWarning (std::string_view message);
47 void printError (std::string_view message);
48 void printProgress(std::string_view message);
49
50 // These overloads are (only) needed for efficiency, because otherwise
51 // the templated overload below is a better match than the 'string_view'
52 // overload above (and we don't want to construct a temp string).
53 void printInfo(const char* message) {
54 printInfo(std::string_view(message));
55 }
56 void printWarning(const char* message) {
57 printWarning(std::string_view(message));
58 }
59 void printError(const char* message) {
60 printError(std::string_view(message));
61 }
62 void printProgress(const char* message) {
63 printProgress(std::string_view(message));
64 }
65
66 template<typename... Args>
67 void printInfo(Args&& ...args) {
68 auto tmp = tmpStrCat(std::forward<Args>(args)...);
69 printInfo(std::string_view(tmp));
70 }
71 template<typename... Args>
72 void printWarning(Args&& ...args) {
73 auto tmp = tmpStrCat(std::forward<Args>(args)...);
74 printWarning(std::string_view(tmp));
75 }
76 template<typename... Args>
77 void printError(Args&& ...args) {
78 auto tmp = tmpStrCat(std::forward<Args>(args)...);
79 printError(std::string_view(tmp));
80 }
81 template<typename... Args>
82 void printProgress(Args&& ...args) {
83 auto tmp = tmpStrCat(std::forward<Args>(args)...);
84 printProgress(std::string_view(tmp));
85 }
86
87 // string representations of the LogLevel and UpdateType enums
88 [[nodiscard]] static std::span<const std::string_view, NUM_LEVELS> getLevelStrings() {
89 static constexpr std::array<std::string_view, NUM_LEVELS> levelStr = {
90 "info", "warning", "error", "progress"
91 };
92 return levelStr;
93 }
94 [[nodiscard]] static std::span<const std::string_view, NUM_UPDATES> getUpdateStrings() {
95 static constexpr std::array<std::string_view, NUM_UPDATES> updateStr = {
96 "led", "setting", "setting-info", "hardware", "plug",
97 "media", "status", "extension", "sounddevice", "connector",
98 "debug"
99 };
100 return updateStr;
101 }
102
103protected:
104 CliComm() = default;
105 ~CliComm() = default;
106};
107
108} // namespace openmsx
109
110#endif
void printProgress(const char *message)
Definition: CliComm.hh:62
void printProgress(std::string_view message)
Definition: CliComm.cc:20
void printInfo(std::string_view message)
Definition: CliComm.cc:5
virtual void updateFiltered(UpdateType type, std::string_view name, std::string_view value)=0
Same as update(), but checks that the value for type-name is the same as in the previous call.
CliComm()=default
void printError(const char *message)
Definition: CliComm.hh:59
virtual void update(UpdateType type, std::string_view name, std::string_view value)=0
~CliComm()=default
void printInfo(Args &&...args)
Definition: CliComm.hh:67
void printError(std::string_view message)
Definition: CliComm.cc:15
static std::span< const std::string_view, NUM_LEVELS > getLevelStrings()
Definition: CliComm.hh:88
void printWarning(Args &&...args)
Definition: CliComm.hh:72
void printProgress(Args &&...args)
Definition: CliComm.hh:82
void printWarning(std::string_view message)
Definition: CliComm.cc:10
void printError(Args &&...args)
Definition: CliComm.hh:77
void printWarning(const char *message)
Definition: CliComm.hh:56
void printInfo(const char *message)
Definition: CliComm.hh:53
virtual void log(LogLevel level, std::string_view message)=0
static std::span< const std::string_view, NUM_UPDATES > getUpdateStrings()
Definition: CliComm.hh:94
This file implemented 3 utility functions:
Definition: Autofire.cc:9
TemporaryString tmpStrCat(Ts &&... ts)
Definition: strCat.hh:610