avr: Construct the pin table more carefully
[avr-sim.git] / src / VerboseInfo.h
blob5584f8a8af8ee82c117163d2435498a4b66a61b2
1 #ifndef AVR_VERBOSEINFO_H
2 #define AVR_VERBOSEINFO_H
4 #include <iostream>
6 namespace avr {
8 enum Verbosity { NONE = 0, WARN = 1, INFO = 2, DBG = 3 };
10 class VerboseInfo;
11 class VerboseInfo {
12 public:
13 VerboseInfo() : verbosity(0) {}
15 public:
16 void setVerbosity(Verbosity verbosity);
17 void setVerbosity(int verbosity);
18 void increaseVerbosity();
20 public:
21 bool shouldOutput(Verbosity vb) const {
22 return ((int)vb > verbosity);
25 public:
26 class Printer {
27 public:
28 Printer(const VerboseInfo & vi, Verbosity vb,
29 std::ostream & ostr)
30 : vi(vi), vb(vb), ostr(ostr) {}
32 public:
33 template <class T>
34 Printer & operator <<(const T & c) {
35 if( vi.shouldOutput(vb) )
36 ostr << c;
37 return *this;
40 Printer & operator<<(std::ostream & (*pf)(std::ostream &)) {
41 if( vi.shouldOutput(vb) )
42 ostr << pf;
43 return *this;
46 private:
47 const VerboseInfo & vi;
48 Verbosity vb;
49 std::ostream & ostr;
52 Printer operator ()(Verbosity vb,
53 std::ostream & ostr = std::cout) const {
54 return Printer(*this, vb, ostr);
57 private:
58 int verbosity;
61 inline void VerboseInfo::setVerbosity(Verbosity verbosity) {
62 this->verbosity = (int)verbosity;
65 inline void VerboseInfo::setVerbosity(int verbosity) {
66 this->verbosity = verbosity;
69 inline void VerboseInfo::increaseVerbosity() {
70 this->verbosity++;
73 extern VerboseInfo info;
76 #endif /* AVR_VERBOSEINFO_H */