NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
persistent-policy.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #ifndef PERSISTENT_POLICY_H_
21 #define PERSISTENT_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 
39 struct persistent_policy_traits {
41  static std::string
42  GetName()
43  {
44  return "Persistent";
45  }
46 
47  struct policy_hook_type : public boost::intrusive::list_member_hook<> {
48  };
49 
50  template<class Container>
51  struct container_hook {
52  typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
53  type;
54  };
55 
56  template<class Base, class Container, class Hook>
57  struct policy {
58  typedef typename boost::intrusive::list<Container, Hook> policy_container;
59 
60  // could be just typedef
61  class type : public policy_container {
62  public:
63  typedef Container parent_trie;
64 
65  type(Base& base)
66  : base_(base)
67  , max_size_(100) // when 0, policy is not enforced
68  {
69  }
70 
71  inline void
72  update(typename parent_trie::iterator item)
73  {
74  // do nothing
75  }
76 
77  inline bool
78  insert(typename parent_trie::iterator item)
79  {
80  if (max_size_ != 0 && policy_container::size() >= max_size_)
81  return false;
82 
83  policy_container::push_back(*item);
84  return true;
85  }
86 
87  inline void
88  lookup(typename parent_trie::iterator item)
89  {
90  // do nothing
91  }
92 
93  inline void
94  erase(typename parent_trie::iterator item)
95  {
96  policy_container::erase(policy_container::s_iterator_to(*item));
97  }
98 
99  inline void
100  clear()
101  {
102  policy_container::clear();
103  }
104 
105  inline void
106  set_max_size(size_t max_size)
107  {
108  max_size_ = max_size;
109  }
110 
111  inline size_t
112  get_max_size() const
113  {
114  return max_size_;
115  }
116 
117  private:
118  // type () : base_(*((Base*)0)) { };
119 
120  private:
121  Base& base_;
122  size_t max_size_;
123  };
124  };
125 };
126 
127 } // ndnSIM
128 } // ndn
129 } // ns3
130 
132 
133 #endif // PERSISTENT_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.