-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.h
78 lines (58 loc) · 1.61 KB
/
command.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
/**
* Command.h
* Base class Command, Parent of BorrowCommand, ReturnCommand, HistoreCommand?
* and InventoryCommand
*
* @author Olga Kuriatnyk
*/
#ifndef COMMAND_H
#define COMMAND_H
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
using namespace std;
class Command;
class CommandFactory {
public:
// virtual create() function will be overridden for
// drama, comedy, and classic objects separately
virtual Command *create(const char &commandType) const = 0;
};
class Command {
public:
// constructor
Command() = default;
// destructor
virtual ~Command() = default;
// copy constructor not allowed
Command(const Command &c) = delete;
// move not allowed
Command(Command &&other) = delete;
// assignment not allowed
Command &operator=(const Command &other) = delete;
// move assignment not allowed
Command &operator=(Command &&other) = delete;
// register the commad factory
static void registerType(const char &type, CommandFactory *newFactroy);
// create if there is the command factory
//@return Commad pointer
static Command *create(const char &type);
// virtual function for read command string.
virtual void read(istream &is) = 0;
// process command
virtual void process() = 0;
protected:
char commandType = ' ';
set<char> movieTypes{ 'C', 'D', 'F' };
// helper function for read(istream& is) function
string readNextItem(istream &io, char end = '\n');
private:
//@return command factory map
static map<char, CommandFactory *> &getMap() {
static map<char, CommandFactory *> factory;
return factory;
}
};
#endif