Go to the documentation of this file.00001
00002 #ifndef vnl_io_vector_fixed_txx_
00003 #define vnl_io_vector_fixed_txx_
00004
00005
00006
00007 #include "vnl_io_vector_fixed.h"
00008 #include <vsl/vsl_binary_io.h>
00009 #include <vsl/vsl_b_read_block_old.h>
00010 #include <vsl/vsl_block_binary.h>
00011
00012
00013
00014 template<class T, unsigned int n>
00015 void vsl_b_write(vsl_b_ostream & os, const vnl_vector_fixed<T,n> & p)
00016 {
00017 const short io_version_no = 2;
00018 vsl_b_write(os, io_version_no);
00019 vsl_b_write(os, p.size());
00020 if (p.size())
00021 vsl_block_binary_write(os, p.data_block(), p.size());
00022 }
00023
00024
00025
00026 template<class T, unsigned int n>
00027 void vsl_b_read(vsl_b_istream &is, vnl_vector_fixed<T,n> & p)
00028 {
00029 if (!is) return;
00030
00031 short ver;
00032 unsigned stream_n;
00033 vsl_b_read(is, ver);
00034 switch (ver)
00035 {
00036 case 1:
00037 vsl_b_read(is, stream_n);
00038 if ( n == stream_n ) {
00039 vsl_b_read_block_old(is, p.begin(), n);
00040 } else {
00041 vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vnl_vector_fixed<T,n>&)\n"
00042 << " Expected n="<<n<<", got "<<stream_n<<'\n';
00043 is.is().clear(vcl_ios::badbit);
00044 return;
00045 }
00046 break;
00047
00048 case 2:
00049 vsl_b_read(is, stream_n);
00050 if ( n == stream_n ) {
00051 vsl_block_binary_read(is, p.data_block(), n);
00052 } else {
00053 vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vnl_vector_fixed<T,n>&)\n"
00054 << " Expected n="<<n<<", got "<<stream_n<<'\n';
00055 is.is().clear(vcl_ios::badbit);
00056 return;
00057 }
00058 break;
00059
00060 default:
00061 vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vnl_vector_fixed<T,n>&)\n"
00062 << " Unknown version number "<< ver << '\n';
00063 is.is().clear(vcl_ios::badbit);
00064 return;
00065 }
00066 }
00067
00068
00069
00070 template<class T, unsigned int n>
00071 void vsl_print_summary(vcl_ostream & os,const vnl_vector_fixed<T,n> & p)
00072 {
00073 os<<"Len: "<<p.size()<<" [fixed] (";
00074 for ( unsigned int i =0; i < p.size() && i < 5; ++i )
00075 os << p(i) <<' ';
00076 if (p.size() > 5) os << " ...";
00077 os << ')';
00078 }
00079
00080 #define VNL_IO_VECTOR_FIXED_INSTANTIATE(T,n) \
00081 template void vsl_print_summary(vcl_ostream &, const vnl_vector_fixed<T,n > &); \
00082 template void vsl_b_read(vsl_b_istream &, vnl_vector_fixed<T,n > &); \
00083 template void vsl_b_write(vsl_b_ostream &, const vnl_vector_fixed<T,n > &)
00084
00085 #endif // vnl_io_vector_fixed_txx_