|
1 | | -#include <ostream> |
2 | 1 | #include <iostream> |
| 2 | +#include <ostream> |
3 | 3 |
|
4 | 4 | #ifndef GDB_DEBUG_H_ |
5 | 5 | #define GDB_DEBUG_H_ |
6 | 6 |
|
7 | | - |
8 | 7 | namespace GdbColor { |
9 | | - enum Code { |
10 | | - FG_RED = 31, |
11 | | - FG_GREEN = 32, |
12 | | - FG_BLUE = 34, |
13 | | - FG_DEFAULT = 39, |
14 | | - BG_RED = 41, |
15 | | - BG_GREEN = 42, |
16 | | - BG_BLUE = 44, |
17 | | - BG_DEFAULT = 49 |
18 | | - }; |
| 8 | +enum Code { |
| 9 | + FG_RED = 31, |
| 10 | + FG_GREEN = 32, |
| 11 | + FG_BLUE = 34, |
| 12 | + FG_DEFAULT = 39, |
| 13 | + BG_RED = 41, |
| 14 | + BG_GREEN = 42, |
| 15 | + BG_BLUE = 44, |
| 16 | + BG_DEFAULT = 49 |
| 17 | +}; |
19 | 18 | // std::ostream& operator<<(std::ostream& os, Code code); |
20 | | - std::ostream& operator<<(std::ostream& os, Code code) { |
21 | | - return os << "\033[" << static_cast<int>(code) << "m"; |
22 | | - } |
| 19 | +std::ostream &operator<<(std::ostream &os, Code code) { |
| 20 | + return os << "\033[" << static_cast<int>(code) << "m"; |
| 21 | +} |
23 | 22 | } |
24 | 23 |
|
25 | | - //class ColorOut: public std::ostream |
26 | | - class ColorOut |
27 | | - { |
28 | | - private: |
29 | | - std::ostream& out; |
30 | | - GdbColor::Code color; |
31 | | - public: |
32 | | - ColorOut(std::ostream& _out, GdbColor::Code _color):out(_out), color(_color){} |
33 | | - template<typename T> |
34 | | - const ColorOut& operator<< (const T& val) const |
35 | | - {out << color << val << GdbColor::FG_DEFAULT; |
36 | | - return *this;} |
37 | | -/* template<typename T> |
38 | | - const ColorOut& operator<< (const T* val) const |
39 | | - {out << GdbColor::FG_RED << val << GdbColor::FG_DEFAULT; |
40 | | - return *this;} |
41 | | - template <class _CharT, class _Traits = std::char_traits<_CharT> > |
42 | | - const ColorOut& operator<< ( const |
43 | | - std::basic_ios<_CharT,_Traits>& (*pf)(std::basic_ios<_CharT,_Traits>&))const |
44 | | - {out << GdbColor::FG_RED << pf << GdbColor::FG_DEFAULT; |
45 | | - return *this;} |
46 | | -*/ |
47 | | - const ColorOut& operator<< (std::ostream& (*pf)(std::ostream&)) const |
48 | | - {out << color << pf << GdbColor::FG_DEFAULT; |
49 | | - return *this;} |
50 | | - |
51 | | - }; |
| 24 | +// class ColorOut: public std::ostream |
| 25 | +class ColorOut { |
| 26 | +private: |
| 27 | + std::ostream &out; |
| 28 | + GdbColor::Code color; |
| 29 | + |
| 30 | +public: |
| 31 | + ColorOut(std::ostream &_out, GdbColor::Code _color) |
| 32 | + : out(_out), color(_color) {} |
| 33 | + template <typename T> const ColorOut &operator<<(const T &val) const { |
| 34 | + out << color << val << GdbColor::FG_DEFAULT; |
| 35 | + return *this; |
| 36 | + } |
| 37 | + /* template<typename T> |
| 38 | + const ColorOut& operator<< (const T* val) const |
| 39 | + {out << GdbColor::FG_RED << val << GdbColor::FG_DEFAULT; |
| 40 | + return *this;} |
| 41 | + template <class _CharT, class _Traits = std::char_traits<_CharT> > |
| 42 | + const ColorOut& operator<< ( const |
| 43 | + std::basic_ios<_CharT,_Traits>& |
| 44 | + (*pf)(std::basic_ios<_CharT,_Traits>&))const |
| 45 | + {out << GdbColor::FG_RED << pf << GdbColor::FG_DEFAULT; |
| 46 | + return *this;} |
| 47 | + */ |
| 48 | + const ColorOut &operator<<(std::ostream &(*pf)(std::ostream &)) const { |
| 49 | + out << color << pf << GdbColor::FG_DEFAULT; |
| 50 | + return *this; |
| 51 | + } |
| 52 | +}; |
52 | 53 |
|
53 | 54 | static ColorOut dout(std::cout, GdbColor::FG_RED); |
54 | 55 | static ColorOut sout(std::cout, GdbColor::FG_GREEN); |
55 | 56 | static ColorOut hout(std::cout, GdbColor::FG_BLUE); |
56 | 57 |
|
57 | | - |
58 | 58 | #endif /*GDB_DEBUG_H_*/ |
0 commit comments