blob: 4a74036db90a1d9ff7872dbe0ef7cbb8ff364e88 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070019
20#ifndef COUNTING_POLICY_H_
21#define COUNTING_POLICY_H_
22
23#include <boost/intrusive/options.hpp>
24#include <boost/intrusive/list.hpp>
25
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070026namespace ns3 {
27namespace ndn {
28namespace ndnSIM {
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070029
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 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080034struct counting_policy_traits {
Alexander Afanasyev991a0cc2012-12-10 11:38:19 -080035 /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080036 static std::string
37 GetName()
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070038 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039 return "Counting";
40 }
41
42 struct policy_hook_type : public boost::intrusive::list_member_hook<> {
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070043 };
44
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 template<class Container>
46 struct container_hook {
47 // could be class/struct implementation
48 typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
49 type;
50 };
51
52 template<class Base, class Container, class Hook>
53 struct policy {
54 typedef typename boost::intrusive::list<Container, Hook> policy_container;
55
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070056 // could be just typedef
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 class type : public policy_container {
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070058 public:
59 typedef Container parent_trie;
60
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061 type(Base& base)
62 : base_(base)
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070063 {
64 }
65
66 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 update(typename parent_trie::iterator item)
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070068 {
69 // do nothing
70 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070072 inline bool
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 insert(typename parent_trie::iterator item)
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070074 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 policy_container::push_back(*item);
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070076 return true;
77 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070079 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 lookup(typename parent_trie::iterator item)
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070081 {
82 // do nothing
83 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070085 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 erase(typename parent_trie::iterator item)
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070087 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 policy_container::erase(policy_container::s_iterator_to(*item));
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070089 }
90
91 inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 clear()
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070093 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 policy_container::clear();
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070095 }
96
97 private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 type()
99 : base_(*((Base*)0)){};
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700100
101 private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 Base& base_;
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700103 };
104 };
105};
106
107} // ndnSIM
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700108} // ndn
Alexander Afanasyeve77db792012-08-09 11:10:58 -0700109} // ns3
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700110
111#endif // COUNTING_POLICY_H_