-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory.cpp
More file actions
88 lines (73 loc) · 1.91 KB
/
history.cpp
File metadata and controls
88 lines (73 loc) · 1.91 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "history.h"
using std::stack;
using std::pair;
using std::make_pair;
HistoryItem::HistoryItem(){
item = Menu::no_item;
hist_indices = make_pair(0, 0);
}
HistoryItem::HistoryItem(MenuItem hist){
item = hist;
hist_indices = make_pair(0, 0);
}
HistoryItem::HistoryItem(MenuItem hist, pair<unsigned int, unsigned int> indices){
item = hist;
hist_indices = indices;
}
pair<unsigned int, unsigned int> HistoryItem::get_indices(){
return hist_indices;
}
MenuItem& HistoryItem::get_item(){
return item;
}
void HistoryItem::set_indices(std::pair<unsigned int, unsigned int> indices){
hist_indices = indices;
}
HistoryItem BrowserHistory::go_back(){
if(history.size() < 2){
return HistoryItem(Menu::no_item);
}
last_item_was_fut = false;
HistoryItem temp = history.top();
history.pop();
future.push(temp);
HistoryItem to_return = history.top();
history.pop();
return to_return;
}
void BrowserHistory::set_hist_indices(pair<unsigned int, unsigned int> indices){
if(history.size()){
history.top().set_indices(indices);
}
}
void BrowserHistory::set_fut_indices(pair<unsigned int, unsigned int> indices){
if(future.size() == 1){
future.top().set_indices(indices);
}
}
HistoryItem BrowserHistory::go_forward(){
if(!future.size()){
return HistoryItem(Menu::no_item);
}
last_item_was_fut = true;
HistoryItem to_return = future.top();
future.pop();
history.push(to_return);
return to_return;
}
void BrowserHistory::clear_future(){
last_item_was_fut = false;
future = stack<HistoryItem>();
}
void BrowserHistory::add_item(MenuItem item){
add_item(HistoryItem(item));
}
void BrowserHistory::add_item(HistoryItem item){
if(!last_item_was_fut){
history.push(item);
}
}
BrowserHistory::BrowserHistory(){
history = stack<HistoryItem>();
future = stack<HistoryItem>();
}