vgl_io_line_2d.hxx
Go to the documentation of this file.
1 // This is core/vgl/io/vgl_io_line_2d.hxx
2 #ifndef vgl_io_line_2d_hxx_
3 #define vgl_io_line_2d_hxx_
4 //:
5 // \file
6 
7 #include <iostream>
8 #include "vgl_io_line_2d.h"
9 
10 //======================================================================
11 //: Binary save vgl_line_2d to stream.
12 template<class T>
13 void vsl_b_write(vsl_b_ostream &os, const vgl_line_2d<T>& v)
14 {
15  constexpr short io_version_no = 1;
16  vsl_b_write(os, io_version_no);
17  vsl_b_write(os, v.a());
18  vsl_b_write(os, v.b());
19  vsl_b_write(os, v.c());
20 }
21 
22 //======================================================================
23 //: Binary load vgl_line_2d from stream.
24 template<class T>
25 void vsl_b_read(vsl_b_istream &is, vgl_line_2d<T>& v)
26 {
27  if (!is) return;
28 
29  T a,b,c;
30  short w;
31  vsl_b_read(is, w);
32  switch (w)
33  {
34  case 1:
35  vsl_b_read(is, a);
36  vsl_b_read(is, b);
37  vsl_b_read(is, c);
38  v.set(a,b,c);
39  break;
40 
41  default:
42  std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vgl_line_2d<T>&)\n"
43  << " Unknown version number "<< v << '\n';
44  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
45  return;
46  }
47 }
48 
49 
50 //======================================================================
51 //: Output a human readable summary of a vgl_line_2d object to the stream
52 template<class T>
53 void vsl_print_summary(std::ostream &os, const vgl_line_2d<T>& v)
54 {
55  os<<"Line: ( "<<v.a()<<"x + "<<v.b()<<"y + "<<v.c()<<"=0 )";
56 }
57 
58 #define VGL_IO_LINE_2D_INSTANTIATE(T) \
59 template void vsl_print_summary(std::ostream &, const vgl_line_2d<T >&); \
60 template void vsl_b_read(vsl_b_istream &, vgl_line_2d<T >&); \
61 template void vsl_b_write(vsl_b_ostream &, const vgl_line_2d<T >&)
62 
63 #endif // vgl_io_line_2d_hxx_
#define v
Definition: vgl_vector_2d.h:74
void vsl_print_summary(std::ostream &os, const vgl_line_2d< T > &v)
Output a human readable summary of a vgl_line_2d object to the stream.
void vsl_b_write(vsl_b_ostream &os, const vgl_line_2d< T > &v)
Binary save vgl_line_2d to stream.
contains functions vsl_b_write, vsl_b_read and vsl_print_summary
void vsl_b_read(vsl_b_istream &is, vgl_line_2d< T > &v)
Binary load vgl_line_2d from stream.