core/vgl/io/vgl_io_vector_2d.txx
Go to the documentation of this file.
00001 // This is core/vgl/io/vgl_io_vector_2d.txx
00002 #ifndef vgl_io_vector_2d_txx_
00003 #define vgl_io_vector_2d_txx_
00004 //:
00005 // \file
00006 
00007 #include "vgl_io_vector_2d.h"
00008 
00009 //============================================================================
00010 //: Binary save self to stream.
00011 template<class T>
00012 void vsl_b_write(vsl_b_ostream &os, const vgl_vector_2d<T> & v)
00013 {
00014   const short io_version_no = 1;
00015   vsl_b_write(os, io_version_no);
00016   vsl_b_write(os, v.x());
00017   vsl_b_write(os, v.y());
00018 }
00019 
00020 //============================================================================
00021 //: Binary load self from stream.
00022 template<class T>
00023 void vsl_b_read(vsl_b_istream &is, vgl_vector_2d<T> & v)
00024 {
00025   if (!is) return;
00026 
00027   short ver;
00028   vsl_b_read(is, ver);
00029   switch (ver)
00030   {
00031    case 1:
00032     T x, y;
00033     vsl_b_read(is, x);
00034     vsl_b_read(is, y);
00035     v.set(x,y);
00036     break;
00037 
00038    default:
00039     vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vgl_vector_2d<T>&)\n"
00040              << "           Unknown version number "<< v << '\n';
00041     is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00042     return;
00043   }
00044 }
00045 
00046 
00047 //============================================================================
00048 //: Output a human readable summary to the stream
00049 template<class T>
00050 void vsl_print_summary(vcl_ostream& os,const vgl_vector_2d<T> & v)
00051 {
00052     os<<'('<<v.x()<<','<<v.y()<<')';
00053 }
00054 
00055 #define VGL_IO_VECTOR_2D_INSTANTIATE(T) \
00056 template void vsl_print_summary(vcl_ostream &, const vgl_vector_2d<T > &); \
00057 template void vsl_b_read(vsl_b_istream &, vgl_vector_2d<T > &); \
00058 template void vsl_b_write(vsl_b_ostream &, const vgl_vector_2d<T > &)
00059 
00060 #endif // vgl_io_vector_2d_txx_