Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

OpSet.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_OPSET_H 00002 #define TAGCOLL_OPSET_H 00003 00004 /* 00005 * std::set with operators overridden with set operations 00006 * 00007 * Copyright (C) 2003 Enrico Zini <enrico@debian.org> 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 * This library is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 /* 00025 * The reason for not using a plain std::set is that libtagcoll involves a lot 00026 * of set operations, and overridden operators greatly help having cleaner code 00027 */ 00028 00029 /* TODO: replace + with | and ^ with &, since logical operators better 00030 * correspond to set operations */ 00031 00032 #pragma interface 00033 00034 #include <set> 00035 00036 namespace Tagcoll 00037 { 00038 00057 template<class T> 00058 class OpSet : public std::set<T> 00059 { 00060 public: 00061 using std::set<T>::begin; 00062 using std::set<T>::end; 00063 00064 // Return true if the tag set contains tag, else false 00065 bool contains(const T& item) const throw () { return find(item) != end(); } 00066 00067 // Return true if the tag set contains ts, else false 00068 bool contains(const OpSet<T>& ts) const throw (); 00069 00070 // Find the distance between two tagsets 00071 // The distance between A and B is defined by infinity if the intersection 00072 // between A and B is empty, else it is | (A + B) - (A ^ B) | 00073 // That is, the cardinality of ((A <union> B) <difference> (A <intersection> B)) 00074 // Return -1 if the distance is infinity 00075 int distance(const OpSet<T>& ts) const throw (); 00076 00081 OpSet<T> operator+(const T& tag) const throw (); 00082 00087 OpSet<T>& operator+=(const T& ts) throw (); 00088 00093 OpSet<T> operator+(const OpSet<T>& ts) const throw (); 00094 00099 OpSet<T>& operator+=(const OpSet<T>& ts) throw (); 00100 00105 OpSet<T> operator-(const T& tag) const throw (); 00106 00111 OpSet<T>& operator-=(const T& tag) throw (); 00112 00117 OpSet<T> operator-(const OpSet<T>& ts) const throw (); 00118 00123 OpSet<T>& operator-=(const OpSet<T>& ts) throw (); 00124 00129 OpSet<T> operator^(const OpSet<T>& ts) const throw (); 00130 00135 OpSet<T>& operator^=(const OpSet<T>& ts) throw (); 00136 }; 00137 00138 }; 00139 00140 // vim:set ts=4 sw=4: 00141 #endif

Generated on Sun Aug 15 12:51:56 2004 for libtagcoll by doxygen 1.3.8