00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00040
00041
00042 template <unsigned Dim, class Key, class Compare>
00043 MultiStampable<Dim, Key, Compare>::MultiStampable()
00044 : _stampset()
00045 {}
00046
00047
00048 template <class Key, class Compare>
00049 MultiStampable<1, Key, Compare>::MultiStampable()
00050 : _stampset()
00051 {}
00052
00053
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
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
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
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
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
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
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
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
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
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 }
00150
00151 }
00152
00153 #endif // ! QOLYESTER_UTL_STAMPABLE_HXX