-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.h
More file actions
175 lines (123 loc) · 2.75 KB
/
command.h
File metadata and controls
175 lines (123 loc) · 2.75 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
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
/*
* command.h
*
* @authors Juan Arias & Nick Tibbott
*
* Command class for extendable Commands and provided basic Commands
*
*/
#ifndef COMMAND_H
#define COMMAND_H
using namespace std;
#include "item.h"
#include "media.h"
/* Forward declaration to avoid circular linkage */
class Store;
/*
* Abstract class for all Commands to have common interface
*/
class Command {
protected:
/* All Commands will operate on a Store */
Store* store;
/* Name of file with Command */
const string fileName;
/*
* Protected constructor for subclasses to set store pointer
*/
explicit Command(Store* store, const string& fileName = "");
public:
/*
* Virtual destructor
*/
virtual ~Command();
/*
* Executes the Command
*/
virtual void execute() const = 0;
};
/*
* subclass of Command to create a customer
*/
class AddCustomer: public Command {
/* Only Store can call private constructor */
friend class Store;
private:
/* ID for the customer */
const long customerID;
/* Name for the customer */
const string name;
/*
* Constructs an AddCustomer object with a given store and line
*/
AddCustomer(Store* store, long customerID, const string& name);
public:
/*
* Execute the command
*/
void execute() const override;
};
/*
* Removes Customer from Store at destruction to deallocate memory
*/
class RemoveCustomer: public Command {
/* Only Store can call private constructor */
friend class Store;
private:
/* ID for the customer */
const long customerID;
/*
* Constructs an AddCustomer object with a given store and line
*/
RemoveCustomer(Store* store, long customerID);
public:
/*
* Execute the command
*/
void execute() const override;
};
/*
* subclass of Command to add an item
*/
class AddItem: public Command {
/* Only Store can call private constructor */
friend class Store;
private:
/* type of item to add */
const ItemType* itemType;
/* type of media for the item */
const Media* media;
/* line from "data4commands.txt" */
const string line;
/*
* Constructs an AddItem object with a given store, itemType, media and line
*/
AddItem(Store* store, const ItemType* itemType, const Media* media,
const string& fileName, const string& line);
public:
/*
* Execute the command
*/
void execute() const override;
};
/*
* Holds error message data to print to the console
* Subclass of Command
*/
class DisplayError: public Command {
/* Only Store can call private constructor */
friend class Store;
private:
/* Line in file with error */
const string line;
/*
* Constructs a DisplayError object with a given store and error line
*/
DisplayError(Store* store, const string& fileName, const string& line);
public:
/*
* Executes the command
*/
void execute() const override;
};
#endif /* COMMAND_H */