vnl_xio_vector.hxx
Go to the documentation of this file.
1 // This is core/vnl/xio/vnl_xio_vector.hxx
2 #ifndef vnl_xio_vector_hxx_
3 #define vnl_xio_vector_hxx_
4 
5 #include "vnl_xio_vector.h"
6 #include <vsl/vsl_basic_xml_element.h>
7 
8 //=================================================================================
9 template<class T>
10 void x_write(std::ostream & os, vnl_vector<T> const& v, std::string name)
11 {
12  vsl_basic_xml_element element(name);
13  element.add_attribute("size", v.size());
14  for (unsigned i=0; i<v.size(); ++i)
15  element.append_cdata(v.get(i));
16  element.x_write(os);
17 }
18 
19 //=================================================================================
20 template<class T>
21 void x_write_tree(std::ostream & os, vnl_vector<T> const& v, std::string name)
22 {
23  vsl_basic_xml_element element(name);
24  element.add_attribute("size", v.size());
25  for (unsigned i=0; i<v.size(); ++i) {
26  element.append_cdata("<element>");
27  element.append_cdata(v.get(i));
28  element.append_cdata("</element>");
29  }
30  element.x_write(os);
31 }
32 
33 #undef VNL_XIO_VECTOR_INSTANTIATE
34 #define VNL_XIO_VECTOR_INSTANTIATE(T) \
35 template VNL_EXPORT void x_write(std::ostream &, vnl_vector<T > const&, std::string); \
36 template VNL_EXPORT void x_write_tree(std::ostream &, vnl_vector<T > const&, std::string)
37 
38 #endif // vnl_xio_vector_hxx_
XML write a vnl_vector Two functions which write a valid XML fragment to an ostream.
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.
#define v
Definition: vnl_vector.h:42
Mathematical vector class, templated by type of element.
Definition: vnl_fwd.h:16
void VNL_EXPORT x_write(std::ostream &os, vnl_matrix< T > const &v, std::string name="vnl_matrix")
XML save vnl_matrix to stream.