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
|
#ifndef SCREEN_H
#define SCREEN_H
#include <string>
#include <vector>
class Screen
{
public:
friend void Window_mgr::clear(std::vector<Screen>::size_type);
typedef std::string::size_type pos;
Screen() = default; // needed because Screen has another constuctor
Screen(pos ht, pos wd) : height(ht), width(wd) {}
Screen(pos ht, pos wd, char c) : height(ht), width(wd), contents(ht * wd, c) {}
Screen &move(pos r, pos c)
{
pos row = r * width; // compute the new location
cursor = row + c; // move curso to the column within that row
return *this; // return this object as lvalue
}
Screen &set(char c)
{
contents [cursor] = c; // set the new value at the crrent cursor location
return *this; // return this object as an lvalue
}
Screen &set(pos r, pos col, char ch)
{
contents[r*width + col] = ch; // set specidified location to given value
return *this; // return this object as an lvalue
}
Screen &display(std::ostream &os)
{
do_display(os);
return *this;
}
const Screen &display(std::ostream &os) const
{
do_display(os);
return *this;
}
char get() const
{
return contents[cursor];
}
char get(pos r, pos c) const
{
pos row = r * width;
return contents[row + c];
}
private:
void do_display(std::ostream &os) const
{
os << contents;
}
pos cursor = 0;
pos height = 0, width = 0;
std::string contents;
};
class Window_mgr
{
public:
// location ID for each screen window
typedef std::vector<Screen>::size_type ScreenIndex;
void clear(ScreenIndex i)
{
Screen &s = screens[i];
s.contents = string(s.height * s.width, ' ')
}
private:
std::vector<Screen> screens{Screen(24, 80, ' ')};
};
#endif // SALES_DATA_H
|