NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_IMPL_CONTAINER_WITH_ON_EMPTY_SIGNAL_HPP
23 #define NDN_IMPL_CONTAINER_WITH_ON_EMPTY_SIGNAL_HPP
24 
26 #include "ndn-cxx/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
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_IMPL_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
Definition: signal.hpp:51
Table::const_iterator iterator
Definition: cs-internal.hpp:41
import common constructs for ndn-cxx library internal use
std::pair< iterator, bool > insert(const value_type &value)
util::Signal< ContainerWithOnEmptySignal< T > > onEmpty
Signal to be fired when container becomes empty.