Go to the documentation of this file.00001
00002 #ifndef vsl_stack_io_txx_
00003 #define vsl_stack_io_txx_
00004
00005
00006
00007
00008
00009 #include "vsl_stack_io.h"
00010 #include <vsl/vsl_binary_io.h>
00011 #include <vsl/vsl_indent.h>
00012
00013
00014
00015 template <class T>
00016 void vsl_b_write(vsl_b_ostream& s, const vcl_stack<T>& v)
00017 {
00018 const short version_no = 1;
00019 vsl_b_write(s, version_no);
00020
00021
00022 vcl_stack<T> tmp_stack = v;
00023
00024 unsigned int stack_size = (unsigned int)(v.size());
00025 vsl_b_write(s, stack_size);
00026 for (unsigned int i=0; i<stack_size; i++)
00027 {
00028 vsl_b_write(s,tmp_stack.top());
00029 tmp_stack.pop();
00030 }
00031 }
00032
00033
00034
00035 template <class T>
00036 void vsl_b_read(vsl_b_istream& is, vcl_stack<T>& v)
00037 {
00038 if (!is) return;
00039
00040 while (!v.empty()) v.pop();
00041
00042 unsigned int stack_size;
00043 vcl_stack<T> tmp_stack;
00044 short ver;
00045 vsl_b_read(is, ver);
00046 switch (ver)
00047 {
00048 case 1:
00049 vsl_b_read(is, stack_size);
00050
00051
00052
00053 for (unsigned int i=0; i<stack_size; i++)
00054 {
00055 T tmp;
00056 vsl_b_read(is,tmp);
00057 tmp_stack.push(tmp);
00058 }
00059 for (unsigned int i=0; i<stack_size; i++)
00060 {
00061 v.push(tmp_stack.top());
00062 tmp_stack.pop();
00063 }
00064 break;
00065 default:
00066 vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vcl_stack<T>&)\n"
00067 << " Unknown version number "<< ver << '\n';
00068 is.is().clear(vcl_ios::badbit);
00069 return;
00070 }
00071 }
00072
00073
00074
00075 template <class T>
00076 void vsl_print_summary(vcl_ostream& os, const vcl_stack<T> &v)
00077 {
00078 vcl_stack<T> tmp_stack = v;
00079 os << "Stack length: " << v.size() << '\n';
00080
00081 unsigned int stack_size = (unsigned int)(v.size());
00082 for (unsigned int i=0; i<stack_size && i<5; i++)
00083 {
00084 os << vsl_indent() << ' ' << i << ": ";
00085 vsl_indent_inc(os);
00086 vsl_print_summary(os, tmp_stack.top());
00087 tmp_stack.pop();
00088 os << '\n';
00089 vsl_indent_dec(os);
00090 }
00091 if (stack_size > 5)
00092 os << " ...\n";
00093 }
00094
00095
00096 #define VSL_STACK_IO_INSTANTIATE(T) \
00097 template void vsl_print_summary(vcl_ostream& s, const vcl_stack<T >& v); \
00098 template void vsl_b_write(vsl_b_ostream& s, const vcl_stack<T >& v); \
00099 template void vsl_b_read(vsl_b_istream& s, vcl_stack<T >& v)
00100
00101 #endif // vsl_stack_io_txx_