stampable.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_UTL_STAMPABLE_HXX
00020 # define QOLYESTER_UTL_STAMPABLE_HXX 1
00021 
00022 # include "stampable.hh"
00023 
00024 namespace olsr {
00025 
00026   namespace utl {
00027 
00028     //
00029     // Stampable methods
00030     //
00031     Stampable::Stampable() : _stamp(0) {}
00032     
00033     bool        
00034     Stampable::expired(const TimeVal& period, const TimeVal& now) const {
00035       return (_stamp + period).is_past(now);
00036     }
00037 
00038     //
00039     // MultiStampable methods
00040     //
00041     // Constructor, generalized version
00042     template <unsigned Dim, class Key, class Compare>
00043     MultiStampable<Dim, Key, Compare>::MultiStampable()
00044       : _stampset()
00045     {}
00046 
00047     // Constructor, specialized version
00048     template <class Key, class Compare>
00049     MultiStampable<1, Key, Compare>::MultiStampable()
00050       : _stampset()
00051     {}
00052 
00053     // Modifier, generalized version
00054     template <unsigned Dim, class Key, class Compare>
00055     void
00056     MultiStampable<Dim, Key, Compare>::set_stamp(unsigned d, const Key& k,
00057                                                  const TimeVal& now) {
00058       assert(d < Dim);
00059       std::pair<typename stampset_t::iterator, bool>    p =
00060         _stampset[d].insert(stampset_t::value_type(k, now));
00061 
00062       if (!p.second)
00063         p.first->second = now;
00064     }
00065 
00066     // Modifier, specialized version
00067     template <class Key, class Compare>
00068     void
00069     MultiStampable<1, Key, Compare>::set_stamp(const Key& k,
00070                                                const TimeVal& now) {
00071       std::pair<typename stampset_t::iterator, bool>    p =
00072         _stampset.insert(typename stampset_t::value_type(k, now));
00073 
00074       if (!p.second)
00075         p.first->second = now;
00076     }
00077 
00078     // Modifier, generalized version
00079     template <unsigned Dim, class Key, class Compare>
00080     void
00081     MultiStampable<Dim, Key, Compare>::remove_stamp(unsigned d, const Key& k) {
00082       _stampset[d].erase(k);
00083     }
00084 
00085     // Modifier, specialized version
00086     template <class Key, class Compare>
00087     void
00088     MultiStampable<1, Key, Compare>::remove_stamp(const Key& k) {
00089       _stampset.erase(k);
00090     }
00091 
00092     // Accessor, generalized version
00093     template <unsigned Dim, class Key, class Compare>
00094     const TimeVal
00095     MultiStampable<Dim, Key, Compare>::stamp(unsigned d, const Key& k) const {
00096       assert(d < Dim);
00097       typename stampset_t::const_iterator       x = _stampset[d].find(k);
00098       if (x == _stampset[d].end())
00099         return TimeVal(0);
00100       return x->second;
00101     }
00102 
00103     // Accessor, specialized version
00104     template <class Key, class Compare>
00105     const TimeVal
00106     MultiStampable<1, Key, Compare>::stamp(const Key& k) const {
00107       typename stampset_t::const_iterator       x = _stampset.find(k);
00108       if (x == _stampset.end())
00109         return TimeVal(0);
00110       return x->second;
00111     }
00112 
00113     // Accessor, generalized version
00114     template <unsigned Dim, class Key, class Compare>
00115     bool
00116     MultiStampable<Dim, Key, Compare>::expired(unsigned d,
00117                                                const Key& k,
00118                                                const TimeVal& period,
00119                                                const TimeVal& now) const {
00120       assert(d < Dim);
00121       return (stamp(d, k) + period).is_past(now);
00122     }
00123 
00124     // Accessor, specialized version
00125     template <class Key, class Compare>
00126     bool
00127     MultiStampable<1, Key, Compare>::expired(const Key& k,
00128                                              const TimeVal& period,
00129                                              const TimeVal& now) const {
00130       return (stamp(k) + period).is_past(now);
00131     }
00132 
00133     // Comparator, generalized version
00134     template <unsigned Dim, class Key, class Compare>
00135     bool
00136     MultiStampable<Dim, Key, Compare>::less(unsigned d, const Key& k,
00137                                             const This& rhs) const {
00138       return stamp(d, k) < rhs.stamp(d, k);
00139     }
00140 
00141     // Comparator, specialized version
00142     template <class Key, class Compare>
00143     bool
00144     MultiStampable<1, Key, Compare>::less(const Key& k,
00145                                           const This& rhs) const {
00146       return stamp(k) < rhs.stamp(k);
00147     }
00148 
00149   } // namespace utl
00150 
00151 } // namespace olsr
00152 
00153 #endif // ! QOLYESTER_UTL_STAMPABLE_HXX

Generated on Mon Sep 4 00:02:16 2006 for Qolyester daemon by  doxygen 1.4.6