-
Notifications
You must be signed in to change notification settings - Fork 246
/
7.32.cpp
114 lines (90 loc) · 2.29 KB
/
7.32.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <string>
#include <vector>
#include <iostream>
class Screen;
class Window_mgr {
public:
using screen_index = std::vector<Screen>::size_type;
void clear(screen_index);
Window_mgr();
private:
std::vector<Screen> screens; //{Screen(24, 80)};
};
class Screen {
friend void Window_mgr::clear(screen_index);
public:
using pos = std::string::size_type;
using content_type = char;
Screen() = default;
Screen(pos ht, pos wd)
: height(ht), width(wd), contents(ht * wd, ' ') {}
Screen(pos ht, pos wd, content_type c)
: height(ht), width(wd), contents(ht * wd, c) {}
const content_type &get() const { return contents[cursor]; }
//content_type &get() { return contents[cursor]; }
const content_type &get(pos row, pos col) const;
//content_type &get(pos row, pos col);
Screen &set(content_type c);
Screen &set(pos row, pos col, content_type c);
Screen &move(pos row, pos col);
const Screen &display(std::ostream &os) const;
Screen &display(std::ostream &os);
private:
void do_display(std::ostream &os) const;
pos cursor = 0;
pos width = 0;
pos height = 0;
std::string contents;
};
inline
const Screen::content_type &Screen::get(pos row, pos col) const {
return contents[row * width + col];
}
//inline
//Screen::content_type &Screen::get(pos row, pos col) {
// return contents[row * width + col];
//}
inline
Screen &Screen::set(content_type c) {
contents[cursor] = c;
return *this;
}
inline
Screen &Screen::set(pos row, pos col, content_type c) {
contents[row * width + col] = c;
return *this;
}
inline
Screen &Screen::move(pos row, pos col) {
cursor = row * width + col;
return *this;
}
inline
const Screen &Screen::display(std::ostream &os) const {
do_display(os);
return *this;
}
inline
Screen &Screen::display(std::ostream &os) {
do_display(os);
return *this;
}
inline
void Screen::do_display(std::ostream &os) const {
//os << contents;
for (pos i = 0; i != contents.size(); ++i) {
os << contents[i];
if ((i + 1) % width == 0 && i + 1 != contents.size())
os << "\n";
}
}
Window_mgr::Window_mgr() : screens{Screen(24, 80)} {}
void Window_mgr::clear(screen_index i) {
Screen &s = screens[i];
s.contents = std::string(s.height * s.width, ' ');
}
int main() {
Window_mgr window;
window.clear(0);
return 0;
}