stlio.h

Go to the documentation of this file.
00001 #ifndef   __stlio_h
00002 #define   __stlio_h
00003 
00004 #include  "fixarray.h"
00005 #include  <string>
00006 #include  "compvector.h"
00007 #include  "gascoigne.h"
00008 
00009 #include  <vector>
00010 #include  <set>
00011 #include  <map>
00012 
00013 #ifdef __OLDCOMPILER__
00014 #include  <hash_map>
00015 #define HASHMAP  hash_map
00016 #else
00017 #include  <ext/hash_map>
00018 #define HASHMAP  __gnu_cxx::hash_map
00019 #endif
00020 
00021 /*---------------------------------------------*/
00022 
00023 namespace Gascoigne
00024 {
00025 
00026 // std::ostream& operator<<(std::ostream &s, const std::map<int,fixarray<4,int> >& A);
00027 // std::ostream& operator<<(std::ostream &s, const std::map<std::string,std::string>& A);
00028 // std::ostream& operator<<(std::ostream &s, const std::map<std::string,int>& A);
00029 // std::ostream& operator<<(std::ostream &s, const std::map<std::string,double>& A);
00030 // std::ostream& operator<<(std::ostream &s, const std::map<std::pair<std::string,std::string>,int>& A);
00031 // std::ostream& operator<<(std::ostream &s, const std::set<std::string>& A);
00032 // std::ostream& operator<<(std::ostream &s, const std::set<int>& A);
00033 // std::ostream& operator<<(std::ostream& s, const std::vector<std::pair<int,int> >& A);
00034 
00035 // std::istream& operator>>(std::istream &s, std::set<std::string>& A);
00036 // std::istream& operator>>(std::istream &s, std::set<int>& A);
00037 
00038 
00039 /*----------------------------------------------*/
00040 
00041 template<class T>
00042 std::ostream& operator<<(std::ostream& s, const std::set<T>& A)
00043 {
00044   std::ostream_iterator<T>  os(s, " ");
00045   copy(A.begin(),A.end(),os);
00046   return s;
00047 }
00048 
00049 template<class T>
00050 std::istream& operator>>(std::istream& s, std::set<T>& A)
00051 {
00052   std::ostream_iterator<T>  os(s, " ");
00053   copy(A.begin(),A.end(),os);
00054   return s;
00055 }
00056 
00057 /*---------------------------------------------*/
00058 
00059 template<class T>
00060 std::ostream& operator<<(std::ostream &s, const std::vector<T>& A)
00061 {
00062   std::ostream_iterator<T>  os(s, " ");
00063   copy(A.begin(),A.end(),os);
00064   return s;
00065 }
00066 
00067 template<class T>
00068 std::istream& operator>>(std::istream &s, std::vector<T>& A)
00069 {
00070   typename std::vector<T>::iterator p = A.begin();
00071   while(p!=A.end())
00072     s >> *p++;
00073   return s;
00074 }
00075 
00076 
00077 /*---------------------------------------------*/
00078 
00079 template<class T>
00080 std::ostream& putvector(const std::vector<T>& v,std::ostream& s)
00081 {
00082   for(typename std::vector<T>::const_iterator p = v.begin();p!=v.end();p++) p->put(s);
00083   return s;
00084 }
00085 
00086 
00087 /*------------------------------------------*/
00088 
00089 template<class T, class S>
00090 std::ostream& operator<<(std::ostream& os, const HASHMAP<T,S>& s)
00091 {
00092   os  << s.size() << std::endl;
00093   for(typename HASHMAP<T,S>::const_iterator p = s.begin(); p!=s.end() ;p++)
00094     {
00095       os << p->first << "->" << p->second << " ";
00096     }
00097   os << std::endl;
00098   return os;
00099 }
00100 
00101 /*------------------------------------------*/
00102 
00103 template<class T, class S>
00104 std::ostream& operator<<(std::ostream& os, const std::map<T,S>& s)
00105 {
00106   os  << s.size() << std::endl;
00107   for(typename std::map<T,S>::const_iterator p = s.begin(); p!=s.end() ;p++)
00108     {
00109       os << p->first << "->" << p->second << " ";
00110     }
00111   os << std::endl;
00112   return os;
00113 }
00114 
00115 
00116 /*---------------------------------------------*/
00117 
00118 
00119 void write_data(const GlobalVector& v,std::ostream& s);
00120 void read_data(       GlobalVector& v,std::istream& s);
00121 
00122 void write_data(const int& v,std::ostream& s);
00123 void read_data(int& v,std::istream& s)       ;
00124 
00125 template<int N,class T>
00126 void write_data(const fixarray<N,T>& v,std::ostream& s);
00127 template<int N,class T>
00128 void read_data(fixarray<N,T>& v,std::istream& s)       ;
00129 
00130 void write_data(const double& v,std::ostream& s);
00131 void read_data(double& v,std::istream& s)       ;
00132 
00133 void write_data(const std::string& v,std::ostream& s);
00134 void read_data(std::string& v,std::istream& s)       ;
00135 
00136 /*---------------------------------------------*/
00137 
00138 template<class T>
00139 void write_data(const std::vector<T>& v,std::ostream& s);
00140 template<class T>
00141 void read_data(std::vector<T>& v,std::istream& s);
00142 
00143 /*---------------------------------------------*/
00144 
00145 template<class T>
00146 void write_data(const std::set<T>& v,std::ostream& s);
00147 template<class T>
00148 void read_data(std::set<T>& v,std::istream& s);
00149 
00150 /*---------------------------------------------*/
00151 
00152 /*---------------------------------------------*/
00153 
00154 template<class T,class S>
00155 void write_data(const std::map<T,S>& v,std::ostream& s)
00156 {
00157   s << v.size() << std::endl;
00158   for (typename std::map<T,S>::const_iterator it = v.begin();it!=v.end();++it)
00159     {
00160       write_data(it->first,s);  s << std::endl;
00161       write_data(it->second,s); s << std::endl;
00162     }
00163 }
00164 
00165 /*---------------------------------------------*/
00166 
00167 template<class T,class S>
00168 void read_data(std::map<T,S>& v,std::istream& s)
00169 {
00170   size_t n;
00171   s >> n;
00172   for (int i=0;i<n;++i)
00173     {
00174       T fi;
00175       S se;
00176       read_data(fi,s);
00177       read_data(se,s);
00178       v[fi]=se;
00179     }
00180 }
00181 
00182 template<class T,class S>
00183 void write_data(const HASHMAP<T,S>& v,std::ostream& s)
00184 {
00185   s << v.size() << std::endl;
00186   for (typename HASHMAP<T,S>::const_iterator it = v.begin();it!=v.end();++it)
00187     {
00188       write_data(it->first,s);  s << std::endl;
00189       write_data(it->second,s); s << std::endl;
00190     }
00191 }
00192 
00193 /*---------------------------------------------*/
00194 
00195 template<class T,class S>
00196 void read_data(HASHMAP<T,S>& v,std::istream& s)
00197 {
00198   size_t n;
00199   s >> n;
00200   for (int i=0;i<n;++i)
00201     {
00202       T fi;
00203       S se;
00204       read_data(fi,s);
00205       read_data(se,s);
00206       v[fi]=se;
00207     }
00208 }
00209 }
00210 
00211 #undef HASHMAP
00212 
00213 #endif
00214 
00215 

Generated on Thu Sep 14 10:34:35 2006 for Gascoigne by  doxygen 1.4.7