NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
container-with-on-empty-signal.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_DETAIL_CONTAINER_WITH_ON_EMPTY_SIGNAL_HPP
23 #define NDN_DETAIL_CONTAINER_WITH_ON_EMPTY_SIGNAL_HPP
24 
25 #include "../common.hpp"
26 #include "../util/signal.hpp"
27 
28 namespace ndn {
29 
33 template<class T>
35 {
36 public:
37  typedef std::list<T> Base;
38  typedef typename Base::value_type value_type;
39  typedef typename Base::iterator iterator;
40 
41  iterator
43  {
44  return m_container.begin();
45  }
46 
47  iterator
48  end()
49  {
50  return m_container.end();
51  }
52 
53  size_t
54  size()
55  {
56  return m_container.size();
57  }
58 
59  bool
61  {
62  return m_container.empty();
63  }
64 
65  iterator
66  erase(iterator item)
67  {
68  iterator next = m_container.erase(item);
69  if (empty()) {
70  this->onEmpty();
71  }
72  return next;
73  }
74 
75  void
77  {
78  m_container.clear();
79  this->onEmpty();
80  }
81 
82  std::pair<iterator, bool>
83  insert(const value_type& value)
84  {
85  return {m_container.insert(end(), value), true};
86  }
87 
88  template<class Predicate>
89  void remove_if(Predicate p)
90  {
91  m_container.remove_if(p);
92  if (empty()) {
93  this->onEmpty();
94  }
95  }
96 
97 public:
99 
104 };
105 
106 } // namespace ndn
107 
108 #endif // NDN_DETAIL_CONTAINER_WITH_ON_EMPTY_SIGNAL_HPP
Copyright (c) 2011-2015 Regents of the University of California.
A container that emits onEmpty signal when it becomes empty.
provides a lightweight signal / event system
Table::const_iterator iterator
Definition: cs-internal.hpp:41
std::pair< iterator, bool > insert(const value_type &value)
util::Signal< ContainerWithOnEmptySignal< T > > onEmpty
Signal to be fired when container becomes empty.