-
Notifications
You must be signed in to change notification settings - Fork 0
/
replay.h
58 lines (53 loc) · 1.05 KB
/
replay.h
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
#ifndef REPLAY_H
#define REPLAY_H
#include "steps.h"
#include "state.h"
#include <string>
class Replay {
std::vector<Step*> steps;
std::vector<Step*>::iterator current;
State &state;
public:
const char * name;
Replay(State &_state, const char * name):state(_state), name(name){
current = steps.begin();
}
~Replay(){
for(std::vector<Step*>::iterator i = steps.begin(); i != steps.end(); i++){
delete *i;
}
}
Replay& operator++(){
if(current != steps.end()&¤t!=(--steps.end())){
current++;
(*current)->execute(state);
}
return *this;
}
Replay& operator--(){
if(current != steps.begin()){
(*current)->unexecute(state);
current--;
}
return *this;
}
void gotoEnd(){
current = steps.end();
if(current != steps.begin()){
current--;
}
}
void reset(){
while(current != steps.begin()){
(*current)->unexecute(state);
current--;
}
}
Step* step(){
return *current;
}
std::vector<Step*>& getSteps(){
return steps;
}
};
#endif