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