vgl_io_vector_2d.hxx
Go to the documentation of this file.
1 // This is core/vgl/io/vgl_io_vector_2d.hxx
2 #ifndef vgl_io_vector_2d_hxx_
3 #define vgl_io_vector_2d_hxx_
4 //:
5 // \file
6 
7 #include <iostream>
8 #include "vgl_io_vector_2d.h"
9 
10 //============================================================================
11 //: Binary save self to stream.
12 template<class T>
13 void vsl_b_write(vsl_b_ostream &os, const vgl_vector_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.x());
18  vsl_b_write(os, v.y());
19 }
20 
21 //============================================================================
22 //: Binary load self from stream.
23 template<class T>
24 void vsl_b_read(vsl_b_istream &is, vgl_vector_2d<T> & v)
25 {
26  if (!is) return;
27 
28  short ver;
29  vsl_b_read(is, ver);
30  switch (ver)
31  {
32  case 1:
33  T x, y;
34  vsl_b_read(is, x);
35  vsl_b_read(is, y);
36  v.set(x,y);
37  break;
38 
39  default:
40  std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vgl_vector_2d<T>&)\n"
41  << " Unknown version number "<< v << '\n';
42  is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
43  return;
44  }
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 vgl_vector_2d<T> & v)
52 {
53  os<<'('<<v.x()<<','<<v.y()<<')';
54 }
55 
56 #define VGL_IO_VECTOR_2D_INSTANTIATE(T) \
57 template void vsl_print_summary(std::ostream &, const vgl_vector_2d<T > &); \
58 template void vsl_b_read(vsl_b_istream &, vgl_vector_2d<T > &); \
59 template void vsl_b_write(vsl_b_ostream &, const vgl_vector_2d<T > &)
60 
61 #endif // vgl_io_vector_2d_hxx_
void vsl_b_read(vsl_b_istream &is, vgl_vector_2d< T > &v)
Binary load self from stream.
Direction vector in Euclidean 2D space, templated by type of element.
Definition: vgl_fwd.h:12
void vsl_print_summary(std::ostream &os, const vgl_vector_2d< T > &v)
Output a human readable summary to the stream.
#define v
Definition: vgl_vector_2d.h:74
void vsl_b_write(vsl_b_ostream &os, const vgl_vector_2d< T > &v)
Binary save self to stream.