Connect++ 0.5.0
A fast, readable connection prover for first-order logic.
Loading...
Searching...
No Matches
vic_strings.hpp
1/*
2
3Copyright © 2023-24 Sean Holden. All rights reserved.
4
5*/
6/*
7
8This file is part of Connect++.
9
10Connect++ is free software: you can redistribute it and/or modify it
11under the terms of the GNU General Public License as published by the
12Free Software Foundation, either version 3 of the License, or (at your
13option) any later version.
14
15Connect++ is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18more details.
19
20You should have received a copy of the GNU General Public License along
21with Connect++. If not, see <https://www.gnu.org/licenses/>.
22
23*/
24
25#ifndef VICSTRING_HPP
26#define VICSTRING_HPP
27
28#include<iostream>
29#include<vector>
30#include<string>
31
39//--------------------------------------------------------------
40namespace unicode_symbols {
44 struct LogSym {
45 static std::string neg;
46 static std::string unicode_space;
47 static std::string or_sym;
48 static std::string and_sym;
49 static std::string true_sym;
50 static std::string false_sym;
51 static std::string forall;
52 static std::string exists;
53 static std::string ifthen;
54 static std::string iff;
55 };
56}
57//--------------------------------------------------------------
58namespace ansi_escape_colours {
62 enum class ColourName {NOCOL,
63 RED,
64 GREEN,
65 BLUE,
66 LBLUE,
67 ORANGE,
68 YELLOW,
69 PURPLE,
70 GREY,
71 LGREY
72 };
82 struct Colour {
83 static uint8_t num_colours;
84 static std::string nocol;
85 static std::string red;
86 static std::string green;
87 static std::string blue;
88 static std::string lblue;
89 static std::string orange;
90 static std::string yellow;
91 static std::string purple;
92 static std::string grey;
93 static std::string lgrey;
94
95 static std::string name_to_string(const ColourName&);
96 };
97}
98//--------------------------------------------------------------
99using std::ostream;
100using std::string;
101
102namespace colour_string {
103 using namespace ansi_escape_colours;
119 private:
120 uint8_t num_colours;
121 bool use_colours;
122 std::vector<ColourName> map;
123 string s;
124 public:
125 ColourString(bool uc)
126 : num_colours(Colour::num_colours)
127 , use_colours(uc)
128 , map()
129 , s()
130 {
131 map = { ColourName::NOCOL,
132 ColourName::RED,
133 ColourName::GREEN,
134 ColourName::BLUE,
135 ColourName::LBLUE,
136 ColourName::ORANGE,
137 ColourName::YELLOW,
138 ColourName::PURPLE,
139 ColourName::GREY,
140 ColourName::LGREY };
141 }
142 /*
143 * Straighforward gets and sets.
144 */
145 bool get_use_colours() const { return use_colours; }
146 void set_use_colours(bool b) { use_colours = b; }
147 void set_map(uint8_t i, ColourName colour) {
148 if (i >= 0 && i < Colour::num_colours)
149 map[i] = colour;
150 }
155 ColourString operator()(const string& _s) {
156 s = _s;
157 return *this;
158 }
164 string operator()(const string& _s, size_t num) {
165 if (use_colours && num >=0 && num < map.size())
166 return Colour::name_to_string(map[num]) + _s + Colour::nocol;
167 else
168 return _s;
169 }
170
171 /*
172 *Individual colour setters.
173 */
174 string red() {
175 if (use_colours)
176 return Colour::red + s + Colour::nocol;
177 else
178 return s;
179 }
180 string green() {
181 if (use_colours)
182 return Colour::green + s + Colour::nocol;
183 else
184 return s;
185 }
186 string blue() {
187 if (use_colours)
188 return Colour::blue + s + Colour::nocol;
189 else
190 return s;
191 }
192 string lblue() {
193 if (use_colours)
194 return Colour::lblue + s + Colour::nocol;
195 else
196 return s;
197 }
198 string orange() {
199 if (use_colours)
200 return Colour::orange + s + Colour::nocol;
201 else
202 return s;
203 }
204 string yellow() {
205 if (use_colours)
206 return Colour::yellow + s + Colour::nocol;
207 else
208 return s;
209 }
210 string purple() {
211 if (use_colours)
212 return Colour::purple + s + Colour::nocol;
213 else
214 return s;
215 }
216 string grey() {
217 if (use_colours)
218 return Colour::grey + s + Colour::nocol;
219 else
220 return s;
221 }
222 string lgrey() {
223 if (use_colours)
224 return Colour::lgrey + s + Colour::nocol;
225 else
226 return s;
227 }
228 };
229}
230
231//--------------------------------------------------------------
232namespace verbose_print {
237 class VPrint {
238 private:
239 static uint8_t verbosity;
240 public:
241 VPrint() = delete;
242 VPrint(uint8_t v) { verbosity = v; }
243 void operator()(uint8_t, const string&, bool = false, uint8_t = 1);
244 void operator()(uint8_t, char*, bool = false, uint8_t = 1);
245 void nl(uint8_t, uint8_t = 1);
246 };
247}
248
249//--------------------------------------------------------------
250namespace commas {
263 class comma {
264 private:
265 size_t target;
266 size_t i;
267 public:
271 comma() = delete;
275 comma(size_t _target)
276 : i(1), target(_target) {}
280 string operator()() {
281 if (i < target) {
282 i++;
283 return string(", ");
284 }
285 return string("");
286 }
287 };
288}
289//--------------------------------------------------------------
296template<typename T>
297string vector_to_string(const std::vector<T>& v,
298 string left = "(",
299 string right = ")",
300 string sep = ", ") {
301 string s(left);
302 size_t i = 1;
303 size_t l = v.size();
304 for (const T& element : v) {
305 s += element.to_string();
306 if (i++ < l)
307 s += sep;
308 }
309 s += right;
310 return s;
311}
315template<typename T>
316string vector_to_string(const std::vector<T*>& v,
317 string left = "(",
318 string right = ")",
319 string sep = ", ") {
320 string s(left);
321 size_t i = 1;
322 size_t l = v.size();
323 for (const T* element : v) {
324 s += element->to_string();
325 if (i++ < l)
326 s += sep;
327 }
328 s += right;
329 return s;
330}
340template<typename T>
341string vector_to_string(const std::vector<T>& v,
342 bool p,
343 string left = "(",
344 string right = ")",
345 string sep = ", ") {
346 string s(left);
347 size_t i = 1;
348 size_t l = v.size();
349 for (const T& element : v) {
350 s += element.to_string(p);
351 if (i++ < l)
352 s += sep;
353 }
354 s += right;
355 return s;
356}
360template<typename T>
361string vector_to_string(const std::vector<T*>& v,
362 bool p,
363 string left = "(",
364 string right = ")",
365 string sep = ", ") {
366 string s(left);
367 size_t i = 1;
368 size_t l = v.size();
369 for (const T* element : v) {
370 s += element->to_string(p);
371 if (i++ < l)
372 s += sep;
373 }
374 s += right;
375 return s;
376}
380template<typename T>
381string vector_to_string(const std::vector<T*>& v,
382 bool p1,
383 bool p2,
384 string left = "(",
385 string right = ")",
386 string sep = ", ") {
387 string s(left);
388 size_t i = 1;
389 size_t l = v.size();
390 for (const T* element : v) {
391 s += element->to_string(p1, p2);
392 if (i++ < l)
393 s += sep;
394 }
395 s += right;
396 return s;
397}
398
399#endif
Simple addition of colour to strings and ostreams.
string operator()(const string &_s, size_t num)
ColourString operator()(const string &_s)
Simple function object for putting commas in lists.
comma()=delete
Wouldn't make any sense.
comma(size_t _target)
Initialise with the length of the list you're printing.
string operator()()
The magic happens here!
void nl(uint8_t, uint8_t=1)
void operator()(uint8_t, const string &, bool=false, uint8_t=1)
vic_string - "verbose/indented/coloured"