Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

vnl_matlab_print2.h

Go to the documentation of this file.
00001 #ifndef vnl_matlab_print2_h_
00002 #define vnl_matlab_print2_h_
00003 // This is vxl/vnl/vnl_matlab_print2.h
00004 
00005 //: \file
00006 //  \author fsm@robots.ox.ac.uk
00007 // After including this header file, the client should be able to say :
00008 // \verbatim
00009 //   vnl_matrix<double> foo(3, 14);
00010 //  ....
00011 //   cerr << "and the blasted matrix is :" << endl
00012 //        << vnl_matlab_print(foo)
00013 //        << vnl_matlab_print(foo, "foo")
00014 //        << vnl_matlab_print(foo, 0, vnl_matlab_fmt_long);
00015 // \endverbatim
00016 // instead of
00017 // \verbatim
00018 //  ....
00019 //   cerr << "and the blasted matrix is :" << endl;
00020 //        vnl_matlab_print(cerr, foo);
00021 //        vnl_matlab_print(cerr, foo, "foo");
00022 //        vnl_matlab_print(cerr, foo, 0, vnl_matlab_fmt_long);
00023 // \endverbatim
00024 //
00025 //
00026 //     
00027 #include <vnl/vnl_matlab_print.h>
00028 
00029 // The proxy classes.
00030 template <class T>
00031 struct vnl_matlab_print_proxy
00032 {
00033   T const &obj;
00034   char const *name;
00035   vnl_matlab_print_format format;
00036   vnl_matlab_print_proxy(T const &obj_,
00037                          char const *name_,
00038                          vnl_matlab_print_format format_)
00039     : obj(obj_), name(name_), format(format_) { }
00040   ~vnl_matlab_print_proxy() { }
00041 };
00042 
00043 // Output operator for the proxies.
00044 template <class T>
00045 inline
00046 vcl_ostream &operator<<(vcl_ostream &os, vnl_matlab_print_proxy<T> const &mp)
00047 {
00048   return vnl_matlab_print(os, mp.obj, mp.name, mp.format);
00049 }
00050 
00051 // Functions to make proxies. This should work for objects of types
00052 // derived from vnl_vector, vnl_matrix etc because the overload
00053 // resolution is done in the operator<< above.
00054 template <class T>
00055 inline
00056 vnl_matlab_print_proxy<T>
00057 vnl_matlab_print(T const &obj,
00058                  char const *name = 0,
00059                  vnl_matlab_print_format format = vnl_matlab_print_format_default)
00060 {
00061   return vnl_matlab_print_proxy<T>(obj, name, format);
00062 }
00063 
00064 #define VNL_MATLAB_PRINT2_INSTANTIATE(T) \
00065 template struct vnl_matlab_print_proxy<T >; \
00066 VCL_INSTANTIATE_INLINE(vcl_ostream &operator<<(vcl_ostream &, \
00067                                            vnl_matlab_print_proxy<T > const &)); \
00068 VCL_INSTANTIATE_INLINE(vnl_matlab_print_proxy<T > vnl_matlab_print(T const &, \
00069                                                                    char const *, \
00070                                                                    vnl_matlab_print_format));
00071 
00072 #endif // vnl_matlab_print2_h_

Generated at Fri May 21 01:15:48 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000