vnl_io_diag_matrix.hxx
Go to the documentation of this file.
1 // This is core/vnl/io/vnl_io_diag_matrix.hxx
2 #ifndef vnl_io_diag_matrix_hxx_
3 #define vnl_io_diag_matrix_hxx_
4 //:
5 // \file
6 
7 #include <iostream>
8 #include "vnl_io_diag_matrix.h"
9 #include <vsl/vsl_binary_io.h>
10 #include <vnl/io/vnl_io_vector.h>
11 
12 
13 //=================================================================================
14 //: Binary save self to stream.
15 template<class T>
16 void vsl_b_write(vsl_b_ostream & os, const vnl_diag_matrix<T> & p)
17 {
18  constexpr short io_version_no = 1;
19  vsl_b_write(os, io_version_no);
20  vsl_b_write(os, p.diagonal());
21 }
22 
23 //=================================================================================
24 //: Binary load self from stream.
25 template<class T>
26 void vsl_b_read(vsl_b_istream &is, vnl_diag_matrix<T> & p)
27 {
28  if (!is) return;
29 
30  short ver;
32  vsl_b_read(is, ver);
33  switch (ver)
34  {
35  case 1:
36  vsl_b_read(is, v);
37  p.set(v);
38  break;
39 
40  default:
41  std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vnl_diag_matrix<T>&)\n"
42  << " Unknown version number "<< v << '\n';
43  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
44  return;
45  }
46 }
47 
48 //====================================================================================
49 //: Output a human readable summary to the stream
50 template<class T>
51 void vsl_print_summary(std::ostream & os,const vnl_diag_matrix<T> & p)
52 {
53  os<<"Diagonal: ";
54  vsl_print_summary(os, p.diagonal());
55 }
56 
57 #define VNL_IO_DIAG_MATRIX_INSTANTIATE(T) \
58 template VNL_EXPORT void vsl_print_summary(std::ostream &, const vnl_diag_matrix<T > &); \
59 template VNL_EXPORT void vsl_b_read(vsl_b_istream &, vnl_diag_matrix<T > &); \
60 template VNL_EXPORT void vsl_b_write(vsl_b_ostream &, const vnl_diag_matrix<T > &)
61 
62 #endif // vnl_io_diag_matrix_hxx_
void vsl_print_summary(std::ostream &os, vnl_bignum const &b)
Print human readable summary of object to a stream.
vnl_diag_matrix & set(vnl_vector< T > const &v)
Set diagonal elements using vector.
vnl_vector< T > const & diagonal() const
Return diagonal elements as a vector.
#define v
Definition: vnl_vector.h:42
void vsl_b_read(vsl_b_istream &is, vnl_bignum &v)
Binary load vnl_bignum from stream.
void vsl_b_write(vsl_b_ostream &os, vnl_bignum const &v)
Binary save vnl_bignum to stream.
Mathematical vector class, templated by type of element.
Definition: vnl_fwd.h:16
stores a diagonal matrix as a single vector.