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