core/vnl/io/vnl_io_rational.cxx
Go to the documentation of this file.
00001 // This is core/vnl/io/vnl_io_rational.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 
00008 #include "vnl_io_rational.h"
00009 #include <vsl/vsl_binary_io.h>
00010 
00011 //=================================================================================
00012 //: Binary save self to stream.
00013 void vsl_b_write(vsl_b_ostream & os, const vnl_rational & p)
00014 {
00015   const short io_version_no = 1;
00016   vsl_b_write(os, io_version_no);
00017   vsl_b_write(os, p.numerator());
00018   vsl_b_write(os, p.denominator());
00019 }
00020 
00021 //=================================================================================
00022 //: Binary load self from stream.
00023 void vsl_b_read(vsl_b_istream &is, vnl_rational & p)
00024 {
00025   if (!is) return;
00026   short ver;
00027   long n, d;
00028   vsl_b_read(is, ver);
00029   switch (ver)
00030   {
00031    case 1:
00032     vsl_b_read(is, n);
00033     vsl_b_read(is, d);
00034     p.set(n,d);
00035     break;
00036 
00037    default:
00038     vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vnl_rational&)\n"
00039              << "           Unknown version number "<< ver << '\n';
00040     is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00041     return;
00042   }
00043 }
00044 
00045 //====================================================================================
00046 //: Output a human readable summary to the stream
00047 void vsl_print_summary(vcl_ostream & os,const vnl_rational & p)
00048 {
00049   os<<p;
00050 }