-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreen.h
More file actions
41 lines (33 loc) · 823 Bytes
/
Screen.h
File metadata and controls
41 lines (33 loc) · 823 Bytes
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
#ifndef SCREEN_H
#define SCREEN_H
#include <string>
#include <cstddef>
class Screen {
public:
typedef std::string::size_type pos;
Screen() = default;
Screen(pos ht, pos wd) : height(ht), width(wd), contents(ht * wd, ' ') {}
Screen(pos ht, pos wd, char c) : height(ht), width(wd), contents(ht * wd, c) {}
char get() const { return contents[cursor]; }
inline char get(pos ht, pos wd) const;
Screen &move(pos r, pos c);
void some_member() const;
private:
pos cursor = 0;
pos height = 0, width = 0;
std::string contents;
mutable std::size_t access_ctr;
};
inline Screen &Screen::move(pos r, pos c) {
pos row = r * width;
cursor = row + c;
return *this;
}
char Screen::get(pos r, pos c) const {
pos row = r * width;
return contents[row + c];
}
void Screen::some_member() const {
++access_ctr;
}
#endif