Go to the documentation of this file.00001
00002 #ifndef vnl_xio_matrix_txx_
00003 #define vnl_xio_matrix_txx_
00004
00005 #include "vnl_xio_matrix.h"
00006 #include <vnl/vnl_matrix.h>
00007 #include <vsl/vsl_basic_xml_element.h>
00008
00009
00010 template<class T>
00011 void x_write(vcl_ostream & os, vnl_matrix<T> const& M, vcl_string name)
00012 {
00013 vsl_basic_xml_element element(name);
00014 element.add_attribute("rows", (int) M.rows());
00015 element.add_attribute("cols", (int) M.cols());
00016 for (unsigned int r=0; r<M.rows(); ++r) {
00017 for (unsigned int c=0; c<M.cols(); ++c)
00018 element.append_cdata(M.get(r,c));
00019 }
00020 element.x_write(os);
00021 }
00022
00023
00024 template<class T>
00025 void x_write_tree(vcl_ostream & os, vnl_matrix<T> const& M, vcl_string name)
00026 {
00027 vsl_basic_xml_element element(name);
00028 element.add_attribute("rows", (int) M.rows());
00029 element.add_attribute("cols", (int) M.cols());
00030 for (unsigned int r=0; r<M.rows(); ++r) {
00031 element.append_cdata("<row>");
00032 for (unsigned int c=0; c<M.cols(); ++c) {
00033 element.append_cdata("<cell>");
00034 element.append_cdata(M.get(r,c));
00035 element.append_cdata("</cell>");
00036 }
00037 element.append_cdata("</row>");
00038 }
00039 element.x_write(os);
00040 }
00041
00042 #undef VNL_XIO_MATRIX_INSTANTIATE
00043 #define VNL_XIO_MATRIX_INSTANTIATE(T) \
00044 template void x_write(vcl_ostream &, vnl_matrix<T > const&, vcl_string); \
00045 template void x_write_tree(vcl_ostream &, vnl_matrix<T > const&, vcl_string)
00046
00047 #endif // vnl_xio_matrix_txx_