Go to the documentation of this file.00001
00002 #ifndef vnl_io_vector_txx_
00003 #define vnl_io_vector_txx_
00004
00005
00006
00007 #include "vnl_io_vector.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>
00015 void vsl_b_write(vsl_b_ostream & os, const vnl_vector<T> & 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.begin(), p.size());
00022 }
00023
00024
00025
00026 template<class T>
00027 void vsl_b_read(vsl_b_istream &is, vnl_vector<T> & p)
00028 {
00029 if (!is) return;
00030
00031 short ver;
00032 unsigned n;
00033 vsl_b_read(is, ver);
00034 switch (ver)
00035 {
00036 case 1:
00037 vsl_b_read(is, n);
00038 p.set_size(n);
00039 if (n)
00040 vsl_b_read_block_old(is, p.data_block(), n);
00041 break;
00042
00043 case 2:
00044 vsl_b_read(is, n);
00045 p.set_size(n);
00046 if (n)
00047 vsl_block_binary_read(is, p.data_block(), n);
00048 break;
00049
00050 default:
00051 vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vnl_vector<T>&)\n"
00052 << " Unknown version number "<< ver << '\n';
00053 is.is().clear(vcl_ios::badbit);
00054 return;
00055 }
00056 }
00057
00058
00059
00060 template<class T>
00061 void vsl_print_summary(vcl_ostream & os,const vnl_vector<T> & p)
00062 {
00063 os<<"Len: "<<p.size()<<" (";
00064 for ( unsigned int i =0; i < p.size() && i < 5; ++i )
00065 os << p.operator()(i) <<' ';
00066 if (p.size() > 5) os << " ...";
00067 os << ')';
00068 }
00069
00070 #define VNL_IO_VECTOR_INSTANTIATE(T) \
00071 template void vsl_print_summary(vcl_ostream &, const vnl_vector<T > &); \
00072 template void vsl_b_read(vsl_b_istream &, vnl_vector<T > &); \
00073 template void vsl_b_write(vsl_b_ostream &, const vnl_vector<T > &)
00074
00075 #endif // vnl_io_vector_txx_