Coverage report for gui


src/
File: src/parser/Parser.hpp
Date: 2024-06-25 10:57:02
Lines:
4/4
100.0%
Functions:
4/4
100.0%
Branches:
28/58
48.3%

Line Branch Exec Source
1 #ifndef PARSER_HPP
2 #define PARSER_HPP
3
4 #include <functional>
5 #include <variant>
6 #include <vector>
7 #include <string>
8 #include <queue>
9
10 #include "Data.hpp"
11 #include "ServerConnect.hpp"
12
13 class Parser
14 {
15 private:
16 enum class Type
17 {
18 INT,
19 STRING
20 };
21
22 using TokenType = std::variant<std::string, int>;
23 using Handler = std::function<void(const std::vector<TokenType>&, Data&, ServerConnect&)>;
24
25 std::queue<std::function<void()>> _queue;
26
27 void msz(const std::vector<TokenType>& values, Data& gameData, ServerConnect &server);
28 void bct(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
29 void tna(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
30 void pnw(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
31 void ppo(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
32 void plv(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
33 void pin(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
34 void pex(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
35 void pbc(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
36 void pic(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
37 void pie(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
38 void pfk(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
39 void pdr(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
40 void pgt(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
41 void pdi(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
42 void enw(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
43 void ebo(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
44 void edi(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
45 void sst(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
46 void sgt(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
47 void seg(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
48 void smg(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
49 void suc(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
50 void sbp(const std::vector<TokenType>& tokens, Data& gameData, ServerConnect &server);
51
52
53 std::map<std::string, Handler> handlers = {
54 {"msz", std::bind(&Parser::msz, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
55 {"bct", std::bind(&Parser::bct, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
56 {"tna", std::bind(&Parser::tna, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
57 {"pnw", std::bind(&Parser::pnw, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
58 {"ppo", std::bind(&Parser::ppo, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
59 {"plv", std::bind(&Parser::plv, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
60 {"pin", std::bind(&Parser::pin, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
61 {"pex", std::bind(&Parser::pex, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
62 {"pbc", std::bind(&Parser::pbc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
63 {"pic", std::bind(&Parser::pic, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
64 {"pie", std::bind(&Parser::pie, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
65 {"pfk", std::bind(&Parser::pfk, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
66 {"pdr", std::bind(&Parser::pdr, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
67 {"pgt", std::bind(&Parser::pgt, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
68 {"pdi", std::bind(&Parser::pdi, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
69 {"enw", std::bind(&Parser::enw, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
70 {"ebo", std::bind(&Parser::ebo, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
71 {"edi", std::bind(&Parser::edi, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
72 {"sst", std::bind(&Parser::sst, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
73 {"sgt", std::bind(&Parser::sgt, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
74 {"seg", std::bind(&Parser::seg, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
75 {"smg", std::bind(&Parser::smg, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
76 {"suc", std::bind(&Parser::suc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)},
77 {"sbp", std::bind(&Parser::sbp, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}
78 };
79
80 public:
81
27/56
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 69 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 69 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 69 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 69 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 69 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 69 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 69 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 69 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 69 times.
✗ Branch 33 not taken.
✓ Branch 35 taken 69 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 69 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 69 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 69 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 69 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 69 times.
✗ Branch 51 not taken.
✓ Branch 53 taken 69 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 69 times.
✗ Branch 57 not taken.
✓ Branch 59 taken 69 times.
✗ Branch 60 not taken.
✓ Branch 62 taken 69 times.
✗ Branch 63 not taken.
✓ Branch 65 taken 69 times.
✗ Branch 66 not taken.
✓ Branch 68 taken 69 times.
✗ Branch 69 not taken.
✓ Branch 71 taken 69 times.
✗ Branch 72 not taken.
✗ Branch 74 not taken.
✓ Branch 75 taken 69 times.
✓ Branch 76 taken 1656 times.
✓ Branch 77 taken 69 times.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
1725 Parser() = default;
82 66 ~Parser() = default;
83
84 class ParserException : public std::exception
85 {
86 public:
87
1/2
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
46 ParserException(const std::string& message) : _message(message) {};
88 1 const char* what() const noexcept override { return _message.c_str(); };
89 private:
90 std::string _message;
91 };
92
93 void parse(std::vector<TokenType> values, Data& gameData, ServerConnect &server);
94
95 void execute();
96
97 void updateData(Data& gameData, ServerConnect &server);
98
99 void checkType(const std::vector<TokenType>& tokens, const std::vector<Type>& expectedTypes, const std::string& name);
100 };
101
102 #endif // PARSER_HPP
103