00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00028 #ifndef __PRINT_SEQ_H_
00029 #define __PRINT_SEQ_H_
00030
00031 #include <iostream>
00032 #include <vector>
00033 #include <list>
00034 #include <deque>
00035 #include <iterator>
00036 #include <linalg.h>
00037
00038 namespace std {
00039
00042 template <typename _Ve, typename _TA>
00043 ostream& operator<<(ostream& o, const vector<_Ve,_TA>& a)
00044 {
00045 if(a.size() == 1)
00046 o << a[0];
00047 else if(!a.empty())
00048 {
00049 typename vector<_Ve,_TA>::const_iterator e(a.end());
00050 copy(a.begin(), --e, ostream_iterator<_Ve>(o, ","));
00051 o << *e;
00052 }
00053 return o;
00054 }
00055
00058 template <typename _Ve, typename _TA>
00059 ostream& operator<<(ostream& o, const list<_Ve,_TA>& a)
00060 {
00061 if(a.size() == 1)
00062 o << *(a.begin());
00063 else if(!a.empty())
00064 {
00065 typename list<_Ve,_TA>::const_iterator e(a.end());
00066 copy(a.begin(), --e, ostream_iterator<_Ve>(o, ", "));
00067 o << *e;
00068 }
00069 return o;
00070 }
00071
00075 template <typename _Ve, typename _TA>
00076 ostream& operator<<(ostream& o, const deque<_Ve,_TA>& a)
00077 {
00078 if(a.size() == 1)
00079 o << *(a.begin());
00080 else if(!a.empty())
00081 {
00082 typename deque<_Ve,_TA>::const_iterator e(a.end());
00083 copy(a.begin(), --e, ostream_iterator<_Ve>(o, ", "));
00084 o << *e;
00085 }
00086 return o;
00087 }
00088
00091 template <typename _Tp>
00092 ostream& operator<<(ostream &s, const linalg::sparse_vector<_Tp> &a)
00093 {
00094 if(a.size()==0)
00095 s << "[ Zero ]";
00096 else
00097
00098 {
00099 if(a.output_format == linalg::linalg_output_sparse)
00100 {
00101 s << "[";
00102 typename linalg::sparse_vector<_Tp>::const_iterator _i;
00103 typename linalg::sparse_vector<_Tp>::const_iterator _i_max;
00104 bool zero=true;
00105 _i_max = a.end();
00106 for(_i = a.begin(); _i < _i_max; ++_i)
00107 {
00108 if(zero)
00109 zero = false;
00110 else
00111 s << ",";
00112 s << "(" << _i.index() << "):" << (*_i);
00113 }
00114
00115 s << ((zero) ? " Zero ]":"]");
00116 }
00117 else
00118 {
00119 s << "[";
00120 int i_max = a.size() - 1;
00121 for(int i=0; i<i_max; ++i)
00122 s << a[i] << ",";
00123
00124 s << a[a.size()]<< "]";
00125 }
00126 }
00127 return s;
00128 }
00129 }
00130
00131 #endif