-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandProcessing.h
More file actions
135 lines (100 loc) · 3.18 KB
/
CommandProcessing.h
File metadata and controls
135 lines (100 loc) · 3.18 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
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
#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "LoggingObserver.h"
using namespace std;
enum GameState {
Start,
MapLoaded,
MapValidated,
PlayersAdded,
AssignReinforcements,
IssueOrders,
ExecuteOrders,
Win,
End
};
// Command Class Definition
class Command : public Subject, public ILoggable {
private:
// Dynamically allocated string variables
string* command;
string* effect;
public:
// Default Constructor
Command();
// Parameterized Constructor
Command(const string& cmd, const string& eff);
// Copy COnstructor
Command(const Command& other);
// Assignment Operator
Command& operator=(const Command& other);
// Stream Insertion Operator
friend ostream& operator<<(ostream& os, const Command& cmd);
// Destructor
~Command();
// Getters
string& getCommand() const;
string& getEffect() const;
void saveEffect(const string& newEffect);
string stringToLog() const override;
};
// CommandProccesor Class Definition
class CommandProcessor : public Subject, public ILoggable {
private:
vector<Command*>* commands; // commands is a pointer to a vector object that holds pointers to Command objects
GameState* currentState; // currentState is a pointer to a GameState enum
public:
// Default Constructor
CommandProcessor();
// Parameterized Constructor
CommandProcessor(GameState* state);
// Copy Constructor
CommandProcessor(const CommandProcessor& other);
// Assignment Operator
CommandProcessor& operator=(const CommandProcessor& other);
// Destructor
~CommandProcessor();
// Stream Insertion operator
friend ostream& operator<<(ostream& os, const CommandProcessor& cp);
// readCommand method
virtual void readCommand();
// set method
void setCurrentState(GameState state);
// get methods
Command* getCommand();
GameState getCurrentState() const;
void printCommands() const;
// save method
void saveCommand(Command* cmd);
// validate method
bool validate(Command* cmd);
string stringToLog() const override;
string getStateString() const;
static bool parseTournamentCommand(
const string& cmdStr,
vector<string>& maps,
vector<string>& strategies,
int& games,
int& maxTurns
);
};
// FileCommandProcessorAdapter Class Definition
class FileCommandProcessorAdapter : public CommandProcessor {
private:
string* fileName;
ifstream* commandFile;
public:
// Parameterized Constructor
FileCommandProcessorAdapter(const string& file);
// Copy Constructor
FileCommandProcessorAdapter(const FileCommandProcessorAdapter& other);
// Assignent Operator
FileCommandProcessorAdapter& operator=(const FileCommandProcessorAdapter& other);
// Destructor
~FileCommandProcessorAdapter();
// Overriden readCommand method
void readCommand() override;
};