-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGNUPlot.cpp
76 lines (63 loc) · 988 Bytes
/
GNUPlot.cpp
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
70
71
72
73
74
75
76
/**
* GNUPlot.cpp
*/
#ifndef GNUPLOT_CPP
#define GNUPLOT_CPP
#include "GNUPlot.h"
GNUPlot::GNUPlot() : _pipe(nullptr)
{
}
GNUPlot::~GNUPlot()
{
close();
}
void GNUPlot::open()
{
close();
_pipe = popen("gnuplot", "w");
}
bool GNUPlot::isOpened() const
{
return _pipe != nullptr;
}
void GNUPlot::flush()
{
if (isOpened())
{
fflush(_pipe);
}
}
void GNUPlot::close()
{
if (isOpened())
{
pclose(_pipe);
_pipe = nullptr;
}
}
void GNUPlot::write(const char *line)
{
if (isOpened() && line != nullptr && line[0] != '\0')
{
fprintf(_pipe, "%s\n", line);
}
}
void GNUPlot::write(const std::string &line)
{
if (!line.empty())
{
write(line.c_str());
}
}
void GNUPlot::execute(const std::vector<std::string> &script)
{
if (isOpened())
{
for (size_t i = 0; i < script.size(); ++i)
{
write(script[i]);
flush();
}
}
}
#endif