MyLang
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
ccc.hpp
Go to the documentation of this file.
1 #ifndef CCC_HPP
2 #define CCC_HPP
3 
4 #include <iostream>
5 
6 #if defined(__unix) || defined(__unix__) || defined(unix) ||\
7  defined(__linux) || defined(__linux__) || defined(linux) ||\
8  defined(__MACH__) || defined(BSD) || defined(__GNU__)
9  #define CCC_UNIX
10 #endif
11 
12 #if defined(_WIN64) || defined(_WIN32) || defined(_WIN16) ||\
13  defined(__WIN64__) || defined(__WIN32__) || defined(__WIN16__) ||\
14  defined(WINDOWS) || defined(__WINDOWS__)
15  #define CCC_WINDOWS
16  #include <windows.h>
17 #endif
18 
19 namespace ccc {
20 
21 enum Style {
22  // font
23  f_0 = 10,
24  f_1,
25  f_2,
26  f_3,
27  f_4,
28  f_5,
29  f_6,
30  f_7,
31  f_8,
32  f_9,
33 
34  // foreground color
35  cf_black = 30,
43 
44  // background color
45  cb_black = 40,
53 
54  // enable style
55  s_bold = 1,
56  s_faint = 2,
57 
58  s_italic = 3,
59  s_fraktur = 20,
60 
63 
66 
67  s_framed = 51,
69 
71  s_conceal = 8,
72  s_delete = 9,
74 
75  // disable style
76  d_all = 0,
77  d_font = 10,
78  d_color_f = 39,
79  d_color_b = 49,
80 
84  d_blink = 25,
85  d_border = 54,
86 
87  d_negative = 27,
88  d_conceal = 28,
89  d_delete = 29,
91 };
92 
93 static std::ostream &operator<<(std::ostream &s, const Style &style) {
94  #if defined(CCC_UNIX)
95  return s << '\x1b' << '[' << (int) style << 'm';
96  #elif defined(CCC_WINDOWS)
97  // not implemented
98 
99  return s;
100  #endif
101 }
102 
103 template <class T>
104 class alsoStyle {
105 public:
106  const T _object;
107  const Style _style;
108 
109  inline alsoStyle(const T &object, const Style &style):
110  _object(object), _style(style) {}
111 };
112 
113 template <class T>
114 static const alsoStyle<T> operator+(const T &object, const Style &style) {
115  return alsoStyle<T>(object, style);
116 }
117 
118 template <class T>
119 inline std::ostream &operator<<(std::ostream &s, const alsoStyle<T> &target) {
120  return s << target._object << target._style;
121 }
122 
123 }
124 
125 #endif
Definition: ccc.hpp:23
const Style _style
Definition: ccc.hpp:107
Definition: ccc.hpp:76
Definition: ccc.hpp:32
Definition: ccc.hpp:40
Definition: ccc.hpp:67
Definition: ccc.hpp:81
Definition: ccc.hpp:46
Definition: ccc.hpp:41
Definition: ccc.hpp:65
Definition: ccc.hpp:85
Definition: ccc.hpp:59
Definition: ccc.hpp:72
Definition: ccc.hpp:90
Definition: ccc.hpp:55
Definition: ccc.hpp:88
Definition: ccc.hpp:24
Definition: ccc.hpp:50
Definition: ccc.hpp:36
Definition: ccc.hpp:47
Definition: ccc.hpp:68
Definition: ccc.hpp:64
Definition: ccc.hpp:51
Definition: ccc.hpp:71
Definition: ccc.hpp:79
Definition: ccc.hpp:89
Definition: ccc.hpp:39
Definition: ccc.hpp:61
static const alsoStyle< T > operator+(const T &object, const Style &style)
Definition: ccc.hpp:114
Definition: ccc.hpp:49
Definition: ccc.hpp:35
Definition: ccc.hpp:42
Definition: ccc.hpp:31
Definition: ccc.hpp:30
Definition: ccc.hpp:62
Definition: ccc.hpp:48
Definition: ccc.hpp:28
Definition: ccc.hpp:58
Definition: ccc.hpp:26
Definition: ccc.hpp:29
Definition: ccc.hpp:82
Style
Definition: ccc.hpp:21
Definition: ccc.hpp:84
Definition: ccc.hpp:38
Definition: ccc.hpp:83
Definition: ccc.hpp:52
Definition: ccc.hpp:56
Definition: ccc.hpp:104
Definition: ccc.hpp:70
static std::ostream & operator<<(std::ostream &s, const Style &style)
Definition: ccc.hpp:93
Definition: ccc.hpp:27
Definition: ccc.hpp:87
Definition: ccc.hpp:25
Definition: ccc.hpp:45
alsoStyle(const T &object, const Style &style)
Definition: ccc.hpp:109
Definition: ccc.hpp:77
Definition: ccc.hpp:73
Definition: ccc.hpp:78
const T _object
Definition: ccc.hpp:106
Definition: ccc.hpp:37