00001 // Copyright (C) 2003, 2004, 2005 Laboratoire de Recherche en Informatique 00002 00003 // This file is part of Qolyester. 00004 00005 // Qolyester is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 00010 // Qolyester 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 General Public License for more details. 00014 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 #ifndef QOLYESTER_DAEMON_SET_GATE_HH 00020 # define QOLYESTER_DAEMON_SET_GATE_HH 1 00021 00022 # include <set> 00023 # include "config.hh" 00024 # include "utl/timeval.hh" 00025 # include "utl/set.hh" 00026 # include "net/ipaddress.hh" 00027 00028 namespace olsr { 00029 00030 namespace set { 00031 00032 class GateEntry : public utl::MultiStampable<1, address_t> { 00033 typedef GateEntry This; 00034 typedef utl::MultiStampable<1, address_t> Super; 00035 public: 00036 inline GateEntry(const address_t& naddr, const unsigned prefix); 00037 00038 virtual ~GateEntry() {} 00039 00040 const address_t& net_addr() const { return naddr_; } 00041 # ifndef QOLYESTER_ENABLE_NUMPREFIX 00042 const address_t& netmask_addr() const { return nmask_; } 00043 # endif 00044 const unsigned& prefix() const { return prefix_; } 00045 00046 bool operator<(const This& rhs) const { 00047 if (naddr_ == rhs.naddr_) 00048 return prefix_ < rhs.prefix_; 00049 return naddr_ < rhs.naddr_; 00050 } 00051 private: 00052 const address_t naddr_; 00053 # ifndef QOLYESTER_ENABLE_NUMPREFIX 00054 const address_t nmask_; 00055 # endif 00056 const unsigned prefix_; 00057 }; 00058 00059 class GateSet { 00060 typedef GateSet This; 00061 typedef GateEntry elem_t; 00062 typedef std::set<elem_t> gset_t; 00063 typedef utl::MSIndex<gset_t, 0, address_t> idx_gset_t; 00064 public: 00065 typedef idx_gset_t hna_gset_t; 00066 typedef gset_t::const_iterator const_iterator; 00067 typedef const_iterator iterator; 00068 00069 hna_gset_t& hna_gset() { return hna_gset_; } 00070 00071 inline GateSet(); 00072 00073 iterator begin() const { return gset_.begin(); } 00074 iterator end() const { return gset_.end(); } 00075 00076 inline std::pair<iterator, bool> insert(const gset_t::value_type& x); 00077 00078 inline void erase(iterator pos); 00079 00080 inline bool empty() const; 00081 private: 00082 gset_t gset_; 00083 idx_gset_t hna_gset_; 00084 }; 00085 00086 } // namespace set 00087 00088 typedef set::GateSet gateset_t; 00089 00090 } // namespace olsr 00091 00092 # include "gate.hxx" 00093 00094 #endif // ! QOLYESTER_DAEMON_SET_GATE_HH