-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandMap.h
More file actions
40 lines (34 loc) · 1.25 KB
/
Copy pathCommandMap.h
File metadata and controls
40 lines (34 loc) · 1.25 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
//
// Created by roy on 12/18/18.
//
#ifndef PROJECTPART1_COMMANDMAP_H
#define PROJECTPART1_COMMANDMAP_H
#include <string>
#include <unordered_map>
using namespace std;
// enum for valid commands.
enum Commands {InValid, OpenDataServer, Connect, Var, Bind, Equal, While, If, Print, Sleep};
class CommandMap {
// initialize the map of the commands.
unordered_map<string,Commands> commands = {{"openDataServer" ,OpenDataServer}, {"connect" ,Connect},
{"var" ,Var}, {"bind" ,Bind}, {"=" ,Equal}, {"while" ,While},
{"sleep" ,Sleep}, {"if" ,If}, {"print" ,Print}};
public:
/**
* This function checks if a given command string is valid in
* command map, and returns the fitting command.
* @param commandString given string to search in map.
* @return command of the given string.
*/
Commands getCommand(string const commandString) const {
// if the key was not found in map, returns invalid command.
if (commands.find(commandString) == commands.end()) {
return InValid;
}
// else, returns the fitting command.
else {
return commands.at(commandString);
}
}
};
#endif //PROJECTPART1_COMMANDMAP_H