-
Notifications
You must be signed in to change notification settings - Fork 3
/
gnuplot.h
45 lines (37 loc) · 836 Bytes
/
gnuplot.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
#pragma once
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
class gnuplot
{
public:
virtual ~gnuplot() {
close();
}
bool is_opened() const { return m_pipe != nullptr; }
void open() {
close();
m_pipe = gp_popen("gnuplot", "w");
}
void close() {
if (is_opened()) {
gp_pclose(m_pipe);
m_pipe = nullptr;
}
}
void command(const std::string &cmd) {
if (is_opened() && !cmd.empty()) {
fprintf(m_pipe, "%s\n", cmd.c_str());
fflush(m_pipe);
}
}
private:
FILE* m_pipe = nullptr;
static FILE* gp_popen(const char *command, const char *mode) {
return _popen(command, mode);
}
static int gp_pclose(FILE *pipe) {
return _pclose(pipe);
}
};