vnl_matlab_print2.h
Go to the documentation of this file.
1 // This is core/vnl/vnl_matlab_print2.h
2 #ifndef vnl_matlab_print2_h_
3 #define vnl_matlab_print2_h_
4 //:
5 // \file
6 //
7 // After including this header file, the client should be able to say :
8 // \code
9 // vnl_matrix<double> foo(3, 14);
10 // ....
11 // std::cerr << "and the blasted matrix is :" << endl
12 // << vnl_matlab_print(foo)
13 // << vnl_matlab_print(foo, "foo")
14 // << vnl_matlab_print(foo, 0, vnl_matlab_fmt_long);
15 // \endcode
16 // instead of
17 // \code
18 // ....
19 // std::cerr << "and the blasted matrix is :" << endl;
20 // vnl_matlab_print(std::cerr, foo);
21 // vnl_matlab_print(std::cerr, foo, "foo");
22 // vnl_matlab_print(std::cerr, foo, 0, vnl_matlab_fmt_long);
23 // \endcode
24 //
25 // \author fsm
26 
27 #include <iosfwd>
28 #include <vnl/vnl_matlab_print.h>
29 #ifdef _MSC_VER
30 # include <vcl_msvc_warnings.h>
31 #endif
32 #include "vnl/vnl_export.h"
33 
34 // The proxy classes.
35 template <class T>
36 struct VNL_EXPORT vnl_matlab_print_proxy
37 {
38  T const &obj;
39  char const *name;
41  vnl_matlab_print_proxy(T const &obj_,
42  char const *name_,
44  : obj(obj_), name(name_), format(format_) { }
45  ~vnl_matlab_print_proxy() = default;
46 };
47 
48 // Output operator for the proxies.
49 template <class T>
50 inline
51 std::ostream &operator<<(std::ostream &os, vnl_matlab_print_proxy<T> const &mp)
52 {
53  return vnl_matlab_print(os, mp.obj, mp.name, mp.format);
54 }
55 
56 // Functions to make proxies. This should work for objects of types
57 // derived from vnl_vector, vnl_matrix etc because the overload
58 // resolution is done in the operator<< above.
59 template <class T>
60 inline
62 vnl_matlab_print(T const &obj,
63  char const *name = nullptr,
65 {
66  return vnl_matlab_print_proxy<T>(obj, name, format);
67 }
68 
69 #define VNL_MATLAB_PRINT2_INSTANTIATE(T) \
70 template struct VNL_EXPORT vnl_matlab_print_proxy<T >; \
71 /* template std::ostream& \
72  operator<<(std::ostream&, vnl_matlab_print_proxy<T > const&); */ \
73 /* template vnl_matlab_print_proxy<T > \
74  vnl_matlab_print(T const&, char const*, vnl_matlab_print_format) */
75 
76 #endif // vnl_matlab_print2_h_
Print matrices and vectors in nice MATLAB format.
vnl_matlab_print_proxy(T const &obj_, char const *name_, vnl_matlab_print_format format_)
VNL_EXPORT std::ostream & vnl_matlab_print(std::ostream &, vnl_diag_matrix< T > const &, char const *variable_name=nullptr, vnl_matlab_print_format=vnl_matlab_print_format_default)
print a vnl_diagonal_matrix<T>.
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
Definition: vnl_decnum.h:393
vnl_matlab_print_format
pretty-printing matlab formats.
vnl_matlab_print_format format