-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordBox.h
61 lines (48 loc) · 1.38 KB
/
WordBox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef WORDBOX_H
#define WORDBOX_H
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <clocale>
#include <locale>
class WordBox {
public:
using Row = std::vector<std::wstring>;
WordBox(wchar_t h = L'-', wchar_t v = L'|', wchar_t c = L'+');
void setAlign(unsigned i, bool left);
bool isAligned(unsigned i) const;
wchar_t vertical() const;
wchar_t horizontal() const;
void addContent(const std::wstring& content);
void newRow();
template <typename Iterator>
void addRow(Iterator begin, Iterator end);
template <typename Container>
void addRow(const Container& container);
const std::vector<Row>& getRows() const;
void prepare() const;
std::wstring ruler() const;
int getWidth(unsigned i) const;
bool hasRuler() const;
void toggleRuler();
void textLength(int l);
void print(void);
private:
wchar_t _h;
wchar_t _v;
wchar_t _c;
mutable bool _hasRuler;
Row _current;
std::vector<Row> _rows;
mutable std::vector<unsigned> _width;
mutable std::map<unsigned, bool> _align;
int maxrowlength = 20;
static std::wstring repeat(unsigned times, wchar_t c);
unsigned columnCount() const;
std::wstring format(const std::wstring& content) const;
void calculateWidths() const;
void configureAlignment() const;
};
#endif // WORDBOX_H