vnl_xio_matrix_fixed.hxx
Go to the documentation of this file.
1 // This is core/vnl/xio/vnl_xio_matrix_fixed.hxx
2 #ifndef vnl_xio_matrix_fixed_hxx_
3 #define vnl_xio_matrix_fixed_hxx_
4 
5 #include "vnl_xio_matrix_fixed.h"
6 #include <vnl/vnl_matrix_fixed.h>
7 #include <vsl/vsl_basic_xml_element.h>
8 
9 //=================================================================================
10 template<class T, unsigned m, unsigned n>
11 void x_write(std::ostream & os, vnl_matrix_fixed<T,m,n> const& M, std::string name)
12 {
13  vsl_basic_xml_element element(name);
14  element.add_attribute("rows", (int) m);
15  element.add_attribute("cols", (int) n);
16  for (unsigned int r=0; r<m; ++r) {
17  for (unsigned int c=0; c<n; ++c)
18  element.append_cdata(M.get(r,c));
19  }
20  element.x_write(os);
21 }
22 
23 //=================================================================================
24 template<class T, unsigned m, unsigned n>
25 void x_write_tree(std::ostream & os, vnl_matrix_fixed<T,m,n> const& M, std::string name)
26 {
27  vsl_basic_xml_element element(name);
28  element.add_attribute("rows", (int) m);
29  element.add_attribute("cols", (int) n);
30  for (unsigned int r=0; r<m; ++r) {
31  element.append_cdata("<row>");
32  for (unsigned int c=0; c<n; ++c) {
33  element.append_cdata("<cell>");
34  element.append_cdata(M.get(r,c));
35  element.append_cdata("</cell>");
36  }
37  element.append_cdata("</row>");
38  }
39  element.x_write(os);
40 }
41 
42 #undef VNL_XIO_MATRIX_FIXED_INSTANTIATE
43 #define VNL_XIO_MATRIX_FIXED_INSTANTIATE(T,m,n) \
44 template void x_write(std::ostream &, vnl_matrix_fixed<T,m,n > const&, std::string); \
45 template void x_write_tree(std::ostream &, vnl_matrix_fixed<T,m,n > const&, std::string)
46 
47 #endif // vnl_xio_matrix_fixed_hxx_
#define m
Definition: vnl_vector.h:43
void VNL_EXPORT x_write_tree(std::ostream &os, vnl_matrix< T > const &v, std::string name="vnl_matrix")
XML save vnl_matrix as a 3-level tree to stream.
Fixed size, stack-stored, space-efficient matrix.
Definition: vnl_fwd.h:23
T get(unsigned r, unsigned c) const
get element.
fixed size matrix
void VNL_EXPORT x_write(std::ostream &os, vnl_matrix< T > const &v, std::string name="vnl_matrix")
XML save vnl_matrix to stream.
XML write a vnl_matrix_fixed Two functions which write a valid XML fragment to an ostream.