Skip to content
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

MSVC support #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
################################################################
Empty file added CMakeLists.txt
Empty file.
27 changes: 20 additions & 7 deletions 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