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
|
#ifndef SCREEN_H
#define SCREEN_H
#include <string>
struct screen{
public:
//type alais(scope within class)
using pos = std::string::size_type;
//constructors
screen() = default;
screen( pos &h, pos &w, std::string &cntnt) : height(h), width(w), content(cntnt){}
screen(const pos& h, const pos& w, char c) : height(h), width(w), content(h*w,c){}
//member function declares
screen& set(char);
screen& set(pos,pos,char);
//private members
private:
pos cursor;
pos height = 0, width = 0;
std::string content = " ";
};
inline screen &screen::set(char c){
content[cursor] = c; // <--HERE
return *this; // return this object as an lvalue
}
inline screen &screen::set(pos r, pos col, char ch){
content[r*width + col] = ch; // <-- AND HERE
return *this; // return this object as an lvalue
}
#endif // SCREEN_H
|