NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
payload-policy.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #ifndef PAYLOAD_POLICY_H_
21 #define PAYLOAD_POLICY_H_
22 
24 
25 #include <boost/intrusive/options.hpp>
26 #include <boost/intrusive/list.hpp>
27 
28 namespace ns3 {
29 namespace ndn {
30 namespace ndnSIM {
31 
35 template<class Member>
36 struct payload_policy_traits {
37  struct policy_hook_type : public boost::intrusive::set_member_hook<> {
38  };
39 
40  template<class Container>
41  struct container_hook {
42  typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
43  type;
44  };
45 
46  template<class Base, class Container, class Hook>
47  struct policy {
48  typedef typename boost::intrusive::list<Container, Hook> policy_container;
49 
50  // could be just typedef
51  class type : public policy_container {
52  public:
53  typedef Container parent_trie;
54 
55  type(Base& base)
56  : base_(base)
57  , max_size_(100)
58  {
59  }
60 
61  inline void
62  update(typename parent_trie::iterator item)
63  {
64  // do relocation
65  policy_container::splice(policy_container::end(), *this,
66  policy_container::s_iterator_to(*item));
67  }
68 
69  inline bool
70  insert(typename parent_trie::iterator item)
71  {
72  if (policy_container::size() >= max_size_) {
73  base_.erase(&(*policy_container::begin()));
74  }
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 relocation
84  policy_container::splice(policy_container::end(), *this,
85  policy_container::s_iterator_to(*item));
86  }
87 
88  inline void
89  erase(typename parent_trie::iterator item)
90  {
91  policy_container::erase(policy_container::s_iterator_to(*item));
92  }
93 
94  inline void
95  clear()
96  {
97  policy_container::clear();
98  }
99 
100  inline void
101  set_max_size(size_t max_size)
102  {
103  max_size_ = max_size;
104  }
105 
106  inline size_t
107  get_max_size() const
108  {
109  return max_size_;
110  }
111 
112  private:
113  type()
114  : base_(*((Base*)0)){};
115 
116  private:
117  Base& base_;
118  size_t max_size_;
119  };
120  };
121 };
122 
123 } // ndnSIM
124 } // ndn
125 } // ns3
126 
128 
129 #endif // PAYLOAD_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.