-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandProcessing.h
180 lines (154 loc) · 4.8 KB
/
CommandProcessing.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//To prevent mutiple inclusion:
#ifndef COMMANDPROCESSING_H
#define COMMANDPROCESSING_H
#include "GameEngine.h"
#include "LoggingObserver.h"
#include <string>
#include <list>
class GameEngine;
//Command class:
class Command : public ILoggable, public Subject
{
public:
//Default constructor:
Command();
//Destructor:
~Command();
//Command that has a specific command name and a default effect:
Command(std::string command);
//save the effect:
void saveEffect(string nextState);
// returns the name of the command as a string
std::string getCommandName();
// returns the name of the effect as a string
std::string getEffect();
//logger function:
std::string stringToLog();
//copy constructor:
Command(const Command &c);
//assignment operator:
Command& operator = (const Command& c);
//stream insertion operator:
friend ostream& operator<<(ostream& os, const Command& c);
private:
std::string* _command;
std::string* _effect;
};
//CommandProcessor:
/*
* The CommandProcessor class.
* This is the Target class.
*/
class CommandProcessor: public ILoggable, public Subject
{
public:
//Default constructor:
CommandProcessor();
//Destructor:
virtual ~CommandProcessor();
//set a new file name:
virtual void setPath(string newPath);
//getCommand function that read command and save them to the list
//of command:
std::list<Command>* getCommand();
//Validate a command on curernt state:
bool validate(GameEngine* myGame, Command* command);
//returns the command list pointer
list<Command>* getCommandList();
//Logger function:
std::string stringToLog();
//copy constructor
CommandProcessor(const CommandProcessor &cp);
//assignment operator:
CommandProcessor& operator = (const CommandProcessor& cp);
//stream insertion operator:
friend ostream& operator<<(ostream& os, const CommandProcessor& cp);
/************************************************************
* method for a3
*************************************************************/
list<string>* getMapCommands();
list<string>* getPlayerCommands();
string* getGameNum();
string* getMaxTurns();
void setMaxTurns(string newNum);
//This analyze the tournament command (if any) and catch the needed info
void tournamentHelper(string commandLine);
void showHelpPage();
bool tournament_mode;
string* turn_num;
protected:
//implemented as virtual function so it would work for both console
// and file inputs:
virtual void readCommand();
void saveCommand();
std::string* command_in;
std::list<Command>* commands_ptr;
bool reject;
/************************************************************
* properties for a3
*************************************************************/
private:
std::list<string>* _commands_map;
std::list<string>* _commands_players;
string* _game_num;
string* _max_turn;
};
//FileLineReader
/*
* The FileLineReader class.
* This is the Adaptee class.
*/
class FileLineReader
{
public:
//default constructor:
FileLineReader();
//Constructor with a file path explicitly inputed
FileLineReader(std::string path);
//Destructor:
~FileLineReader();
// Used to read line from the file and get everthing into
// a single string:
std::string readLineFromFile();
//returns the path that the fileLineReader is reading
std::string getPath();
//copy constructor
FileLineReader(const FileLineReader &flr);
//assignment operator:
FileLineReader& operator = (const FileLineReader& flr);
//stream insertion operator:
friend ostream& operator<<(ostream& os, const FileLineReader& flr);
private:
std::string* _path;
};
//FileCommandProcessorAdapter:
/*
* The FileCommandProcessorAdaptor class.
* This is the adapter class.
* It adapts a CommandProcessor to a FileLineReader.
* Its interface is CommandProcessor.
*/
class FileCommandProcessorAdapter : public CommandProcessor
{
public:
//Default Constructor
FileCommandProcessorAdapter();
//Destructor:
~FileCommandProcessorAdapter();
//Processes a specific file:
FileCommandProcessorAdapter(std::string pathIn);
//set a new file name:
void setPath(string newPath);
//copy constructor
FileCommandProcessorAdapter(const FileCommandProcessorAdapter &fcpa);
//assignment operator:
FileCommandProcessorAdapter& operator = (const FileCommandProcessorAdapter& fcpa);
//stream insertion operator:
friend ostream& operator<<(ostream& os, const FileCommandProcessorAdapter& fcpa);
protected:
void readCommand();
//file lien reader is called to read command from file:
FileLineReader* flr;
std::string* _pathIn;
};
#endif