00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _SWORD_STLTOOLS_MAP_
00020 #define _SWORD_STLTOOLS_MAP_
00021
00022 #include <map>
00023 #include "sword/streams.OStream.h"
00024 #include "sword/streams.IStream.h"
00025
00026 namespace std {
00027
00028
00029
00030 template<class IDX, class T>
00031 ostream& operator<<(ostream& lhs, const std::map<IDX,T>& rhs)
00032 {
00033 if (rhs.empty()) lhs << "<empty>";
00034 else
00035 {
00036 lhs << "<";
00037 for(std::map<IDX,T>::const_iterator i=rhs.begin();i!=rhs.end();++i)
00038 {
00039 if (i!=rhs.begin()) lhs << ", ";
00040 lhs << i->first << "=>" << i->second;
00041 }
00042 lhs << ">";
00043 }
00044 return lhs;
00045 }
00046
00047
00048
00049 template<class K, class V>
00050 sword::OStream& operator<<(sword::OStream& lhs, std::map<K, V>& rhs)
00051 {
00052 lhs << rhs.size();
00053 for (std::map<K, V>::const_iterator it = rhs.begin(); it != rhs.end(); ++it)
00054 {
00055 lhs << it->first;
00056 lhs << it->second;
00057 }
00058 return lhs;
00059 }
00060
00061
00062
00063 template<class K, class V>
00064 sword::IStream& operator>>(sword::IStream& lhs, std::map<K, V>& rhs)
00065 {
00066 size_t size;
00067 lhs >> size;
00068 for(size_t i=0; i<size; ++i)
00069 {
00070 K key;
00071 V value;
00072 lhs >> key;
00073 lhs >> value;
00074 rhs[key] = value;
00075 }
00076 return lhs;
00077 }
00078
00079
00080
00081 template<class K, class V>
00082 bool in(const K& value, const std::map<K, V>& v)
00083 {
00084 return v.find(value) != v.end();
00085 }
00086
00087 }
00088
00089 #endif // _SWORD_STLTOOLS_MAP_