-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommandParser.h
60 lines (50 loc) · 1.11 KB
/
CommandParser.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
#pragma once
#include "Command.h"
#include <vector>
namespace nlohmann
{
class node;
}
namespace Commands
{
/*
Valid JSON command format:
{
"Commands": [
{
"type": "Speed rise",
"value": "15",
},
{
"type": "Speed reduction",
"value": "10",
"timeToProceed": ""
},
{
"type": "fuel drop",
"value": "",
"timeToProceed": ""
}]
}
Since we translate "type" to real command type, it is very
important that ie. "Speed rise" stay as const string.
If changed, it needs to be fixed in lookUp. Can be found in source, as:
std::map< std::string, Commands::Type> lookUp
{
{ "Speed rise", Commands::Type::speedRise },
{ "Speed reduction", Commands::Type::speedDown },
{ "fuel drop", Commands::Type::fuelState },
};
timeToProceed is optional.
*/
class CommandParser
{
public:
std::vector<Command> fromJason(std::string jasonAsString);
private:
Command fromJason(const nlohmann::json& node);
Type type(const nlohmann::json& node);
int value(const nlohmann::json& node);
int timeToProceed(const nlohmann::json& node);
};
}