00001
00002
00003
00004
00005 #ifndef PRINTABLE_H_
00006 #define PRINTABLE_H_
00007
00008 #include <iostream>
00009 #include <ostream>
00010 #include <vector>
00011 #include <map>
00012
00013 using namespace std;
00014
00015
00016 static bool string_aspas_25072009 = false;
00017 static bool string_aspas_25072009_ctrl = true;
00018
00019
00020
00021
00022
00023
00024
00025 ostream& operator<< (ostream &os, const string &obj)
00026 {
00027 if(string_aspas_25072009 && string_aspas_25072009_ctrl)
00028 {
00029 string_aspas_25072009_ctrl = false;
00030
00031 os << "\"" << obj << "\"";
00032 }
00033 else
00034 {
00035 string_aspas_25072009_ctrl = true;
00036
00037 for(unsigned int i=0;i<obj.length();i++)
00038 if ( (obj[i] == '\"') || (obj[i] == '\\'))
00039 os << '\\' << obj[i];
00040 else
00041 os << obj[i];
00042 }
00043 return os;
00044 }
00045
00046
00047
00048
00049
00050 template<class T>
00051 ostream& operator<< (ostream &os, const vector<T> &obj)
00052 {
00053
00054 string_aspas_25072009 = true;
00055
00056 os << "vector(" << obj.size() << ") [";
00057
00058 if(obj.size()>0)
00059 {
00060 for(unsigned int i = 0; i < obj.size()-1; i++)
00061 os << obj.at(i) << " , ";
00062 os << obj.at(obj.size()-1);
00063 }
00064
00065 os << "]";
00066
00067
00068 string_aspas_25072009 = false;
00069
00070 return os;
00071 }
00072
00073
00074
00075
00076
00077 template<class T>
00078 ostream& operator<< (ostream &os, const vector<T*> &obj)
00079 {
00080
00081 string_aspas_25072009 = true;
00082
00083 os << "vector(" << obj.size() << ") [";
00084
00085 if(obj.size()>0)
00086 {
00087 for(unsigned int i = 0; i < obj.size()-1; i++)
00088 if (obj.at(i) == NULL)
00089 os << "NULL" << " , ";
00090 else
00091 os << (*obj.at(i)) << " , ";
00092
00093 if(obj.size()>0)
00094 {
00095 if (obj.at(obj.size()-1) == NULL)
00096 os << "NULL";
00097 else
00098 os << (*obj.at(obj.size()-1));
00099 }
00100 }
00101
00102 os << "]";
00103
00104
00105 string_aspas_25072009 = false;
00106
00107 return os;
00108 }
00109
00110
00111
00112
00113
00114 template<class T1, class T2>
00115 ostream& operator<< (ostream &os, const pair<T1,T2> &obj)
00116 {
00117
00118 string_aspas_25072009 = true;
00119
00120 os << "pair(" << obj.first << " , " << obj.second << ")";
00121
00122
00123 string_aspas_25072009 = false;
00124
00125 return os;
00126 }
00127
00128
00129
00130
00131 template<class T1, class T2>
00132 ostream& operator<< (ostream &os, const pair<T1,T2*> &obj)
00133 {
00134
00135 string_aspas_25072009 = true;
00136
00137 os << "pair(" << obj.first << " , ";
00138
00139 if(obj.second == NULL)
00140 os << "NULL" << ")";
00141 else
00142 os << (*obj.second) << ")";
00143
00144
00145 string_aspas_25072009 = false;
00146
00147 return os;
00148 }
00149
00150
00151
00152
00153 template<class T1, class T2>
00154 ostream& operator<< (ostream &os, const pair<T1*,T2> &obj)
00155 {
00156
00157 string_aspas_25072009 = true;
00158
00159 os << "pair(";
00160
00161 if(obj.first == NULL)
00162 os << "NULL";
00163 else
00164 os << (*obj.first);
00165
00166 os << " , " << obj.second << ")";
00167
00168
00169 string_aspas_25072009 = false;
00170
00171 return os;
00172 }
00173
00174
00175
00176
00177 template<class T1, class T2>
00178 ostream& operator<< (ostream &os, const pair<T1*,T2*> &obj)
00179 {
00180
00181 string_aspas_25072009 = true;
00182
00183 os << "pair(";
00184
00185 if(obj.first == NULL)
00186 os << "NULL";
00187 else
00188 os << (*obj.first);
00189
00190 os << " , ";
00191
00192 if(obj.second == NULL)
00193 os << "NULL" << ")";
00194 else
00195 os << (*obj.second) << ")";
00196
00197
00198 string_aspas_25072009 = false;
00199
00200 return os;
00201 }
00202
00203
00204
00205
00206
00207 template<class Key, class T>
00208 ostream& operator<< (ostream &os, multimap<Key,T> &obj)
00209 {
00210
00211 string_aspas_25072009 = true;
00212
00213 os << "multimap(" << obj.size() << ") [";
00214
00215 if(obj.size()>0)
00216 {
00217 typename multimap<Key,T>::iterator it;
00218 int i = 0;
00219 for(it = obj.begin(); it != obj.end(); ++it)
00220 {
00221 os << *it;
00222 if (i != obj.size()-1) os << " , "; i++;
00223 }
00224 }
00225
00226 os << "]";
00227
00228
00229 string_aspas_25072009 = false;
00230
00231 return os;
00232 }
00233
00234
00235
00236
00237 template<class Key, class T>
00238 ostream& operator<< (ostream &os, map<Key,T> &obj)
00239 {
00240
00241 string_aspas_25072009 = true;
00242
00243 os << "map(" << obj.size() << ") [";
00244
00245 if(obj.size()>0)
00246 {
00247 typename map<Key,T>::iterator it;
00248 int i = 0;
00249 for(it = obj.begin(); it != obj.end(); ++it)
00250 {
00251 os << *it;
00252 if (i != obj.size()-1) os << " , "; i++;
00253 }
00254 }
00255
00256 os << "]";
00257
00258
00259 string_aspas_25072009 = false;
00260
00261 return os;
00262 }
00263
00264 #endif