-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.hpp
95 lines (76 loc) · 2.03 KB
/
command.hpp
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
#ifndef SRE_COMMAND_HPP
#define SRE_COMMAND_HPP
#include <list>
namespace sre { namespace console {
class CommandFunc;
class CommandDef;
class Command;
class Value;
class Type;
class Arg;
using TypeList = std::list<Type>;
class CommandDef
{
private:
std::string id;
std::unique_ptr<TypeList> parameters;
std::shared_ptr<CommandFunc> func;
public:
CommandDef (const CommandDef& cmdDef);
CommandDef (std::string id);
void push (Type type);
void setFunc (std::shared_ptr<CommandFunc> cmdFunc);
std::string operator() (Command cmd);
std::string getId() {return id;}
friend bool operator== (const Command& cmd, const CommandDef& def);
friend bool operator== (const CommandDef& def, const Command& cmd);
};
class Command
{
private:
std::string id;
std::unique_ptr<TypeList> args;
public:
Command(std::string id);
void push(Type type);
friend bool operator==(const Command& cmd, const CommandDef& def);
friend bool operator==(const CommandDef& def, const Command& cmd);
};
class CommandFunc {
public:
CommandFunc () {}
virtual std::string operator() (const Command& cmd) =0;
};
class EmptyCommand : public CommandFunc {
public:
std::string operator() (const Command& cmd) { return "Did nothing."; }
};
//class EchoCommand : public CommandFunc {
// void operator() (Command cmd);
//};
class Type
{
private:
std::string id;
public:
Type (std::string id);
Type (const Type & type);
Type & operator= (const Type & type);
friend bool operator==(const Command& cmd, const CommandDef& def);
friend bool operator==(const CommandDef& def, const Command& cmd);
};
class Arg
{
private:
std::unique_ptr<Type> type;
std::string value;
public:
Arg(const Type& type, std::string value);
std::string getVal() { return value; }
Type getType() { return *type; }
};
//// namespace functions ////
bool operator==(const Command& cmd, const CommandDef& def);
bool operator==(const CommandDef& def, const Command& cmd);
}} // namespace
#endif // SRE_COMMAND_HPP