core/vgl/io/vgl_io_box_2d.txx
Go to the documentation of this file.
00001 // This is core/vgl/io/vgl_io_box_2d.txx
00002 #ifndef vgl_io_box_2d_txx_
00003 #define vgl_io_box_2d_txx_
00004 //:
00005 // \file
00006 
00007 #include "vgl_io_box_2d.h"
00008 #include <vsl/vsl_binary_io.h>
00009 
00010 //============================================================================
00011 //: Binary save self to stream.
00012 template<class T>
00013 void vsl_b_write(vsl_b_ostream &os, const vgl_box_2d<T> & p)
00014 {
00015   const short io_version_no = 1;
00016   vsl_b_write(os, io_version_no);
00017   vsl_b_write(os, p.min_x());
00018   vsl_b_write(os, p.min_y());
00019   vsl_b_write(os, p.max_x());
00020   vsl_b_write(os, p.max_y());
00021 }
00022 
00023 //============================================================================
00024 //: Binary load self from stream.
00025 template<class T>
00026 void vsl_b_read(vsl_b_istream &is, vgl_box_2d<T> & p)
00027 {
00028   if (!is) return;
00029 
00030   short v;
00031   T min_pos[2];
00032   T max_pos[2];
00033   vsl_b_read(is, v);
00034   switch (v)
00035   {
00036    case 1:
00037     vsl_b_read(is, min_pos[0]);
00038     vsl_b_read(is, min_pos[1]);
00039     vsl_b_read(is, max_pos[0]);
00040     vsl_b_read(is, max_pos[1]);
00041 
00042     p.set_min_x(min_pos[0]);
00043     p.set_min_y(min_pos[1]);
00044     p.set_max_x(max_pos[0]);
00045     p.set_max_y(max_pos[1]);
00046     break;
00047 
00048    default:
00049     vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vgl_box_2d<T>&)\n"
00050              << "           Unknown version number "<< v << '\n';
00051     is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00052     return;
00053   }
00054 }
00055 
00056 //============================================================================
00057 //: Output a human readable summary to the stream
00058 template<class T>
00059 void vsl_print_summary(vcl_ostream& os,const vgl_box_2d<T> & p)
00060 {
00061   if (p.is_empty())
00062     os<<"Empty 2d box\n";
00063   else
00064     os<<"2d box with opposite corners at (" <<p.min_x() << ',' << p.min_y()
00065       <<") and (" << p.max_x() << ',' << p.max_y() << ")\n";
00066 }
00067 
00068 #define VGL_IO_BOX_2D_INSTANTIATE(T) \
00069 template void vsl_print_summary(vcl_ostream &, const vgl_box_2d<T > &); \
00070 template void vsl_b_read(vsl_b_istream &, vgl_box_2d<T > &); \
00071 template void vsl_b_write(vsl_b_ostream &, const vgl_box_2d<T > &)
00072 
00073 #endif // vgl_io_box_2d_txx_