Connect++ 0.6.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#include<cstdint>
32
40//--------------------------------------------------------------
41namespace unicode_symbols {
45 struct LogSym {
46 static std::string neg;
47 static std::string unicode_space;
48 static std::string or_sym;
49 static std::string and_sym;
50 static std::string true_sym;
51 static std::string false_sym;
52 static std::string forall;
53 static std::string exists;
54 static std::string ifthen;
55 static std::string iff;
56 static std::string neq;
57 static std::string subbed;
58 };
59}
60//--------------------------------------------------------------
61namespace ansi_escape_colours {
65 enum class ColourName {NOCOL,
66 RED,
67 GREEN,
68 BLUE,
69 LBLUE,
70 ORANGE,
71 YELLOW,
72 PURPLE,
73 GREY,
74 LGREY
75 };
85 struct Colour {
86 static uint8_t num_colours;
87 static std::string nocol;
88 static std::string red;
89 static std::string green;
90 static std::string blue;
91 static std::string lblue;
92 static std::string orange;
93 static std::string yellow;
94 static std::string purple;
95 static std::string grey;
96 static std::string lgrey;
97
98 static std::string name_to_string(const ColourName&);
99 };
100}
101//--------------------------------------------------------------
102using std::ostream;
103using std::string;
104
105namespace colour_string {
106 using namespace ansi_escape_colours;
122 private:
123 uint8_t num_colours;
124 bool use_colours;
125 std::vector<ColourName> map;
126 string s;
127 public:
128 ColourString(bool uc)
129 : num_colours(Colour::num_colours)
130 , use_colours(uc)
131 , map()
132 , s()
133 {
134 map = { ColourName::NOCOL,
135 ColourName::RED,
136 ColourName::GREEN,
137 ColourName::BLUE,
138 ColourName::LBLUE,
139 ColourName::ORANGE,
140 ColourName::YELLOW,
141 ColourName::PURPLE,
142 ColourName::GREY,
143 ColourName::LGREY };
144 }
145 /*
146 * Straighforward gets and sets.
147 */
148 bool get_use_colours() const { return use_colours; }
149 void set_use_colours(bool b) { use_colours = b; }
150 void set_map(uint8_t i, ColourName colour) {
151 if (i >= 0 && i < Colour::num_colours)
152 map[i] = colour;
153 }
158 ColourString operator()(const string& _s) {
159 s = _s;
160 return *this;
161 }
167 string operator()(const string& _s, size_t num) {
168 if (use_colours && num >=0 && num < map.size())
169 return Colour::name_to_string(map[num]) + _s + Colour::nocol;
170 else
171 return _s;
172 }
173
174 /*
175 *Individual colour setters.
176 */
177 string red() {
178 if (use_colours)
179 return Colour::red + s + Colour::nocol;
180 else
181 return s;
182 }
183 string green() {
184 if (use_colours)
185 return Colour::green + s + Colour::nocol;
186 else
187 return s;
188 }
189 string blue() {
190 if (use_colours)
191 return Colour::blue + s + Colour::nocol;
192 else
193 return s;
194 }
195 string lblue() {
196 if (use_colours)
197 return Colour::lblue + s + Colour::nocol;
198 else
199 return s;
200 }
201 string orange() {
202 if (use_colours)
203 return Colour::orange + s + Colour::nocol;
204 else
205 return s;
206 }
207 string yellow() {
208 if (use_colours)
209 return Colour::yellow + s + Colour::nocol;
210 else
211 return s;
212 }
213 string purple() {
214 if (use_colours)
215 return Colour::purple + s + Colour::nocol;
216 else
217 return s;
218 }
219 string grey() {
220 if (use_colours)
221 return Colour::grey + s + Colour::nocol;
222 else
223 return s;
224 }
225 string lgrey() {
226 if (use_colours)
227 return Colour::lgrey + s + Colour::nocol;
228 else
229 return s;
230 }
231 };
232}
233
234//--------------------------------------------------------------
235namespace verbose_print {
240 class VPrint {
241 private:
242 static uint8_t verbosity;
243 public:
244 VPrint() = delete;
245 VPrint(uint8_t v) { verbosity = v; }
246 void operator()(uint8_t, const string&, bool = false, uint8_t = 1);
247 void operator()(uint8_t, char*, bool = false, uint8_t = 1);
248 void nl(uint8_t, uint8_t = 1);
249 };
250}
251
252//--------------------------------------------------------------
253namespace commas {
266 class comma {
267 private:
268 size_t target;
269 size_t i;
270 public:
274 comma() = delete;
278 comma(size_t _target)
279 : i(1), target(_target) {}
283 string operator()() {
284 if (i < target) {
285 i++;
286 return string(", ");
287 }
288 return string("");
289 }
290 };
291}
292//--------------------------------------------------------------
299template<typename T>
300string vector_to_string(const std::vector<T>& v,
301 string left = "(",
302 string right = ")",
303 string sep = ", ") {
304 string s(left);
305 size_t i = 1;
306 size_t l = v.size();
307 for (const T& element : v) {
308 s += element.to_string();
309 if (i++ < l)
310 s += sep;
311 }
312 s += right;
313 return s;
314}
318template<typename T>
319string vector_to_string(const std::vector<T*>& v,
320 string left = "(",
321 string right = ")",
322 string sep = ", ") {
323 string s(left);
324 size_t i = 1;
325 size_t l = v.size();
326 for (const T* element : v) {
327 s += element->to_string();
328 if (i++ < l)
329 s += sep;
330 }
331 s += right;
332 return s;
333}
343template<typename T>
344string vector_to_string(const std::vector<T>& v,
345 bool p,
346 string left = "(",
347 string right = ")",
348 string sep = ", ") {
349 string s(left);
350 size_t i = 1;
351 size_t l = v.size();
352 for (const T& element : v) {
353 s += element.to_string(p);
354 if (i++ < l)
355 s += sep;
356 }
357 s += right;
358 return s;
359}
363template<typename T>
364string vector_to_string(const std::vector<T*>& v,
365 bool p,
366 string left = "(",
367 string right = ")",
368 string sep = ", ") {
369 string s(left);
370 size_t i = 1;
371 size_t l = v.size();
372 for (const T* element : v) {
373 s += element->to_string(p);
374 if (i++ < l)
375 s += sep;
376 }
377 s += right;
378 return s;
379}
383template<typename T>
384string vector_to_string(const std::vector<T*>& v,
385 bool p1,
386 bool p2,
387 string left = "(",
388 string right = ")",
389 string sep = ", ") {
390 string s(left);
391 size_t i = 1;
392 size_t l = v.size();
393 for (const T* element : v) {
394 s += element->to_string(p1, p2);
395 if (i++ < l)
396 s += sep;
397 }
398 s += right;
399 return s;
400}
401
402#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"