Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 27 | namespace ns3 { |
| 28 | namespace ndn { |
| 29 | namespace ndnSIM { |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 30 | |
| 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 | */ |
| 35 | struct counting_policy_traits |
| 36 | { |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 37 | /// @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 Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 40 | 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 Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 110 | } // ndn |
Alexander Afanasyev | e77db79 | 2012-08-09 11:10:58 -0700 | [diff] [blame] | 111 | } // ns3 |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 112 | |
| 113 | #endif // COUNTING_POLICY_H_ |