blob: d27f91555f7efb8d258fee04db1062e6fc088e24 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
9 */
10
11#ifndef COUNTING_POLICY_H_
12#define COUNTING_POLICY_H_
13
14#include <boost/intrusive/options.hpp>
15#include <boost/intrusive/list.hpp>
16
17namespace ndn {
18namespace trie {
19
20/**
21 * @brief Traits for policy that just keeps track of number of elements
22 * It's doing a rather expensive job, but just in case it needs to be extended later
23 */
24struct counting_policy_traits
25{
26 /// @brief Name that can be used to identify the policy (e.g., for logging)
27 static std::string GetName () { return "Counting"; }
28
29 struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
30
31 template<class Container>
32 struct container_hook
33 {
34 // could be class/struct implementation
35 typedef boost::intrusive::member_hook< Container,
36 policy_hook_type,
37 &Container::policy_hook_ > type;
38 };
39
40 template<class Base,
41 class Container,
42 class Hook>
43 struct policy
44 {
45 typedef typename boost::intrusive::list< Container, Hook > policy_container;
46
47 // could be just typedef
48 class type : public policy_container
49 {
50 public:
51 typedef Container parent_trie;
52
53 type (Base &base)
54 : base_ (base)
55 {
56 }
57
58 inline void
59 update (typename parent_trie::iterator item)
60 {
61 // do nothing
62 }
63
64 inline bool
65 insert (typename parent_trie::iterator item)
66 {
67 policy_container::push_back (*item);
68 return true;
69 }
70
71 inline void
72 lookup (typename parent_trie::iterator item)
73 {
74 // do nothing
75 }
76
77 inline void
78 erase (typename parent_trie::iterator item)
79 {
80 policy_container::erase (policy_container::s_iterator_to (*item));
81 }
82
83 inline void
84 clear ()
85 {
86 policy_container::clear ();
87 }
88
89 private:
90 type () : base_(*((Base*)0)) { };
91
92 private:
93 Base &base_;
94 };
95 };
96};
97
98} // trie
99} // ndn
100
101#endif // COUNTING_POLICY_H_