-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.h
More file actions
68 lines (56 loc) · 1.78 KB
/
menu.h
File metadata and controls
68 lines (56 loc) · 1.78 KB
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
#ifndef menu_h
#define menu_h
#include <iostream>
#include "command.h"
using namespace std;
class Menu {
private:
int history_index;
vector<Command*> history;
public:
Menu() {
//Base constructor to set up all necessary members
this->history_index = -1;
};
void execute() {
//Prints the current commands value (based on history_index), if no commands exist
//print 0 by default
if(history_index < 0) {
cout << 0 << endl;
return;
}
cout << this->history.at(history_index)->execute() << endl;
};
bool initialized() {
//Return true if the history has been primed with a single op instruciton
//This is necessary because that is the base of a calculation
if(this->history_index >= 0) return true;
return false;
};
void add_command(Command* cmd) {
//Adds a command to history in the appropriate posiiton (based on history_index)
this->history.push_back(cmd);
this->history_index += 1;
};
Command* get_command() {
//Returns the command in history we are currently referring to (based on history_index)
return this->history[this->history_index];
};
void undo() {
//Moves to the last command in history (if possible)
if(this->history_index > 0) {
history_index -= 1;
return;
}
cout << "Error\n";
};
void redo() {
//Moves to the next command in history (if possible)
if(this->history_index < (int)this->history.size()-1) {
++ history_index;
return;
}
cout << "Error\n";
};
};
#endif //__MENU_CLASS__