Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

stltools.Set.h

00001 /*----------------------------------------------------------------------------
00002   SWORD 2000 - Software With Objects for Rapid Development
00003   Copyright (C) 2003 David JOBET
00004   ----------------------------------------------------------------------------
00005   SWORD is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU Lesser General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   SWORD is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public License
00016   along with SWORD; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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         // Implementation for : "cout << set<T>"
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         // Implementation for : "OStream << set<T>"
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         // Implementation for : "IStream << set<T>"
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   // in<> on std::set
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 } // namespace std
00085 
00086 #endif // _SWORD_STLTOOLS_SET_

Generated on Tue Dec 23 20:08:56 2003 for SWORD by doxygen1.3-rc2