blob: 2c8656c82a8d6470b4edbab862ea7f018b70e2f1 [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{
Alexander Afanasyev991a0cc2012-12-10 11:38:19 -080037 /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
38 static std::string GetName () { return "Counting"; }
39
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070040 struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
41
42 template<class Container>
43 struct container_hook
44 {
45 // could be class/struct implementation
46 typedef boost::intrusive::member_hook< Container,
47 policy_hook_type,
48 &Container::policy_hook_ > type;
49 };
50
51 template<class Base,
52 class Container,
53 class Hook>
54 struct policy
55 {
56 typedef typename boost::intrusive::list< Container, Hook > policy_container;
57
58 // could be just typedef
59 class type : public policy_container
60 {
61 public:
62 typedef Container parent_trie;
63
64 type (Base &base)
65 : base_ (base)
66 {
67 }
68
69 inline void
70 update (typename parent_trie::iterator item)
71 {
72 // do nothing
73 }
74
75 inline bool
76 insert (typename parent_trie::iterator item)
77 {
78 policy_container::push_back (*item);
79 return true;
80 }
81
82 inline void
83 lookup (typename parent_trie::iterator item)
84 {
85 // do nothing
86 }
87
88 inline void
89 erase (typename parent_trie::iterator item)
90 {
91 policy_container::erase (policy_container::s_iterator_to (*item));
92 }
93
94 inline void
95 clear ()
96 {
97 policy_container::clear ();
98 }
99
100 private:
101 type () : base_(*((Base*)0)) { };
102
103 private:
104 Base &base_;
105 };
106 };
107};
108
109} // ndnSIM
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700110} // ndn
Alexander Afanasyeve77db792012-08-09 11:10:58 -0700111} // ns3
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700112
113#endif // COUNTING_POLICY_H_