TextStyle.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31 #ifndef DRAIN_TEXT_STYLE
32 #define DRAIN_TEXT_STYLE
33 
34 #include <iostream>
35 #include <map>
36 #include <set>
37 
38 #include "Type.h"
39 //#include "Sprinter.h"
40 //#include "StringBuilder.h"
41 
42 namespace drain
43 {
44 
46 
50 class TextStyle {
51 
52 public:
53 
54  enum Colour {DEFAULT_COLOR=0, BLACK, GRAY, RED, GREEN, YELLOW, BLUE, PURPLE, CYAN, WHITE};
55 
56  enum Style {NO_STYLE=0, ITALIC=1, BOLD=2, DIM=4, REVERSE=8}; // NO_STYLE not needed?
57 
58  enum Line {NO_LINE=0, UNDERLINE=1, DOUBLE_UNDERLINE=2, OVERLINE=4};
59 
60 
61  // Could be: EnumFlagger<SingleFlagger> ? -> see TextDecorator
62  Colour colour;
63 
64  // Could be: EnumFlagger<MultiFlagger> -> see TextDecorator
65  std::set<Style> style;
66 
67  // Could be: EnumFlagger<SingleFlagger> ? -> see TextDecorator
68  Line line;
69 
70  template <typename ... T>
71  inline
72  void set(const T &... args) {
73  reset();
74  //this->value = 0;
75  add(args...);
76  }
77 
78  template <typename T, typename ... TT>
79  inline
80  void add(const T & arg, const TT &... args) {
81  _add(arg);
82  add(args...);
83  }
84 
85 protected:
86 
87  inline
88  void reset(){
89  colour = Colour::DEFAULT_COLOR;
90  line = Line::NO_LINE;
91  style.clear();
92  };
93 
94 
95  inline
96  void set(){};
97 
98  inline
99  void add(){};
100 
101  inline
102  void _add(const Colour & c){
103  colour = c;
104  };
105 
106  inline
107  void _add(const Line & l){
108  line = l;
109  };
110 
111  inline
112  void _add(const Style & s){
113  style.insert(s);
114  };
115 
116 };
117 
118 DRAIN_TYPENAME(TextStyle);
119 
120 DRAIN_TYPENAME(TextStyle::Colour);
121 DRAIN_TYPENAME(TextStyle::Line);
122 DRAIN_TYPENAME(TextStyle::Style);
123 
124 inline
125 std::ostream & operator<<(std::ostream & ostr, const TextStyle &t){
126  ostr << __FILE__ << ':' << __LINE__ << '?';
127  return ostr;
128 }
129 
130 
131 } // ::drain
132 
133 #endif
Utility for scanning text segments.
Definition: TextStyle.h:50
Definition: DataSelector.cpp:1277