openMSX
CliComm.hh
Go to the documentation of this file.
1 #ifndef CLICOMM_HH
2 #define CLICOMM_HH
3 
4 #include "span.hh"
5 #include "strCat.hh"
6 #include "string_view.hh"
7 
8 namespace openmsx {
9 
10 class CliComm
11 {
12 public:
13  enum LogLevel {
16  LOGLEVEL_ERROR, // ERROR may give preprocessor name clashes
18  NUM_LEVELS // must be last
19  };
20  enum UpdateType {
21  LED,
31  NUM_UPDATES // must be last
32  };
33 
34  virtual void log(LogLevel level, string_view message) = 0;
35  virtual void update(UpdateType type, string_view name,
36  string_view value) = 0;
37 
38  // convenience methods (shortcuts for log())
39  void printInfo (string_view message);
40  void printWarning (string_view message);
41  void printError (string_view message);
42  void printProgress(string_view message);
43 
44  // These overloads are (only) needed for efficiency, because otherwise
45  // the templated overload below is a better match than the 'string_view'
46  // overload above (and we don't want to construct a temp string).
47  void printInfo(const char* message) {
48  printInfo(string_view(message));
49  }
50  void printWarning(const char* message) {
51  printWarning(string_view(message));
52  }
53  void printError(const char* message) {
54  printError(string_view(message));
55  }
56  void printProgress(const char* message) {
57  printProgress(string_view(message));
58  }
59 
60  template<typename... Args>
61  void printInfo(Args&& ...args) {
62  printInfo(string_view(strCat(std::forward<Args>(args)...)));
63  }
64  template<typename... Args>
65  void printWarning(Args&& ...args) {
66  printWarning(string_view(strCat(std::forward<Args>(args)...)));
67  }
68  template<typename... Args>
69  void printError(Args&& ...args) {
70  printError(string_view(strCat(std::forward<Args>(args)...)));
71  }
72  template<typename... Args>
73  void printProgress(Args&& ...args) {
74  printProgress(string_view(strCat(std::forward<Args>(args)...)));
75  }
76 
77  // string representations of the LogLevel and UpdateType enums
79  return levelStr;
80  }
82  return updateStr;
83  }
84 
85 protected:
86  CliComm() = default;
87  ~CliComm() = default;
88 
89 private:
90  static const char* const levelStr [NUM_LEVELS];
91  static const char* const updateStr[NUM_UPDATES];
92 };
93 
94 } // namespace openmsx
95 
96 #endif
void printProgress(const char *message)
Definition: CliComm.hh:56
void printError(Args &&...args)
Definition: CliComm.hh:69
void printError(const char *message)
Definition: CliComm.hh:53
void printWarning(Args &&...args)
Definition: CliComm.hh:65
void printInfo(Args &&...args)
Definition: CliComm.hh:61
void printInfo(const char *message)
Definition: CliComm.hh:47
void printProgress(Args &&...args)
Definition: CliComm.hh:73
Definition: span.hh:34
~CliComm()=default
CliComm()=default
void printInfo(string_view message)
Definition: CliComm.cc:15
void printWarning(const char *message)
Definition: CliComm.hh:50
virtual void log(LogLevel level, string_view message)=0
static span< const char *const > getLevelStrings()
Definition: CliComm.hh:78
static span< const char *const > getUpdateStrings()
Definition: CliComm.hh:81
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
void printProgress(string_view message)
Definition: CliComm.cc:30
virtual void update(UpdateType type, string_view name, string_view value)=0
std::string strCat(Ts &&...ts)
Definition: strCat.hh:577
void printWarning(string_view message)
Definition: CliComm.cc:20
void printError(string_view message)
Definition: CliComm.cc:25