-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgtpclient.h
70 lines (48 loc) · 1.54 KB
/
gtpclient.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
#ifndef GTPCLIENT_H
#define GTPCLIENT_H
#include <boost/process.hpp>
#include <boost/filesystem/path.hpp>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <spdlog/spdlog.h>
#include "InputThread.h"
#include <regex>
#include <nlohmann/json.hpp>
struct OutputFilter {
std::string regex;
std::string output;
std::string var;
std::regex compiled;
};
void replaceAll(std::string& out, const std::string& what, const std::string& by);
class GtpClient {
private:
boost::process::opstream pis;
boost::process::ipstream pes;
boost::process::ipstream pos;
boost::process::child c;
std::string exe;
std::string lastLine;
std::vector<OutputFilter> outputFilters;
InputThread<GtpClient, boost::process::ipstream> *reader;
nlohmann::json vars;
public:
typedef std::vector<std::string> CommandOutput;
GtpClient(const std::string& exe, const std::string& cmdline,
const std::string& path, const nlohmann::json& messages);
~GtpClient();
void interpolate(std::string& out);
void operator()(const std::string& line);
void initFilters(const nlohmann::json& messages);
void compileFilters();
void addOutputFilter(const std::string& msg, const std::string& format, const std::string& var);
std::string lastError();
CommandOutput showboard();
CommandOutput name();
CommandOutput version();
CommandOutput issueCommand(const std::string& command);
static bool success(const CommandOutput& ret);
};
#endif // GTPCLIENT_H