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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00042
00043
00044 #ifndef IOSTREAM_EXT_HEADER
00045 #define IOSTREAM_EXT_HEADER
00046
00047 #include <iostream>
00048 #include <sstream>
00049 #include <vector>
00050 #include <list>
00051
00052 namespace ot
00053 {
00060 template <typename T>
00061 std::ostream& operator<<(std::ostream& os, const std::vector<T>& object)
00062 {
00063 typename std::vector<T>::const_iterator it;
00064
00065 os << "[" << object.size() << ":";
00066 for (it = object.begin(); it != object.end(); it++)
00067 {
00068 if (it != object.begin())
00069 os << ";";
00070 os << *it;
00071 }
00072 os << "]";
00073 return os;
00074 };
00081 template <typename T>
00082 std::ostream& operator<<(std::ostream& os, const std::list<T>& object)
00083 {
00084 typename std::list<T>::const_iterator it;
00085
00086 os << object.size() << ":";
00087 for (it = object.begin(); it != object.end(); it++)
00088 {
00089 if (it != object.begin())
00090 os << ";";
00091 os << *it;
00092 }
00093 os << ".";
00094 return os;
00095 };
00102 template <typename T>
00103 std::istream& operator>>(std::istream& is, std::vector<T>& object)
00104 {
00105 typename std::vector<T>::size_type n;
00106 typename std::vector<T>::size_type i;
00107 char c;
00108
00109 object.clear();
00110
00111
00112 if (!(is >> c))
00113 return is;
00114 if (c != '[')
00115 {
00116 is.setstate(std::ios_base::failbit);
00117 return is;
00118 }
00119
00120
00121 if (!(is >> n))
00122 return is;
00123 object.reserve(n);
00124
00125
00126 if (!(is >> c))
00127 return is;
00128 if (c != ':')
00129 {
00130 is.setstate(std::ios_base::failbit);
00131 return is;
00132 }
00133
00134
00135 for (i = 0; i < n; i++)
00136 {
00137 T t;
00138 is >> t;
00139 object.push_back(t);
00140
00141 if (!(is >> c))
00142 return is;
00143 if (c != ';' && c != ']')
00144 {
00145 is.setstate(std::ios_base::failbit);
00146 return is;
00147 }
00148 }
00149
00150 return is;
00151 };
00158 template <typename T>
00159 std::istream& operator>>(std::istream& is, std::list<T>& object)
00160 {
00161 typename std::list<T>::size_type n;
00162 typename std::list<T>::size_type i;
00163 char c;
00164
00165 object.clear();
00166
00167
00168 if (!(is >> n))
00169 return is;
00170
00171
00172 if (!(is >> c))
00173 return is;
00174 if (c != ':')
00175 {
00176 is.setstate(std::ios_base::failbit);
00177 return is;
00178 }
00179
00180
00181 for (i = 0; i < n; i++)
00182 {
00183 T t;
00184 is >> t;
00185 object.push_back(t);
00186
00187 if (!(is >> c))
00188 return is;
00189 if (c != ';' && c!= '.')
00190 {
00191 is.setstate(std::ios_base::failbit);
00192 return is;
00193 }
00194 }
00195
00196 return is;
00197 };
00198
00199 }
00200
00201 #endif
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217