diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bbbea4e --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ + +################################################################ +# Default GitHub's CMake gitignore +################################################################ + +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +################################################################ +# Additional Gitignores +################################################################ + +################################ +# Visual Studio +################################ + +# default VS stuff folder +.vs/ + +# default VS output folder +out/ + +################################################################ +# Git added +################################################################ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/include/gnuplot.h b/include/gnuplot.h index cb6cfa4..c7b6f54 100644 --- a/include/gnuplot.h +++ b/include/gnuplot.h @@ -24,28 +24,37 @@ #include #include +#if defined(_MSC_VER) || defined(_WIN32) +#include +#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); @@ -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(); @@ -71,3 +80,7 @@ class GnuplotPipe { FILE* pipe; std::vector buffer; }; + + +#undef _MR_GPCPP_POPEN +#undef _MR_GPCPP_PCLOSE \ No newline at end of file