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