xorp

elem_set.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2001-2011 XORP, Inc and Others
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License, Version 2, June
00008 // 1991 as published by the Free Software Foundation. Redistribution
00009 // and/or modification of this program under the terms of any other
00010 // version of the GNU General Public License is not permitted.
00011 // 
00012 // This program is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00015 // see the GNU General Public License, Version 2, a copy of which can be
00016 // found in the XORP LICENSE.gpl file.
00017 // 
00018 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00019 // http://xorp.net
00020 
00021 // $XORP: xorp/policy/common/elem_set.hh,v 1.14 2008/10/02 21:58:06 bms Exp $
00022 
00023 #ifndef __POLICY_COMMON_ELEM_SET_HH__
00024 #define __POLICY_COMMON_ELEM_SET_HH__
00025 
00026 #include "element_base.hh"
00027 #include "element.hh"
00028 
00029 
00030 
00031 class ElemSet : public Element {
00032 public:
00033     ElemSet(Hash hash) : Element(hash) {}
00034     virtual ~ElemSet() {}
00035 
00036     virtual void erase(const ElemSet&) = 0;
00037 };
00038 
00045 template <class T> 
00046 class ElemSetAny : public ElemSet {
00047 public:
00048     typedef set<T> Set;
00049     typedef typename Set::iterator iterator;
00050     typedef typename Set::const_iterator const_iterator;
00051 
00052     static const char* id;
00053     static Hash _hash;
00054 
00055     ElemSetAny(const Set& val);
00056 
00060     ElemSetAny(const char* c_str);
00061     ElemSetAny();
00062 
00066     string str() const;
00067 
00071     void insert(const T& s);
00072 
00078     void insert(const ElemSetAny<T>& s);
00079 
00085     bool operator==(const ElemSetAny<T>& rhs) const;
00086     
00092     bool operator!=(const ElemSetAny<T>& rhs) const;
00093 
00099     bool operator<(const ElemSetAny<T>& rhs) const;
00100 
00106     bool operator>(const ElemSetAny<T>& rhs) const;
00107 
00113     bool operator<=(const ElemSetAny<T>& rhs) const;
00114 
00120     bool operator>=(const ElemSetAny<T>& rhs) const;
00121 
00129     bool operator<(const T& rhs) const;
00130     
00139     bool operator>(const T& rhs) const;
00140 
00148     bool operator==(const T& rhs) const;
00149 
00157     bool operator!=(const T& rhs) const;
00158 
00166     bool operator<=(const T& rhs) const;
00167 
00175     bool operator>=(const T& rhs) const;
00176 
00180     bool nonempty_intersection(const ElemSetAny<T>& rhs) const;
00181 
00187     void erase(const ElemSetAny<T>& rhs);
00188     void erase(const ElemSet& rhs);
00189 
00195     iterator begin();
00196 
00202     iterator end(); 
00203     
00209     const_iterator begin() const;
00210 
00216     const_iterator end() const;
00217 
00218     const char* type() const;
00219 
00220 private:
00221     Set _val;
00222 };
00223 
00224 // define set types
00225 typedef ElemSetAny<ElemU32> ElemSetU32;
00226 typedef ElemSetAny<ElemCom32> ElemSetCom32;
00227 typedef ElemSetAny<ElemIPv4Net> ElemSetIPv4Net;
00228 typedef ElemSetAny<ElemIPv6Net> ElemSetIPv6Net;
00229 typedef ElemSetAny<ElemStr> ElemSetStr;
00230 
00231 #endif // __POLICY_COMMON_ELEM_SET_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations