blob: ffa2d1a812dd7f56055e9ec4a116c5c2cbbce015 [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
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070027namespace ns3 {
28namespace ndn {
29namespace ndnSIM {
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070030
31/**
32 * @brief Traits for policy that just keeps track of number of elements
33 * It's doing a rather expensive job, but just in case it needs to be extended later
34 */
35struct counting_policy_traits
36{
37 struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
38
39 template<class Container>
40 struct container_hook
41 {
42 // could be class/struct implementation
43 typedef boost::intrusive::member_hook< Container,
44 policy_hook_type,
45 &Container::policy_hook_ > type;
46 };
47
48 template<class Base,
49 class Container,
50 class Hook>
51 struct policy
52 {
53 typedef typename boost::intrusive::list< Container, Hook > policy_container;
54
55 // could be just typedef
56 class type : public policy_container
57 {
58 public:
59 typedef Container parent_trie;
60
61 type (Base &base)
62 : base_ (base)
63 {
64 }
65
66 inline void
67 update (typename parent_trie::iterator item)
68 {
69 // do nothing
70 }
71
72 inline bool
73 insert (typename parent_trie::iterator item)
74 {
75 policy_container::push_back (*item);
76 return true;
77 }
78
79 inline void
80 lookup (typename parent_trie::iterator item)
81 {
82 // do nothing
83 }
84
85 inline void
86 erase (typename parent_trie::iterator item)
87 {
88 policy_container::erase (policy_container::s_iterator_to (*item));
89 }
90
91 inline void
92 clear ()
93 {
94 policy_container::clear ();
95 }
96
97 private:
98 type () : base_(*((Base*)0)) { };
99
100 private:
101 Base &base_;
102 };
103 };
104};
105
106} // ndnSIM
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700107} // ndn
Alexander Afanasyeve77db792012-08-09 11:10:58 -0700108} // ns3
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700109
110#endif // COUNTING_POLICY_H_