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