21 #ifndef LIFETIME_STATS_POLICY_H_
22 #define LIFETIME_STATS_POLICY_H_
24 #include <boost/intrusive/options.hpp>
25 #include <boost/intrusive/list.hpp>
27 #include <ns3/nstime.h>
28 #include <ns3/simulator.h>
29 #include <ns3/traced-callback.h>
41 static std::string
GetName () {
return "LifetimeStats"; }
43 struct policy_hook_type :
public boost::intrusive::list_member_hook<> { Time timeWhenAdded; };
45 template<
class Container>
48 typedef boost::intrusive::member_hook< Container,
50 &Container::policy_hook_ > type;
58 typedef typename boost::intrusive::list< Container, Hook > policy_container;
60 static Time& get_time (
typename Container::iterator item)
62 return static_cast<typename policy_container::value_traits::hook_type*
>
63 (policy_container::value_traits::to_node_ptr(*item))->timeWhenAdded;
66 static const Time& get_time (
typename Container::const_iterator item)
68 return static_cast<const typename policy_container::value_traits::hook_type*
>
69 (policy_container::value_traits::to_node_ptr(*item))->timeWhenAdded;
72 class type :
public policy_container
76 typedef Container parent_trie;
81 , m_willRemoveEntry (0)
86 update (
typename parent_trie::iterator item)
92 insert (
typename parent_trie::iterator item)
94 get_time (item) = Simulator::Now ();
96 policy_container::push_back (*item);
101 lookup (
typename parent_trie::iterator item)
107 erase (
typename parent_trie::iterator item)
109 Time lifetime = Simulator::Now () - get_time (item);
111 if (m_willRemoveEntry != 0)
113 (*m_willRemoveEntry) (item->payload (), lifetime);
116 policy_container::erase (policy_container::s_iterator_to (*item));
122 policy_container::clear ();
126 set_max_size (
size_t max_size)
128 max_size_ = max_size;
132 get_max_size ()
const
138 set_traced_callback (TracedCallback< typename parent_trie::payload_traits::const_base_type, Time > *callback)
140 m_willRemoveEntry = callback;
144 type () : base_(*((Base*)0)) { };
150 TracedCallback< typename parent_trie::payload_traits::const_base_type, Time > *m_willRemoveEntry;
159 #endif // LIFETIME_STATS_POLICY_H
static std::string GetName()
Name that can be used to identify the policy (for NS-3 object model and logging)
Traits for lifetime stats policy.