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

set/mid.hxx

Go to the documentation of this file.
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_MID_HXX
00020 # define QOLYESTER_DAEMON_SET_MID_HXX 1
00021 
00022 # include "utl/mark.hh"
00023 
00024 # include "mid.hh"
00025 
00026 namespace olsr {
00027 
00028   extern utl::Mark      routes_recomp;
00029 
00030   namespace set {
00031 
00032     MIDEntry::MIDEntry()
00033       : i_addr_(),
00034         m_addr_(),
00035         time_(0, 0)
00036     {}
00037     
00038     MIDEntry::MIDEntry(const address_t& iaddr, 
00039                        const address_t& maddr,
00040                        const timeval_t& vtime)
00041       : i_addr_(iaddr), 
00042         m_addr_(maddr), 
00043         time_(timeval_t::in(vtime))
00044     {}
00045 
00046     bool
00047     MIDEntry::is_valid() const { return !time_.is_past(); }
00048 
00049     void
00050     MIDEntry::set_time(const timeval_t& t) { time_ = t; }
00051 
00052     void
00053     MIDEntry::set_main_addr(const address_t& maddr) {
00054       m_addr_ = maddr;
00055     }
00056 
00057     bool
00058     MIDEntry::operator<(const This& rhs) const {
00059       return i_addr_ < rhs.i_addr_;
00060     }
00061 
00062     MIDEntry&
00063     MIDEntry::operator=(const This& other) {
00064       assert(i_addr_ == other.i_addr_);
00065       assert(m_addr_ == other.m_addr_);
00066       time_ = other.time_;
00067       return *this;
00068     }
00069 
00070     MIDEntry
00071     MIDEntry::make_key(const address_t& iaddr) {
00072       This      tmp = dummy_for_find_;
00073       
00074       const_cast<address_t&>(tmp.i_addr_) = iaddr;
00075 
00076       return tmp;
00077     }
00078 
00079     MIDSet::MIDSet()
00080       : mset_(),
00081         midset_(*this, mset_)
00082     {}
00083 
00084     void
00085     MIDSet::insert(const MIDEntry& x) {
00086       std::pair<mset_t::iterator, bool> p = mset_.insert(x);
00087       if (!p.second) {
00088         sch::TimedEvent*        e = p.first->updater();
00089         scheduler.erase(e);
00090         e->set_next(x.time());
00091         scheduler.insert(e);
00092 
00093         if (p.first->main_addr() != x.main_addr()) {
00094           const_cast<elem_t&>(*p.first).set_main_addr(x.main_addr());
00095           routes_recomp.set_mark();
00096         }
00097         const_cast<elem_t&>(*p.first).set_time(x.time());
00098       } else {
00099         sch::TimedEvent*        e = new updater_t(x.time(),
00100                                                   eraser_t(*this, p.first));
00101         const_cast<elem_t&>(*p.first).set_updater(e);
00102         scheduler.insert(e);
00103         routes_recomp.set_mark();
00104       }
00105     }
00106 
00107     void
00108     MIDSet::erase(const mset_t::iterator& pos) {
00109       sch::TimedEvent*  e = pos->updater();
00110       mset_.erase(pos);
00111       scheduler.destroy(e);
00112       routes_recomp.set_mark();
00113     }
00114 
00115   } // namespace set
00116 
00117 } // namespace olsr
00118 
00119 #endif // ! QOLYESTER_DAEMON_SET_MID_HXX

Generated on Thu Jul 28 21:21:47 2005 for Qolyester daemon by  doxygen 1.4.1