identity-container.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2022 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_CXX_SECURITY_PIB_IDENTITY_CONTAINER_HPP
23 #define NDN_CXX_SECURITY_PIB_IDENTITY_CONTAINER_HPP
24 
26 
27 #include <iterator>
28 #include <set>
29 #include <unordered_map>
30 
31 namespace ndn {
32 namespace security {
33 namespace pib {
34 
35 class Pib;
36 class PibImpl;
37 
38 namespace detail {
39 class IdentityImpl;
40 } // namespace detail
41 
50 class IdentityContainer : noncopyable
51 {
52 private:
53  using NameSet = std::set<Name>;
54 
55 public:
57  {
58  public:
59  using iterator_category = std::forward_iterator_tag;
60  using value_type = const Identity;
61  using difference_type = std::ptrdiff_t;
62  using pointer = value_type*;
64 
65  const_iterator() = default;
66 
67  Identity
68  operator*();
69 
72  {
73  ++m_it;
74  return *this;
75  }
76 
79  {
80  const_iterator it(*this);
81  ++m_it;
82  return it;
83  }
84 
85  bool
86  operator==(const const_iterator& other) const;
87 
88  bool
89  operator!=(const const_iterator& other) const
90  {
91  return !this->operator==(other);
92  }
93 
94  private:
95  const_iterator(NameSet::const_iterator it, const IdentityContainer& container) noexcept;
96 
97  private:
98  NameSet::const_iterator m_it;
99  const IdentityContainer* m_container = nullptr;
100 
101  friend IdentityContainer;
102  };
103 
105 
106 public:
108  begin() const noexcept
109  {
110  return {m_identityNames.begin(), *this};
111  }
112 
113  const_iterator
114  end() const noexcept
115  {
116  return {};
117  }
118 
119  const_iterator
120  find(const Name& identity) const;
121 
125  NDN_CXX_NODISCARD bool
126  empty() const noexcept
127  {
128  return m_identityNames.empty();
129  }
130 
134  size_t
135  size() const noexcept
136  {
137  return m_identityNames.size();
138  }
139 
143  Identity
144  add(const Name& identity);
145 
149  void
150  remove(const Name& identity);
151 
156  Identity
157  get(const Name& identity) const;
158 
164  void
165  reset();
166 
171  bool
172  isConsistent() const;
173 
174 NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: // private interface for Pib
179  explicit
180  IdentityContainer(shared_ptr<PibImpl> pibImpl);
181 
183  // cache of loaded IdentityImpl
184  mutable std::unordered_map<Name, shared_ptr<detail::IdentityImpl>> m_identities;
185 
186 private:
187  NameSet m_identityNames;
188  const shared_ptr<PibImpl> m_pib;
189 
190  friend Pib;
191 };
192 
193 } // namespace pib
194 } // namespace security
195 } // namespace ndn
196 
197 #endif // NDN_CXX_SECURITY_PIB_IDENTITY_CONTAINER_HPP
#define NDN_CXX_NODISCARD
Definition: backports.hpp:68
Represents an absolute name.
Definition: name.hpp:44
bool operator==(const const_iterator &other) const
bool operator!=(const const_iterator &other) const
Container of identities of a PIB.
bool empty() const noexcept
Check whether the container is empty.
size_t size() const noexcept
Return the number of identities in the container.
const_iterator begin() const noexcept
Identity get(const Name &identity) const
Return an identity by name.
const_iterator find(const Name &identity) const
const_iterator end() const noexcept
void remove(const Name &identity)
Remove identity from the container.
Identity add(const Name &identity)
Add identity into the container.
bool isConsistent() const
Check if the container is consistent with the backend storage.
void reset()
Reset the state of the container.
Frontend handle for an identity in the PIB.
Definition: identity.hpp:50
Frontend to the Public Information Base.
Definition: pib.hpp:53
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:48
Definition: data.cpp:25