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