blob: b7d992e1c50c0b1afc81214e317413697e5e7382 [file] [log] [blame]
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
21#ifndef COUNTING_POLICY_H_
22#define COUNTING_POLICY_H_
23
24#include <boost/intrusive/options.hpp>
25#include <boost/intrusive/list.hpp>
26
27namespace ndnSIM
28{
29
30/**
31 * @brief Traits for policy that just keeps track of number of elements
32 * It's doing a rather expensive job, but just in case it needs to be extended later
33 */
34struct counting_policy_traits
35{
36 struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
37
38 template<class Container>
39 struct container_hook
40 {
41 // could be class/struct implementation
42 typedef boost::intrusive::member_hook< Container,
43 policy_hook_type,
44 &Container::policy_hook_ > type;
45 };
46
47 template<class Base,
48 class Container,
49 class Hook>
50 struct policy
51 {
52 typedef typename boost::intrusive::list< Container, Hook > policy_container;
53
54 // could be just typedef
55 class type : public policy_container
56 {
57 public:
58 typedef Container parent_trie;
59
60 type (Base &base)
61 : base_ (base)
62 {
63 }
64
65 inline void
66 update (typename parent_trie::iterator item)
67 {
68 // do nothing
69 }
70
71 inline bool
72 insert (typename parent_trie::iterator item)
73 {
74 policy_container::push_back (*item);
75 return true;
76 }
77
78 inline void
79 lookup (typename parent_trie::iterator item)
80 {
81 // do nothing
82 }
83
84 inline void
85 erase (typename parent_trie::iterator item)
86 {
87 policy_container::erase (policy_container::s_iterator_to (*item));
88 }
89
90 inline void
91 clear ()
92 {
93 policy_container::clear ();
94 }
95
96 private:
97 type () : base_(*((Base*)0)) { };
98
99 private:
100 Base &base_;
101 };
102 };
103};
104
105} // ndnSIM
106
107#endif // COUNTING_POLICY_H_