-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy path19.17.cpp
80 lines (70 loc) · 1.54 KB
/
19.17.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
/*
* Exercise 19.17: Define a type alias for each distinct Screen member function
* type.
*
* By Faisal Saadatmand
*/
#ifndef SCREEN_H
#define SCREEN_H
#include <iostream>
#include <string>
class Screen {
public:
enum Directions { HOME, FORWARD, BACK, UP, DOWN }; // need to be before Movement
using pos = std::string::size_type;
using Action = Screen& (Screen::*)(); // home(), forward(), back(), up(), down()
using Movement = Screen& (Screen::*)(Directions); // move(Directions)
using Cursor_Postion = char (Screen::*)() const; // get(), get_cursor()
using Postion = char (Screen::*)(pos, pos) const; // get(pos, pos)
char get_cursor() const { return contents[cursor]; }
char get() const;
char get(pos ht, pos wd) const;
Screen& move(Directions);
Screen& home();
Screen& forward();
Screen& back();
Screen& up();
Screen& down();
private:
static Action Menu[];
std::string contents;
pos cursor;
pos height, width;
};
// static member
Screen::Action Screen::Menu[] = { &Screen::home,
&Screen::forward,
&Screen::back,
&Screen::up,
&Screen::down,
};
Screen& Screen::home()
{
std::cout << "home()\n";
return *this;
}
Screen& Screen::forward()
{
std::cout << "forward()\n";
return *this;
}
Screen& Screen::back()
{
std::cout << "back()\n";
return *this;
}
Screen& Screen::up()
{
std::cout << "up()\n";
return *this;
}
Screen& Screen::down()
{
std::cout << "down()\n";
return *this;
}
Screen& Screen::move(Directions cm)
{
return (this->*Menu[cm]) ();
}
#endif // SCREEN_H