Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 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 MULTI_POLICY_H_ |
| 22 | #define MULTI_POLICY_H_ |
| 23 | |
| 24 | #include "detail/multi-type-container.h" |
| 25 | #include "detail/multi-policy-container.h" |
| 26 | #include "detail/functor-hook.h" |
| 27 | |
| 28 | #include <boost/mpl/size.hpp> |
| 29 | #include <boost/mpl/at.hpp> |
| 30 | #include <boost/mpl/range_c.hpp> |
| 31 | #include <boost/mpl/transform.hpp> |
| 32 | #include <boost/mpl/back_inserter.hpp> |
| 33 | #include <boost/mpl/vector.hpp> |
| 34 | |
| 35 | #include <boost/intrusive/options.hpp> |
| 36 | |
| 37 | namespace ndnSIM |
| 38 | { |
| 39 | |
| 40 | template<typename Policies> // e.g., mpl::vector1< lru_policy_traits > |
| 41 | struct multi_policy_traits |
| 42 | { |
| 43 | typedef Policies policy_traits; |
| 44 | |
| 45 | struct getHook { template<class Item> struct apply { typedef typename Item::policy_hook_type type; }; }; |
| 46 | typedef detail::multi_type_container< typename boost::mpl::transform1<policy_traits, getHook>::type > policy_hook_type; |
| 47 | |
| 48 | template<class Container> |
| 49 | struct container_hook |
| 50 | { |
| 51 | typedef policy_hook_type type; |
| 52 | }; |
| 53 | |
| 54 | template<class Base, |
| 55 | class Container, |
| 56 | class Hook> |
| 57 | struct policy |
| 58 | { |
| 59 | typedef boost::mpl::range_c<int, 0, boost::mpl::size<policy_traits>::type::value> policies_range; |
| 60 | |
| 61 | struct getPolicy |
| 62 | { |
| 63 | template<class Number> |
| 64 | struct apply |
| 65 | { |
| 66 | typedef |
| 67 | typename boost::mpl::at_c<policy_traits, Number::value>::type:: |
| 68 | template policy<Base, |
| 69 | Container, |
| 70 | boost::intrusive::function_hook< detail::FunctorHook <Hook, |
| 71 | Container, |
| 72 | Number::value> > >::type |
| 73 | type; |
| 74 | }; |
| 75 | }; |
| 76 | |
| 77 | typedef |
| 78 | typename boost::mpl::transform1<policies_range, |
| 79 | getPolicy, |
| 80 | boost::mpl::back_inserter< boost::mpl::vector0<> > >::type policies; |
| 81 | |
| 82 | |
| 83 | typedef detail::multi_policy_container< Base, policies > policy_container; |
| 84 | |
| 85 | class type : public policy_container |
| 86 | { |
| 87 | public: |
| 88 | typedef Container parent_trie; |
| 89 | |
| 90 | type (Base &base) |
| 91 | : policy_container (base) |
| 92 | { |
| 93 | } |
| 94 | |
| 95 | inline void |
| 96 | update (typename parent_trie::iterator item) |
| 97 | { |
| 98 | policy_container::update (item); |
| 99 | } |
| 100 | |
| 101 | inline bool |
| 102 | insert (typename parent_trie::iterator item) |
| 103 | { |
| 104 | return policy_container::insert (item); |
| 105 | } |
| 106 | |
| 107 | inline void |
| 108 | lookup (typename parent_trie::iterator item) |
| 109 | { |
| 110 | policy_container::lookup (item); |
| 111 | } |
| 112 | |
| 113 | inline void |
| 114 | erase (typename parent_trie::iterator item) |
| 115 | { |
| 116 | policy_container::erase (item); |
| 117 | } |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 118 | |
| 119 | inline void |
| 120 | clear () |
| 121 | { |
| 122 | policy_container::clear (); |
| 123 | } |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 124 | }; |
| 125 | }; |
| 126 | }; |
| 127 | |
| 128 | } // ndnSIM |
| 129 | |
| 130 | #endif // MULTI_POLICY_H_ |