37 #ifndef GNUPLOT_IOSTREAM_H 38 #define GNUPLOT_IOSTREAM_H 42 #define GNUPLOT_IOSTREAM_VERSION 2 44 #ifndef GNUPLOT_ENABLE_CXX11 45 # define GNUPLOT_ENABLE_CXX11 (__cplusplus >= 201103) 50 #ifdef GNUPLOT_ENABLE_PTY 58 #endif // GNUPLOT_ENABLE_PTY 73 #if GNUPLOT_ENABLE_CXX11 77 #include <boost/iostreams/device/file_descriptor.hpp> 78 #include <boost/iostreams/stream.hpp> 79 #include <boost/version.hpp> 80 #include <boost/utility.hpp> 81 #include <boost/tuple/tuple.hpp> 82 #include <boost/mpl/bool.hpp> 84 #if BOOST_VERSION >= 104600 85 # define GNUPLOT_USE_TMPFILE 86 # include <boost/filesystem.hpp> 87 #endif // BOOST_VERSION 90 #include <boost/cstdint.hpp> 95 #ifdef GNUPLOT_ENABLE_BLITZ 96 # include <blitz/array.h> 99 #ifdef BOOST_STATIC_ASSERT_MSG 100 # define GNUPLOT_STATIC_ASSERT_MSG(cond, msg) BOOST_STATIC_ASSERT_MSG((cond), msg) 102 # define GNUPLOT_STATIC_ASSERT_MSG(cond, msg) BOOST_STATIC_ASSERT((cond)) 106 #ifdef GNUPLOT_DEPRECATE_WARN 108 # define GNUPLOT_DEPRECATE(msg) __attribute__ ((deprecated(msg))) 109 # elif defined(_MSC_VER) 110 # define GNUPLOT_DEPRECATE(msg) __declspec(deprecated(msg)) 112 # define GNUPLOT_DEPRECATE(msg) 115 # define GNUPLOT_DEPRECATE(msg) 120 # include <windows.h> 121 # define GNUPLOT_PCLOSE _pclose 122 # define GNUPLOT_POPEN _popen 123 # define GNUPLOT_FILENO _fileno 125 # define GNUPLOT_PCLOSE pclose 126 # define GNUPLOT_POPEN popen 127 # define GNUPLOT_FILENO fileno 131 # define GNUPLOT_ISNAN _isnan 135 # define GNUPLOT_ISNAN std::isnan 142 #if defined(_MSC_VER) && _MSC_VER >= 1400 143 # define GNUPLOT_MSVC_WARNING_4996_PUSH \ 144 __pragma(warning(push)) \ 145 __pragma(warning(disable:4996)) 146 # define GNUPLOT_MSVC_WARNING_4996_POP \ 147 __pragma(warning(pop)) 149 # define GNUPLOT_MSVC_WARNING_4996_PUSH 150 # define GNUPLOT_MSVC_WARNING_4996_POP 153 #ifndef GNUPLOT_DEFAULT_COMMAND 160 # define GNUPLOT_DEFAULT_COMMAND "gnuplot -persist 2> NUL" 162 # define GNUPLOT_DEFAULT_COMMAND "gnuplot -persist" 177 template <
typename T>
179 typedef boost::mpl::bool_<false>
type;
182 BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
183 BOOST_MPL_HAS_XXX_TRAIT_DEF(const_iterator)
185 template <typename T>
187 typedef boost::mpl::and_<
188 typename has_value_type<T>::type,
189 typename has_const_iterator<T>::type,
190 boost::mpl::not_<dont_treat_as_stl_container<T> >
192 static const bool value = type::value;
195 template <
typename T>
197 static const bool value =
false;
198 typedef boost::mpl::bool_<value>
type;
203 static const bool value =
true;
204 typedef boost::mpl::bool_<value>
type;
207 BOOST_MPL_HAS_XXX_TRAIT_DEF(head_type)
208 BOOST_MPL_HAS_XXX_TRAIT_DEF(tail_type)
210 template <typename T>
212 typedef boost::mpl::and_<
213 typename has_head_type<T>::type,
214 typename has_tail_type<T>::type
216 static const bool value = type::value;
245 #ifdef GNUPLOT_USE_TMPFILE 247 class GnuplotTmpfile {
250 file(boost::filesystem::unique_path(
251 boost::filesystem::temp_directory_path() /
252 "tmp-gnuplot-%%%%-%%%%-%%%%-%%%%"))
257 GnuplotTmpfile(
const GnuplotTmpfile &);
258 const GnuplotTmpfile& operator=(
const GnuplotTmpfile &);
265 }
catch(
const std::exception &) {
266 std::cerr <<
"Failed to remove temporary file " << file << std::endl;
271 boost::filesystem::path file;
273 #endif // GNUPLOT_USE_TMPFILE 292 virtual std::string
filename()
const = 0;
293 virtual FILE *handle()
const = 0;
301 #ifdef GNUPLOT_ENABLE_PTY 302 #define GNUPLOT_ENABLE_FEEDBACK 305 explicit GnuplotFeedbackPty(
bool debug_messages) :
312 if(0 > openpty(&master_fd, &slave_fd, NULL, NULL, NULL)) {
314 throw std::runtime_error(
"openpty failed");
316 char pty_fn_buf[1024];
317 if(ttyname_r(slave_fd, pty_fn_buf, 1024)) {
319 throw std::runtime_error(
"ttyname failed");
321 pty_fn = std::string(pty_fn_buf);
323 std::cerr <<
"feedback_fn=" << pty_fn << std::endl;
328 if(tcgetattr(slave_fd, &tios) < 0) {
330 throw std::runtime_error(
"tcgetattr failed");
332 tios.c_lflag &= ~(ECHO | ECHONL);
333 if(tcsetattr(slave_fd, TCSAFLUSH, &tios) < 0) {
335 throw std::runtime_error(
"tcsetattr failed");
338 pty_fh = fdopen(master_fd,
"r");
340 throw std::runtime_error(
"fdopen failed");
346 GnuplotFeedbackPty(
const GnuplotFeedbackPty &);
347 const GnuplotFeedbackPty& operator=(
const GnuplotFeedbackPty &);
350 ~GnuplotFeedbackPty() {
351 if(pty_fh) fclose(pty_fh);
352 if(master_fd > 0) ::close(master_fd);
353 if(slave_fd > 0) ::close(slave_fd);
360 FILE *handle()
const {
367 int master_fd, slave_fd;
408 #endif // GNUPLOT_ENABLE_PTY, GNUPLOT_USE_TMPFILE 430 template <
typename T,
typename Enable=
void>
432 static void send(std::ostream &stream,
const T &v) {
438 template <
typename T,
typename Enable=
void>
443 static void send(std::ostream &stream,
const T &v);
448 template <
typename T>
450 static void send(std::ostream &stream,
const T &v) {
451 stream.write(reinterpret_cast<const char *>(&v),
sizeof(T));
456 template <
typename T,
typename Enable=
void>
461 static void send(std::ostream &);
466 template<>
struct BinfmtSender< float> {
static void send(std::ostream &stream) { stream <<
"%float"; } };
467 template<>
struct BinfmtSender<double> {
static void send(std::ostream &stream) { stream <<
"%double"; } };
471 template<>
struct BinfmtSender<
boost::uint16_t> {
static void send(std::ostream &stream) { stream <<
"%uint16"; } };
473 template<>
struct BinfmtSender<
boost::uint32_t> {
static void send(std::ostream &stream) { stream <<
"%uint32"; } };
475 template<>
struct BinfmtSender<
boost::uint64_t> {
static void send(std::ostream &stream) { stream <<
"%uint64"; } };
491 template <
typename T>
493 static void send(std::ostream &stream,
const T &v) {
502 template <
typename T>
504 static void send(std::ostream &stream,
const T &v) {
505 if(
GNUPLOT_ISNAN(v)) { stream <<
"nan"; }
else { stream << v; }
516 template <
typename T,
typename U>
518 static void send(std::ostream &stream,
const std::pair<T, U> &v) {
525 template <
typename T,
typename U>
527 static void send(std::ostream &stream) {
533 template <
typename T,
typename U>
535 static void send(std::ostream &stream,
const std::pair<T, U> &v) {
545 template <
typename T>
547 static void send(std::ostream &stream,
const std::complex<T> &v) {
554 template <
typename T>
556 static void send(std::ostream &stream) {
562 template <
typename T>
564 static void send(std::ostream &stream,
const std::complex<T> &v) {
574 template <
typename T>
576 typename boost::enable_if<
579 boost::mpl::not_<is_boost_tuple_nulltype<typename T::tail_type> >
583 static void send(std::ostream &stream,
const T &v) {
590 template <
typename T>
592 typename boost::enable_if<
595 is_boost_tuple_nulltype<typename T::tail_type>
599 static void send(std::ostream &stream,
const T &v) {
604 template <
typename T>
606 typename boost::enable_if<
609 boost::mpl::not_<is_boost_tuple_nulltype<typename T::tail_type> >
613 static void send(std::ostream &stream) {
620 template <
typename T>
622 typename boost::enable_if<
625 is_boost_tuple_nulltype<typename T::tail_type>
629 static void send(std::ostream &stream) {
634 template <
typename T>
636 typename boost::enable_if<
639 boost::mpl::not_<is_boost_tuple_nulltype<typename T::tail_type> >
643 static void send(std::ostream &stream,
const T &v) {
649 template <
typename T>
651 typename boost::enable_if<
654 is_boost_tuple_nulltype<typename T::tail_type>
658 static void send(std::ostream &stream,
const T &v) {
667 #if GNUPLOT_ENABLE_CXX11 671 template<std::
size_t>
struct int_{};
673 template <
typename Tuple, std::
size_t I>
674 void std_tuple_formatcode_helper(std::ostream &stream,
const Tuple *, int_<I>) {
675 std_tuple_formatcode_helper(stream, (
const Tuple *)(0), int_<I-1>());
680 template <
typename Tuple>
681 void std_tuple_formatcode_helper(std::ostream &stream,
const Tuple *, int_<0>) {
685 template <
typename... Args>
687 typedef typename std::tuple<Args...> Tuple;
689 static void send(std::ostream &stream) {
690 std_tuple_formatcode_helper(stream, (
const Tuple *)(0), int_<
sizeof...(Args)-1>());
694 template <
typename Tuple, std::
size_t I>
695 void std_tuple_textsend_helper(std::ostream &stream,
const Tuple &v, int_<I>) {
696 std_tuple_textsend_helper(stream, v, int_<I-1>());
701 template <
typename Tuple>
702 void std_tuple_textsend_helper(std::ostream &stream,
const Tuple &v, int_<0>) {
706 template <
typename... Args>
708 typedef typename std::tuple<Args...> Tuple;
710 static void send(std::ostream &stream,
const Tuple &v) {
711 std_tuple_textsend_helper(stream, v, int_<
sizeof...(Args)-1>());
715 template <
typename Tuple, std::
size_t I>
716 void std_tuple_binsend_helper(std::ostream &stream,
const Tuple &v, int_<I>) {
717 std_tuple_binsend_helper(stream, v, int_<I-1>());
721 template <
typename Tuple>
722 void std_tuple_binsend_helper(std::ostream &stream,
const Tuple &v, int_<0>) {
726 template <
typename... Args>
728 typedef typename std::tuple<Args...> Tuple;
730 static void send(std::ostream &stream,
const Tuple &v) {
731 std_tuple_binsend_helper(stream, v, int_<
sizeof...(Args)-1>());
735 #endif // GNUPLOT_ENABLE_CXX11 804 template <
typename T,
typename Enable=
void>
812 static const bool is_container =
false;
817 static const bool allow_auto_unwrap =
false;
819 static const size_t depth = 0;
824 throw std::logic_error(
"static assert should have been triggered by this point");
830 template <
typename V>
835 static const bool is_container =
true;
836 static const bool allow_auto_unwrap =
true;
843 template <
typename T>
848 #if GNUPLOT_ENABLE_CXX11 849 template <
typename T>
857 template <
typename TI,
typename TV>
864 typedef typename boost::mpl::if_c<is_container,
868 bool is_end()
const {
return it == end; }
874 "deref called on nested container");
876 throw std::runtime_error(
"attepted to dereference past end of iterator");
883 "deref_subiter called on non-nested container");
885 throw std::runtime_error(
"attepted to dereference past end of iterator");
894 template <
typename T>
896 typename boost::enable_if<is_like_stl_container<T> >
::type 902 return range_type(arg.begin(), arg.end());
910 template <
typename T,
size_t N>
916 return range_type(arg, arg+N);
924 template <
typename RT,
typename RU>
926 template <
typename T,
typename U,
typename Pr
intMode>
933 static const bool is_container = RT::is_container && RU::is_container;
935 typedef std::pair<typename RT::value_type, typename RU::value_type>
value_type;
939 bool el = l.is_end();
940 bool er = r.is_end();
942 throw std::length_error(
"columns were different lengths");
953 return std::make_pair(l.deref(), r.deref());
957 return subiter_type(l.deref_subiter(), r.deref_subiter());
965 template <
typename T,
typename U>
972 static const bool allow_auto_unwrap =
false;
977 static const size_t depth = (l_depth < r_depth) ? l_depth : r_depth;
979 static range_type
get_range(
const std::pair<T, U> &arg) {
991 template <
typename T>
993 typename boost::enable_if<
996 boost::mpl::not_<is_boost_tuple_nulltype<typename T::tail_type> >
1001 typename T::head_type,
1002 typename T::tail_type
1006 typedef typename T::head_type
HT;
1007 typedef typename T::tail_type
TT;
1019 template <
typename T>
1021 typename boost::enable_if<
1024 is_boost_tuple_nulltype<typename T::tail_type>
1028 typename T::head_type
1030 typedef typename T::head_type
HT;
1036 return parent::get_range(arg.get_head());
1044 #if GNUPLOT_ENABLE_CXX11 1046 template <
typename Tuple,
size_t idx>
1047 struct StdTupUnwinder {
1049 typename StdTupUnwinder<Tuple, idx-1>
::type,
1050 typename std::tuple_element<idx, Tuple>::type
1055 StdTupUnwinder<Tuple, idx-1>::get_range(arg),
1056 ArrayTraits<
typename std::tuple_element<idx, Tuple>::type>::get_range(std::get<idx>(arg))
1061 template <
typename Tuple>
1062 struct StdTupUnwinder<Tuple, 0> {
1063 typedef typename std::tuple_element<0, Tuple>::type
type;
1070 template <
typename... Args>
1072 public ArrayTraits<typename StdTupUnwinder<std::tuple<Args...>, sizeof...(Args)-1>::type>
1074 typedef std::tuple<Args...> Tuple;
1079 return StdTupUnwinder<std::tuple<Args...>,
sizeof...(Args)-1>::get_range(arg);
1083 #endif // GNUPLOT_ENABLE_CXX11 1093 template <
typename RT>
1095 template <
typename T,
typename Pr
intMode>
1100 explicit VecOfRange(
const std::vector<RT> &_rvec) : rvec(_rvec) { }
1102 static const bool is_container = RT::is_container;
1104 static const bool allow_auto_unwrap =
false;
1110 if(rvec.empty())
return true;
1111 bool ret = rvec[0].is_end();
1112 for(
size_t i=1; i<rvec.size(); i++) {
1113 if(ret != rvec[i].is_end()) {
1114 throw std::length_error(
"columns were different lengths");
1121 for(
size_t i=0; i<rvec.size(); i++) {
1127 value_type ret(rvec.size());
1128 for(
size_t i=0; i<rvec.size(); i++) {
1129 ret[i] = rvec[i].deref();
1135 std::vector<typename RT::subiter_type> subvec(rvec.size());
1136 for(
size_t i=0; i<rvec.size(); i++) {
1139 return subiter_type(subvec);
1146 template <
typename T>
1150 std::vector<U> rvec;
1152 while(!outer.is_end()) {
1153 rvec.push_back(outer.deref_subiter());
1193 struct ModeText {
static const bool is_text = 1;
static const bool is_binfmt = 0;
static const bool is_size = 0; };
1194 struct ModeBinary {
static const bool is_text = 0;
static const bool is_binfmt = 0;
static const bool is_size = 0; };
1195 struct ModeBinfmt {
static const bool is_text = 0;
static const bool is_binfmt = 1;
static const bool is_size = 0; };
1196 struct ModeSize {
static const bool is_text = 0;
static const bool is_binfmt = 0;
static const bool is_size = 1; };
1221 template <
typename T,
typename Enable=
void>
1224 template <
typename T>
1226 typename boost::enable_if_c<
1227 (ArrayTraits<T>::depth == 1)
1233 template <
typename T>
1235 typename boost::enable_if_c<
1236 (ArrayTraits<T>::depth == 2) &&
1237 !ArrayTraits<T>::allow_auto_unwrap
1243 template <
typename T>
1245 typename boost::enable_if_c<
1246 (ArrayTraits<T>::depth == 2) &&
1247 ArrayTraits<T>::allow_auto_unwrap
1253 template <
typename T>
1255 typename boost::enable_if_c<
1256 (ArrayTraits<T>::depth > 2) &&
1263 template <
typename T>
1265 typename boost::enable_if_c<
1266 (ArrayTraits<T>::depth > 2) &&
1289 template <
typename T>
1294 template <
typename T>
1299 template <
typename T>
1313 template <
typename T,
typename Pr
intMode>
1314 typename boost::disable_if_c<T::is_container>::type
1316 const typename T::value_type &v = arg.deref();
1323 template <
typename T,
typename Pr
intMode>
1324 typename boost::enable_if_c<T::is_container>::type
1327 typename T::subiter_type subrange = arg.deref_subiter();
1329 if(debug_array_print && PrintMode::is_text) stream <<
"{";
1331 while(!subrange.is_end()) {
1332 if(!first && PrintMode::is_text) stream <<
" ";
1337 if(debug_array_print && PrintMode::is_text) stream <<
"}";
1341 template <
typename T,
typename U,
typename Pr
intMode>
1344 if(PrintMode::is_text) stream <<
" ";
1349 template <
typename T,
typename Pr
intMode>
1352 for(
size_t i=0; i<arg.
rvec.size(); i++) {
1353 if(i && PrintMode::is_text) stream <<
" ";
1377 template <
size_t Depth,
typename T,
typename Pr
intMode>
1378 typename boost::enable_if_c<(Depth==1) && !PrintMode::is_size>::type
1381 for(; !arg.is_end(); arg.inc()) {
1386 if(PrintMode::is_binfmt)
break;
1387 if(PrintMode::is_text) stream << std::endl;
1393 template <
size_t Depth,
typename T,
typename Pr
intMode>
1394 typename boost::enable_if_c<(Depth>1) && !PrintMode::is_size>::
type 1398 for(; !arg.is_end(); arg.inc()) {
1402 if(PrintMode::is_text) stream << std::endl;
1404 if(debug_array_print && PrintMode::is_text) stream <<
"<block>" << std::endl;
1406 typename T::subiter_type sub = arg.deref_subiter();
1410 if(PrintMode::is_binfmt)
break;
1415 template <
typename T>
1419 for(T i=arg; !i.is_end(); i.inc()) ++ret;
1424 template <
size_t Depth,
typename T,
typename Pr
intMode>
1425 typename boost::enable_if_c<(Depth==1) && PrintMode::is_size>::type
1431 template <
size_t Depth,
typename T,
typename Pr
intMode>
1432 typename boost::enable_if_c<(Depth>1) && PrintMode::is_size>::
type 1437 typename T::subiter_type sub = arg.deref_subiter();
1450 template <
size_t Depth,
typename T,
typename Pr
intMode>
1454 print_block<Depth>(stream, range, PrintMode());
1457 template <
size_t Depth,
typename T,
typename Pr
intMode>
1461 print_block<Depth>(stream, cols, PrintMode());
1473 template <
typename T,
typename Pr
intMode>
1475 handle_colunwrap_tag<1>(stream, arg,
ColUnwrapNo(), PrintMode());
1478 template <
typename T,
typename Pr
intMode>
1480 handle_colunwrap_tag<2>(stream, arg,
ColUnwrapNo(), PrintMode());
1483 template <
typename T,
typename Pr
intMode>
1485 handle_colunwrap_tag<1>(stream, arg,
ColUnwrapYes(), PrintMode());
1488 template <
typename T,
typename Pr
intMode>
1490 handle_colunwrap_tag<2>(stream, arg,
ColUnwrapYes(), PrintMode());
1493 template <
typename T,
typename Pr
intMode>
1506 template <
typename T,
typename OrganizationMode,
typename Pr
intMode>
1523 wrapped_fh(_fh), should_use_pclose(_should_use_pclose) { }
1526 if(should_use_pclose) {
1528 std::cerr <<
"pclose returned error" << std::endl;
1531 if(fclose(wrapped_fh)) {
1532 std::cerr <<
"fclose returned error" << std::endl;
1554 public boost::iostreams::stream<boost::iostreams::file_descriptor_sink>
1559 char *from_env = std::getenv(
"GNUPLOT_IOSTREAM_CMD");
1561 if(from_env && from_env[0]) {
1569 std::string cmd = in.empty() ? get_default_cmd() : in;
1570 assert(!cmd.empty());
1572 std::string fn = cmd.substr(1);
1574 FILE *fh = std::fopen(fn.c_str(),
"w");
1576 if(!fh)
throw(std::ios_base::failure(
"cannot open file "+fn));
1580 if(!fh)
throw(std::ios_base::failure(
"cannot open pipe "+cmd));
1588 boost::iostreams::stream<boost::iostreams::file_descriptor_sink>(
1590 #if BOOST_VERSION >= 104400
1591 boost::iostreams::never_close_handle
1598 debug_messages(false)
1600 *
this << std::scientific << std::setprecision(18);
1605 boost::iostreams::stream<boost::iostreams::file_descriptor_sink>(
1607 #if BOOST_VERSION >= 104400
1608 boost::iostreams::never_close_handle
1615 debug_messages(false)
1617 *
this << std::scientific << std::setprecision(18);
1627 if(debug_messages) {
1628 std::cerr <<
"ending gnuplot session" << std::endl;
1650 *
this << std::flush;
1655 #ifdef GNUPLOT_USE_TMPFILE 1659 tmp_files.push_back(tmp_file);
1660 return tmp_file->file.string();
1662 throw(std::logic_error(
"no filename given and temporary files not enabled"));
1663 #endif // GNUPLOT_USE_TMPFILE 1673 template <
typename T,
typename OrganizationMode>
1676 *
this <<
"e" << std::endl;
1681 template <
typename T,
typename OrganizationMode>
1688 template <
typename T,
typename OrganizationMode>
1689 std::string
binfmt(
const T &arg,
const std::string &arr_or_rec, OrganizationMode) {
1690 assert((arr_or_rec ==
"array") || (arr_or_rec ==
"record"));
1693 std::ostringstream tmp;
1696 tmp <<
"' " << arr_or_rec <<
"=(";
1702 ret = std::string(
" format='' ") + arr_or_rec +
"=(0) ";
1708 template <
typename T,
typename OrganizationMode>
1709 std::string
file(
const T &arg, std::string filename, OrganizationMode) {
1710 if(filename.empty()) filename = make_tmpfile();
1711 std::fstream tmp_stream(filename.c_str(), std::fstream::out);
1715 std::ostringstream cmdline;
1717 cmdline <<
" '" << filename <<
"' ";
1718 return cmdline.str();
1722 template <
typename T,
typename OrganizationMode>
1723 std::string
binaryFile(
const T &arg, std::string filename,
const std::string &arr_or_rec, OrganizationMode) {
1724 if(filename.empty()) filename = make_tmpfile();
1725 std::fstream tmp_stream(filename.c_str(), std::fstream::out | std::fstream::binary);
1729 std::ostringstream cmdline;
1731 cmdline <<
" '" << filename <<
"' binary" << binfmt(arg, arr_or_rec, OrganizationMode());
1732 return cmdline.str();
1742 &send(
const T &arg) {
return send(arg,
ModeAuto()); }
1745 binfmt(const T &arg, const std::
string &arr_or_rec="array")
1746 {
return binfmt(arg, arr_or_rec,
ModeAuto()); }
1749 &sendBinary(
const T &arg) {
return sendBinary(arg,
ModeAuto()); }
1752 file(
const T &arg,
const std::string &
filename=
"")
1756 binaryFile(
const T &arg,
const std::string &
filename=
"",
const std::string &arr_or_rec=
"array")
1766 template <
typename T>
Gnuplot &send1d (
const T &arg) {
return send(arg,
Mode1D ()); }
1767 template <
typename T>
Gnuplot &send2d (
const T &arg) {
return send(arg,
Mode2D ()); }
1768 template <
typename T>
Gnuplot &send1d_colmajor(
const T &arg) {
return send(arg,
Mode1DUnwrap()); }
1769 template <
typename T>
Gnuplot &send2d_colmajor(
const T &arg) {
return send(arg,
Mode2DUnwrap()); }
1771 template <
typename T>
Gnuplot &sendBinary1d (
const T &arg) {
return sendBinary(arg,
Mode1D ()); }
1772 template <
typename T>
Gnuplot &sendBinary2d (
const T &arg) {
return sendBinary(arg,
Mode2D ()); }
1773 template <
typename T>
Gnuplot &sendBinary1d_colmajor(
const T &arg) {
return sendBinary(arg,
Mode1DUnwrap()); }
1774 template <
typename T>
Gnuplot &sendBinary2d_colmajor(
const T &arg) {
return sendBinary(arg,
Mode2DUnwrap()); }
1776 template <
typename T> std::string file1d (
const T &arg,
const std::string &
filename=
"") {
return file(arg,
filename,
Mode1D ()); }
1777 template <
typename T> std::string file2d (
const T &arg,
const std::string &
filename=
"") {
return file(arg,
filename,
Mode2D ()); }
1778 template <
typename T> std::string file1d_colmajor(
const T &arg,
const std::string &
filename=
"") {
return file(arg,
filename,
Mode1DUnwrap()); }
1779 template <
typename T> std::string file2d_colmajor(
const T &arg,
const std::string &
filename=
"") {
return file(arg,
filename,
Mode2DUnwrap()); }
1781 template <
typename T> std::string binFmt1d (
const T &arg,
const std::string &arr_or_rec) {
return binfmt(arg, arr_or_rec,
Mode1D ()); }
1782 template <
typename T> std::string binFmt2d (
const T &arg,
const std::string &arr_or_rec) {
return binfmt(arg, arr_or_rec,
Mode2D ()); }
1783 template <
typename T> std::string binFmt1d_colmajor(
const T &arg,
const std::string &arr_or_rec) {
return binfmt(arg, arr_or_rec,
Mode1DUnwrap()); }
1784 template <
typename T> std::string binFmt2d_colmajor(
const T &arg,
const std::string &arr_or_rec) {
return binfmt(arg, arr_or_rec,
Mode2DUnwrap()); }
1786 template <
typename T> std::string binFile1d (
const T &arg,
const std::string &arr_or_rec,
const std::string &
filename=
"") {
return binaryFile(arg,
filename, arr_or_rec,
Mode1D ()); }
1787 template <
typename T> std::string binFile2d (
const T &arg,
const std::string &arr_or_rec,
const std::string &
filename=
"") {
return binaryFile(arg,
filename, arr_or_rec,
Mode2D ()); }
1788 template <
typename T> std::string binFile1d_colmajor(
const T &arg,
const std::string &arr_or_rec,
const std::string &
filename=
"") {
return binaryFile(arg,
filename, arr_or_rec,
Mode1DUnwrap()); }
1789 template <
typename T> std::string binFile2d_colmajor(
const T &arg,
const std::string &arr_or_rec,
const std::string &
filename=
"") {
return binaryFile(arg,
filename, arr_or_rec,
Mode2DUnwrap()); }
1793 #ifdef GNUPLOT_ENABLE_FEEDBACK 1799 double &mx,
double &my,
int &mb,
1800 std::string msg=
"Click Mouse!" 1804 *
this <<
"set mouse" << std::endl;
1805 *
this <<
"pause mouse \"" << msg <<
"\\n\"" << std::endl;
1806 *
this <<
"if (exists(\"MOUSE_X\")) print MOUSE_X, MOUSE_Y, MOUSE_BUTTON; else print 0, 0, -1;" << std::endl;
1807 if(debug_messages) {
1808 std::cerr <<
"begin scanf" << std::endl;
1810 if(3 != fscanf(feedback->handle(),
"%50lf %50lf %50d", &mx, &my, &mb)) {
1811 throw std::runtime_error(
"could not parse reply");
1813 if(debug_messages) {
1814 std::cerr <<
"end scanf" << std::endl;
1819 void allocFeedback() {
1821 #ifdef GNUPLOT_ENABLE_PTY 1822 feedback =
new GnuplotFeedbackPty(debug_messages);
1831 *
this <<
"set print \"" << feedback->filename() <<
"\"" << std::endl;
1834 #endif // GNUPLOT_ENABLE_FEEDBACK 1838 #ifdef GNUPLOT_USE_TMPFILE 1839 std::vector<boost::shared_ptr<GnuplotTmpfile> > tmp_files;
1843 #endif // GNUPLOT_USE_TMPFILE 1857 #endif // GNUPLOT_IOSTREAM_H 1871 #ifndef GNUPLOT_BLITZ_SUPPORT_LOADED 1872 #define GNUPLOT_BLITZ_SUPPORT_LOADED 1875 template <
typename T,
int N>
1877 static void send(std::ostream &stream) {
1878 for(
int i=0; i<N; i++) {
1884 template <
typename T,
int N>
1885 struct TextSender<blitz::TinyVector<T, N> > {
1886 static void send(std::ostream &stream,
const blitz::TinyVector<T, N> &v) {
1887 for(
int i=0; i<N; i++) {
1888 if(i) stream <<
" ";
1894 template <
typename T,
int N>
1896 static void send(std::ostream &stream,
const blitz::TinyVector<T, N> &v) {
1897 for(
int i=0; i<N; i++) {
1903 class Error_WasBlitzPartialSlice { };
1905 template <
typename T,
int ArrayDim,
int SliceDim>
1906 class BlitzIterator {
1908 BlitzIterator() : p(NULL) { }
1910 const blitz::Array<T, ArrayDim> *_p,
1911 const blitz::TinyVector<int, ArrayDim> _idx
1912 ) : p(_p), idx(_idx) { }
1914 typedef Error_WasBlitzPartialSlice value_type;
1915 typedef BlitzIterator<T, ArrayDim, SliceDim-1> subiter_type;
1916 static const bool is_container =
true;
1919 bool is_end()
const {
1920 return idx[ArrayDim-SliceDim] == p->shape()[ArrayDim-SliceDim];
1924 ++idx[ArrayDim-SliceDim];
1927 value_type deref()
const {
1929 throw std::logic_error(
"static assert should have been triggered by this point");
1932 subiter_type deref_subiter()
const {
1933 return BlitzIterator<T, ArrayDim, SliceDim-1>(p, idx);
1937 const blitz::Array<T, ArrayDim> *p;
1938 blitz::TinyVector<int, ArrayDim> idx;
1941 template <
typename T,
int ArrayDim>
1942 class BlitzIterator<T, ArrayDim, 1> {
1944 BlitzIterator() : p(NULL) { }
1946 const blitz::Array<T, ArrayDim> *_p,
1947 const blitz::TinyVector<int, ArrayDim> _idx
1948 ) : p(_p), idx(_idx) { }
1950 typedef T value_type;
1952 static const bool is_container =
false;
1955 bool is_end()
const {
1956 return idx[ArrayDim-1] == p->shape()[ArrayDim-1];
1963 value_type deref()
const {
1967 subiter_type deref_subiter()
const {
1969 throw std::logic_error(
"static assert should have been triggered by this point");
1973 const blitz::Array<T, ArrayDim> *p;
1974 blitz::TinyVector<int, ArrayDim> idx;
1977 template <
typename T,
int ArrayDim>
1980 static const bool allow_auto_unwrap =
false;
1983 typedef BlitzIterator<T, ArrayDim, ArrayDim> range_type;
1985 static range_type get_range(
const blitz::Array<T, ArrayDim> &arg) {
1986 blitz::TinyVector<int, ArrayDim> start_idx;
1988 return range_type(&arg, start_idx);
1993 #endif // GNUPLOT_BLITZ_SUPPORT_LOADED 1994 #endif // BZ_BLITZ_H 2007 #ifdef ARMA_INCLUDES 2008 #ifndef GNUPLOT_ARMADILLO_SUPPORT_LOADED 2009 #define GNUPLOT_ARMADILLO_SUPPORT_LOADED 2020 template <
typename T>
2024 SliceRange() : p(NULL), col(0), slice(0) { }
2025 explicit SliceRange(
const arma::Cube<T> *_p,
size_t _row,
size_t _col) :
2026 p(_p), row(_row), col(_col), slice(0) { }
2028 typedef T value_type;
2030 static const bool is_container =
false;
2032 bool is_end()
const {
return slice == p->n_slices; }
2034 void inc() { ++slice; }
2036 value_type deref()
const {
2037 return (*p)(row, col, slice);
2040 subiter_type deref_subiter()
const {
2042 throw std::logic_error(
"static assert should have been triggered by this point");
2046 const arma::Cube<T> *p;
2047 size_t row, col, slice;
2052 ColRange() : p(NULL), row(0), col(0) { }
2053 explicit ColRange(
const arma::Cube<T> *_p,
size_t _row) :
2054 p(_p), row(_row), col(0) { }
2056 typedef T value_type;
2057 typedef SliceRange subiter_type;
2058 static const bool is_container =
true;
2060 bool is_end()
const {
return col == p->n_cols; }
2062 void inc() { ++col; }
2064 value_type deref()
const {
2066 throw std::logic_error(
"static assert should have been triggered by this point");
2069 subiter_type deref_subiter()
const {
2070 return subiter_type(p, row, col);
2074 const arma::Cube<T> *p;
2080 RowRange() : p(NULL), row(0) { }
2081 explicit RowRange(
const arma::Cube<T> *_p) : p(_p), row(0) { }
2083 typedef T value_type;
2084 typedef ColRange subiter_type;
2085 static const bool is_container =
true;
2087 bool is_end()
const {
return row == p->n_rows; }
2089 void inc() { ++row; }
2091 value_type deref()
const {
2093 throw std::logic_error(
"static assert should have been triggered by this point");
2096 subiter_type deref_subiter()
const {
2097 return subiter_type(p, row);
2101 const arma::Cube<T> *p;
2106 static const bool allow_auto_unwrap =
false;
2109 typedef RowRange range_type;
2111 static range_type get_range(
const arma::Cube<T> &arg) {
2113 return range_type(&arg);
2121 template <
typename RF,
typename T>
2125 ColRange() : p(NULL), row(0), col(0) { }
2126 explicit ColRange(
const RF *_p,
size_t _row) :
2127 p(_p), row(_row), col(0) { }
2129 typedef T value_type;
2131 static const bool is_container =
false;
2133 bool is_end()
const {
return col == p->n_cols; }
2135 void inc() { ++col; }
2137 value_type deref()
const {
2138 return (*p)(row, col);
2141 subiter_type deref_subiter()
const {
2143 throw std::logic_error(
"static assert should have been triggered by this point");
2153 RowRange() : p(NULL), row(0) { }
2154 explicit RowRange(
const RF *_p) : p(_p), row(0) { }
2156 typedef T value_type;
2157 typedef ColRange subiter_type;
2158 static const bool is_container =
true;
2160 bool is_end()
const {
return row == p->n_rows; }
2162 void inc() { ++row; }
2164 value_type deref()
const {
2166 throw std::logic_error(
"static assert should have been triggered by this point");
2169 subiter_type deref_subiter()
const {
2170 return subiter_type(p, row);
2179 static const bool allow_auto_unwrap =
false;
2182 typedef RowRange range_type;
2184 static range_type get_range(
const RF &arg) {
2186 return range_type(&arg);
2190 template <
typename T>
2191 class ArrayTraits<arma::field<T> > :
public ArrayTraits_ArmaMatOrField<arma::field<T>, T> { };
2193 template <
typename T>
2194 class ArrayTraits<arma::Mat<T> > :
public ArrayTraits_ArmaMatOrField<arma::Mat<T>, T> { };
2200 template <
typename T>
2203 static const bool allow_auto_unwrap =
false;
2207 static range_type get_range(
const arma::Row<T> &arg) {
2209 return range_type(arg.begin(), arg.end());
2217 template <
typename T>
2220 static const bool allow_auto_unwrap =
false;
2224 static range_type get_range(
const arma::Col<T> &arg) {
2226 return range_type(arg.begin(), arg.end());
2233 #endif // GNUPLOT_ARMADILLO_SUPPORT_LOADED 2234 #endif // ARMA_INCLUDES static range_type get_range(const T &)
VecOfRange< typename ArrayTraits< T >::range_type::subiter_type > get_columns_range(const T &arg)
Gnuplot & send(const T &arg, OrganizationMode)
void send_scalar(std::ostream &stream, const T &arg, ModeText)
IteratorRange< typename T::const_iterator, typename T::value_type > range_type
boost::mpl::and_< typename has_head_type< T >::type, typename has_tail_type< T >::type > type
static void send(std::ostream &stream)
static void send(std::ostream &stream)
static std::string class_name()
ArrayTraits< typename std::pair< HT, TT > > parent
static void send(std::ostream &stream, const T &v)
static void send(std::ostream &stream, const T &v)
#define GNUPLOT_STATIC_ASSERT_MSG(cond, msg)
Gnuplot & sendBinary(const T &arg, OrganizationMode)
static void send(std::ostream &stream, const T &v)
static bool debug_array_print
static void send(std::ostream &stream, const std::pair< T, U > &v)
boost::disable_if_c< T::is_container >::type deref_and_print(std::ostream &stream, const T &arg, PrintMode)
Gnuplot(const std::string &_cmd="")
PairOfRange(const RT &_l, const RU &_r)
std::string make_tmpfile()
static void send(std::ostream &stream)
static std::string class_name()
#define GNUPLOT_MSVC_WARNING_4996_POP
IteratorRange(const TI &_it, const TI &_end)
boost::mpl::if_c< is_container, Error_InappropriateDeref, TV >::type value_type
static std::string get_default_cmd()
static std::string class_name()
static range_type get_range(const std::pair< T, U > &arg)
static void send(std::ostream &stream)
static std::string class_name()
std::string binfmt(const T &arg, const std::string &arr_or_rec, OrganizationMode)
size_t get_range_size(const T &arg)
std::string binaryFile(const T &arg, std::string filename, const std::string &arr_or_rec, OrganizationMode)
FileHandleWrapper(std::FILE *_fh, bool _should_use_pclose)
static void send(std::ostream &stream)
subiter_type deref_subiter() const
std::vector< int > tmp_files
static range_type get_range(const T(&arg)[N])
static void send(std::ostream &stream)
boost::mpl::and_< typename has_value_type< T >::type, typename has_const_iterator< T >::type, boost::mpl::not_< dont_treat_as_stl_container< T > > > type
Error_WasNotContainer value_type
static void send(std::ostream &stream, const T &v)
static void send(std::ostream &stream, const T &v)
PairOfRange< typename RT::subiter_type, typename RU::subiter_type > subiter_type
boost::mpl::bool_< value > type
ArrayTraits< TV >::range_type subiter_type
void top_level_array_sender(std::ostream &stream, const T &arg, OrganizationMode, PrintMode)
static void send(std::ostream &)
plotting_empty_container()
static void send(std::ostream &stream)
subiter_type deref_subiter() const
#define GNUPLOT_DEPRECATE(msg)
VecOfRange(const std::vector< RT > &_rvec)
static parent::range_type get_range(const T &arg)
Gnuplot GNUPLOT_DEPRECATE("use send1d or send2d")&send(const T &arg)
std::pair< typename ArrayTraits< T >::value_type, typename ArrayTraits< U >::value_type > value_type
std::vector< typename RT::value_type > value_type
std::string file(const T &arg, std::string filename, OrganizationMode)
static void send(std::ostream &stream, const T &v)
static void send(std::ostream &stream, const std::complex< T > &v)
static range_type get_range(const T &arg)
void handle_colunwrap_tag(std::ostream &stream, const T &arg, ColUnwrapNo, PrintMode)
static void send(std::ostream &stream)
static void send(std::ostream &stream)
static void send(std::ostream &stream, const T &v)
static void send(std::ostream &stream, const std::pair< T, U > &v)
static parent::range_type get_range(const T &arg)
void handle_organization_tag(std::ostream &stream, const T &arg, Mode1D, PrintMode)
virtual ~GnuplotFeedback()
Error_WasNotContainer range_type
static FileHandleWrapper open_cmdline(const std::string &in)
boost::mpl::bool_< false > type
PairOfRange< typename ArrayTraits< T >::range_type, typename ArrayTraits< U >::range_type > range_type
VecOfRange< typename RT::subiter_type > subiter_type
static void send(std::ostream &stream, const T &v)
#define GNUPLOT_MSVC_WARNING_4996_PUSH
subiter_type deref_subiter() const
IteratorRange< const T *, T > range_type
static void send(std::ostream &stream)
boost::mpl::bool_< value > type
boost::enable_if_c<(Depth==1)&&!PrintMode::is_size >::type print_block(std::ostream &stream, T &arg, PrintMode)
static void send(std::ostream &stream, const T &v)
static void send(std::ostream &stream)
std::pair< typename RT::value_type, typename RU::value_type > value_type
static void send(std::ostream &stream)
static void send(std::ostream &stream)
static void send(std::ostream &stream)
static std::string class_name()
#define GNUPLOT_DEFAULT_COMMAND
static void send(std::ostream &stream, const std::complex< T > &v)