-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path7_32.h
73 lines (67 loc) · 1.27 KB
/
7_32.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
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef EX7_32_H
#define EX7_32_H
class Screen;
class Window_mgr
{
public:
using ScreenIndex = vector<Screen>::size_type;
inline void clear(ScreenIndex);
private:
vector<Screen> screens{Screen(24, 80, ' ')};
};
class Screen
{
public:
typedef std::string::size_type pos;
friend void Window_mgr::clear(ScreenIndex);
Screen &set(char c)
{
contents[cursor] = c;
return *this;
}
Screen &set(pos r, pos col, char c)
{
contents[r * width + col] = c;
return *this;
}
Screen &display(std::ostream &os)
{
do_display(os);
return *this;
}
const Screen &display(std::ostream &os) const
{
do_display(os);
return *this;
}
Screen() = default;
Screen(pos ht, pos wd, char c) : height(ht), width(wd), contents(ht * width, c) { }
Screen(pos ht, pos wd) : height(ht), width(wd), contents(ht * wd, ' ') { }
char get() const
{
return contents[cursor];
}
char get(pos ht, pos wd) const
{
return contents[ht * width + wd];
}
Screen &move(pos r, pos c)
{
cursor = r * width + c;
return *this;
}
private:
void do_display(std::ostream &os) const
{
os << contents;
}
pos cursor = 0;
pos height = 0, width = 0;
std::string contents;
};
void Window_mgr::clear(ScreenIndex i)
{
Screen &s = screens[i];
s.contents = string(s.height * s.width, ' ');
}
#endif