blob: 386cb2e16485455328b2256297384e07cac78244 [file] [log] [blame]
Alexander Afanasyev30cb1172012-07-06 10:47:39 -07001/* -*- 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
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070037namespace ns3 {
38namespace ndn {
39namespace ndnSIM {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070040
41template<typename Policies> // e.g., mpl::vector1< lru_policy_traits >
42struct multi_policy_traits
43{
44 typedef Policies policy_traits;
45
46 struct getHook { template<class Item> struct apply { typedef typename Item::policy_hook_type type; }; };
47 typedef detail::multi_type_container< typename boost::mpl::transform1<policy_traits, getHook>::type > policy_hook_type;
48
49 template<class Container>
50 struct container_hook
51 {
52 typedef policy_hook_type type;
53 };
54
55 template<class Base,
56 class Container,
57 class Hook>
58 struct policy
59 {
60 typedef boost::mpl::range_c<int, 0, boost::mpl::size<policy_traits>::type::value> policies_range;
61
62 struct getPolicy
63 {
64 template<class Number>
65 struct apply
66 {
67 typedef
68 typename boost::mpl::at_c<policy_traits, Number::value>::type::
69 template policy<Base,
70 Container,
71 boost::intrusive::function_hook< detail::FunctorHook <Hook,
72 Container,
73 Number::value> > >::type
74 type;
75 };
76 };
77
78 typedef
79 typename boost::mpl::transform1<policies_range,
80 getPolicy,
81 boost::mpl::back_inserter< boost::mpl::vector0<> > >::type policies;
82
83
84 typedef detail::multi_policy_container< Base, policies > policy_container;
85
86 class type : public policy_container
87 {
88 public:
89 typedef Container parent_trie;
90
91 type (Base &base)
92 : policy_container (base)
93 {
94 }
95
96 inline void
97 update (typename parent_trie::iterator item)
98 {
99 policy_container::update (item);
100 }
101
102 inline bool
103 insert (typename parent_trie::iterator item)
104 {
105 return policy_container::insert (item);
106 }
107
108 inline void
109 lookup (typename parent_trie::iterator item)
110 {
111 policy_container::lookup (item);
112 }
113
114 inline void
115 erase (typename parent_trie::iterator item)
116 {
117 policy_container::erase (item);
118 }
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700119
120 inline void
121 clear ()
122 {
123 policy_container::clear ();
124 }
Alexander Afanasyev30cb1172012-07-06 10:47:39 -0700125 };
126 };
127};
128
129} // ndnSIM
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700130} // ndn
Alexander Afanasyeve77db792012-08-09 11:10:58 -0700131} // ns3
Alexander Afanasyev30cb1172012-07-06 10:47:39 -0700132
133#endif // MULTI_POLICY_H_