core/vsl/vsl_list_io.txx

Go to the documentation of this file.
00001 // This is core/vsl/vsl_list_io.txx
00002 #ifndef vsl_list_io_txx_
00003 #define vsl_list_io_txx_
00004 //:
00005 // \file
00006 // \brief  binary IO functions for vcl_list<T>
00007 // \author K.Y.McGaul
00008 //
00009 // Implementation
00010 
00011 #include "vsl_list_io.h"
00012 #include <vsl/vsl_binary_io.h>
00013 #include <vcl_iostream.h>
00014 
00015 //====================================================================================
00016 //: Write list to binary stream
00017 template <class T>
00018 void vsl_b_write(vsl_b_ostream& s, const vcl_list<T>& v)
00019 {
00020   const short version_no = 1;
00021   vsl_b_write(s, version_no);
00022   vsl_b_write(s, v.size());
00023   for (typename vcl_list<T>::const_iterator iter = v.begin(); iter != v.end(); iter++)
00024     vsl_b_write(s,*iter);
00025 }
00026 
00027 //====================================================================================
00028 //: Read list from binary stream
00029 template <class T>
00030 void vsl_b_read(vsl_b_istream& is, vcl_list<T>& v)
00031 {
00032   if (!is) return;
00033 
00034   v.clear();
00035   unsigned list_size;
00036   short ver;
00037   vsl_b_read(is, ver);
00038   switch (ver)
00039   {
00040   case 1:
00041     vsl_b_read(is, list_size);
00042     for (unsigned i=0; i<list_size; i++)
00043     {
00044       T tmp;
00045       vsl_b_read(is,tmp);
00046       v.push_back(tmp);
00047     }
00048     break;
00049   default:
00050     vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vcl_list<T>&)\n"
00051              << "           Unknown version number "<< ver << '\n';
00052     is.is().clear(vcl_ios::badbit); // Set an unrecoverable IO error on stream
00053     return;
00054   }
00055 }
00056 
00057 //====================================================================================
00058 //: Output a human readable summary to the stream
00059 template <class T>
00060 void vsl_print_summary(vcl_ostream& os, const vcl_list<T> &v)
00061 {
00062   unsigned i=0;
00063   os << "List length: " << v.size() << '\n';
00064   for (typename vcl_list<T>::const_iterator iter = v.begin();
00065        iter != v.end() && i<5; ++iter,++i)
00066   {
00067     os << ' ' << i << ": ";
00068     vsl_print_summary(os, *iter);
00069     os << '\n';
00070   }
00071   if (v.size() > 5)
00072     os << " ...\n";
00073 }
00074 
00075 #define VSL_LIST_IO_INSTANTIATE(T) \
00076 template void vsl_print_summary(vcl_ostream&, const vcl_list<T >&); \
00077 template void vsl_b_write(vsl_b_ostream& s, const vcl_list<T >& v); \
00078 template void vsl_b_read(vsl_b_istream& s, vcl_list<T >& v)
00079 
00080 #endif // vsl_list_io_txx_

Generated on Mon Oct 6 05:05:50 2008 for core/vsl by  doxygen 1.5.1