NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
multi-policy.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #ifndef MULTI_POLICY_H_
21 #define MULTI_POLICY_H_
22 
24 
27 #include "detail/functor-hook.hpp"
28 
29 #include <boost/mpl/size.hpp>
30 #include <boost/mpl/at.hpp>
31 #include <boost/mpl/range_c.hpp>
32 #include <boost/mpl/transform.hpp>
33 #include <boost/mpl/back_inserter.hpp>
34 #include <boost/mpl/vector.hpp>
35 #include <boost/mpl/for_each.hpp>
36 
37 #include <boost/intrusive/options.hpp>
38 
39 namespace ns3 {
40 namespace ndn {
41 namespace ndnSIM {
42 
43 template<typename Policies> // e.g., mpl::vector1< lru_policy_traits >
44 struct multi_policy_traits {
45  typedef Policies policy_traits;
46 
47  struct getHook {
48  template<class Item>
49  struct apply {
50  typedef typename Item::policy_hook_type type;
51  };
52  };
53  typedef detail::multi_type_container<
54  typename boost::mpl::transform1<policy_traits, getHook>::type> policy_hook_type;
55 
56  template<class Container>
57  struct container_hook {
58  typedef policy_hook_type type;
59  };
60 
61  template<class Base, class Container, class Hook>
62  struct policy {
64  policies_range;
65 
66  struct getPolicy {
67  template<class Number>
68  struct apply {
69  typedef typename boost::mpl::at_c<policy_traits, Number::value>::type::
70  template policy<Base, Container,
71  boost::intrusive::function_hook<detail::FunctorHook<Hook, Container,
72  Number::value>>>::type
73  type;
74  };
75  };
76 
77  typedef typename boost::mpl::transform1<policies_range, getPolicy,
78  boost::mpl::back_inserter<boost::mpl::vector0<>>>::type
79  policies;
80 
81  typedef detail::multi_policy_container<Base, policies> policy_container;
82 
83  class type : public policy_container {
84  public:
85  typedef policy policy_base; // to get access to get_time methods from outside
86  typedef Container parent_trie;
87 
88  type(Base& base)
89  : policy_container(base)
90  {
91  }
92 
93  inline void
94  update(typename parent_trie::iterator item)
95  {
96  policy_container::update(item);
97  }
98 
99  inline bool
100  insert(typename parent_trie::iterator item)
101  {
102  return policy_container::insert(item);
103  }
104 
105  inline void
106  lookup(typename parent_trie::iterator item)
107  {
108  policy_container::lookup(item);
109  }
110 
111  inline void
112  erase(typename parent_trie::iterator item)
113  {
114  policy_container::erase(item);
115  }
116 
117  inline void
118  clear()
119  {
120  policy_container::clear();
121  }
122 
123  struct max_size_setter {
124  max_size_setter(policy_container& container, size_t size)
125  : m_container(container)
126  , m_size(size)
127  {
128  }
129 
130  template<typename U>
131  void
132  operator()(U index)
133  {
134  m_container.template get<U::value>().set_max_size(m_size);
135  }
136 
137  private:
138  policy_container& m_container;
139  size_t m_size;
140  };
141 
142  inline void
143  set_max_size(size_t max_size)
144  {
145  boost::mpl::for_each<boost::mpl::range_c<int, 0,
147  max_size_setter(*this, max_size));
148  }
149 
150  inline size_t
151  get_max_size() const
152  {
153  // as max size should be the same everywhere, get the value from the first available policy
154  return policy_container::template get<0>().get_max_size();
155  }
156  };
157  };
158 
159  struct name_getter {
160  name_getter(std::string& name)
161  : m_name(name)
162  {
163  }
164 
165  template<typename U>
166  void
167  operator()(U index)
168  {
169  if (!m_name.empty())
170  m_name += "::";
171  m_name += boost::mpl::at_c<policy_traits, U::value>::type::GetName();
172  }
173 
174  std::string& m_name;
175  };
176 
178  static std::string
179  GetName()
180  {
181  // combine names of all internal policies
182  std::string name;
184  name_getter(name));
185 
186  return name;
187  }
188 };
189 
190 } // ndnSIM
191 } // ndn
192 } // ns3
193 
195 
196 #endif // MULTI_POLICY_H_
Copyright (c) 2011-2015 Regents of the University of California.
Table::const_iterator iterator
Definition: cs-internal.hpp:41
Copyright (c) 2011-2015 Regents of the University of California.