Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MSVC support #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
Loading
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions 27 include/gnuplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,37 @@
#include <iostream>
#include <fstream>

#if defined(_MSC_VER) || defined(_WIN32)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to gnuplot-iostream

#include <windows.h>
#define _MR_GPCPP_POPEN _popen
#define _MR_GPCPP_PCLOSE _pclose
#else
#define _MR_GPCPP_POPEN popen
#define _MR_GPCPP_PCLOSE pclose
#endif

class GnuplotPipe {
public:
inline GnuplotPipe(bool persist = true) {
std::cout << "Opening gnuplot... ";
pipe = popen(persist ? "gnuplot -persist" : "gnuplot", "w");
pipe = _MR_GPCPP_POPEN(persist ? "gnuplot -persist" : "gnuplot", "w");
if (!pipe)
std::cout << "failed!" << std::endl;
else
std::cout << "succeded." << std::endl;
}
inline virtual ~GnuplotPipe(){
if (pipe) pclose(pipe);
inline virtual ~GnuplotPipe() {
if (pipe) _MR_GPCPP_PCLOSE(pipe);
}

void sendLine(const std::string& text, bool useBuffer = false){
void sendLine(const std::string& text, bool useBuffer = false) {
if (!pipe) return;
if (useBuffer)
buffer.push_back(text + "\n");
else
fputs((text + "\n").c_str(), pipe);
}
void sendEndOfData(unsigned repeatBuffer = 1){
void sendEndOfData(unsigned repeatBuffer = 1) {
if (!pipe) return;
for (unsigned i = 0; i < repeatBuffer; i++) {
for (auto& line : buffer) fputs(line.c_str(), pipe);
Expand All @@ -54,11 +63,11 @@ class GnuplotPipe {
fflush(pipe);
buffer.clear();
}
void sendNewDataBlock(){
void sendNewDataBlock() {
sendLine("\n", !buffer.empty());
}

void writeBufferToFile(const std::string& fileName){
void writeBufferToFile(const std::string& fileName) {
std::ofstream fileOut(fileName);
for (auto& line : buffer) fileOut << line;
fileOut.close();
Expand All @@ -71,3 +80,7 @@ class GnuplotPipe {
FILE* pipe;
std::vector<std::string> buffer;
};


#undef _MR_GPCPP_POPEN
#undef _MR_GPCPP_PCLOSE
Morty Proxy This is a proxified and sanitized view of the page, visit original site.