NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
identity-container.cpp
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 
26 
27 namespace ndn {
28 namespace security {
29 namespace pib {
30 
32 
34  : m_container(nullptr)
35 {
36 }
37 
38 IdentityContainer::const_iterator::const_iterator(std::set<Name>::const_iterator it,
39  const IdentityContainer& container)
40  : m_it(it)
41  , m_container(&container)
42 {
43 }
44 
47 {
48  BOOST_ASSERT(m_container != nullptr);
49  return m_container->get(*m_it);
50 }
51 
54 {
55  ++m_it;
56  return *this;
57 }
58 
61 {
62  const_iterator it(*this);
63  ++m_it;
64  return it;
65 }
66 
67 bool
69 {
70  bool isThisEnd = m_container == nullptr || m_it == m_container->m_identityNames.end();
71  bool isOtherEnd = other.m_container == nullptr || other.m_it == other.m_container->m_identityNames.end();
72  return ((isThisEnd || isOtherEnd) ?
73  (isThisEnd == isOtherEnd) :
74  m_container->m_pibImpl == other.m_container->m_pibImpl && m_it == other.m_it);
75 }
76 
77 bool
79 {
80  return !(*this == other);
81 }
82 
83 IdentityContainer::IdentityContainer(shared_ptr<PibImpl> pibImpl)
84  : m_pibImpl(std::move(pibImpl))
85 {
86  BOOST_ASSERT(m_pibImpl != nullptr);
87  m_identityNames = m_pibImpl->getIdentities();
88 }
89 
92 {
93  return const_iterator(m_identityNames.begin(), *this);
94 }
95 
98 {
99  return const_iterator();
100 }
101 
103 IdentityContainer::find(const Name& identity) const
104 {
105  return const_iterator(m_identityNames.find(identity), *this);
106 }
107 
108 size_t
110 {
111  return m_identityNames.size();
112 }
113 
114 Identity
115 IdentityContainer::add(const Name& identityName)
116 {
117  if (m_identityNames.count(identityName) == 0) {
118  m_identityNames.insert(identityName);
119  m_identities[identityName] = make_shared<detail::IdentityImpl>(identityName, m_pibImpl, true);
120  }
121  return get(identityName);
122 }
123 
124 void
125 IdentityContainer::remove(const Name& identityName)
126 {
127  m_identityNames.erase(identityName);
128  m_identities.erase(identityName);
129  m_pibImpl->removeIdentity(identityName);
130 }
131 
132 Identity
133 IdentityContainer::get(const Name& identityName) const
134 {
135  shared_ptr<detail::IdentityImpl> id;
136  auto it = m_identities.find(identityName);
137 
138  if (it != m_identities.end()) {
139  id = it->second;
140  }
141  else {
142  id = make_shared<detail::IdentityImpl>(identityName, m_pibImpl, false);
143  m_identities[identityName] = id;
144  }
145  return Identity(id);
146 }
147 
148 void
150 {
151  m_identities.clear();
152  m_identityNames = m_pibImpl->getIdentities();
153 }
154 
155 bool
157 {
158  return m_identityNames == m_pibImpl->getIdentities();
159 }
160 
161 } // namespace pib
162 } // namespace security
163 } // namespace ndn
ndn::security::pib::IdentityContainer::const_iterator::operator*
Identity operator*()
Definition: identity-container.cpp:46
identity-impl.hpp
ndn::security::pib::IdentityContainer::end
const_iterator end() const
Definition: identity-container.cpp:97
ndn::security::pib::IdentityContainer::remove
void remove(const Name &identity)
Remove identity from the container.
Definition: identity-container.cpp:125
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:421
ndn::security::pib::IdentityContainer::get
Identity get(const Name &identity) const
Get identity from the container.
Definition: identity-container.cpp:133
concepts.hpp
ndn::security::pib::IdentityContainer::begin
const_iterator begin() const
Definition: identity-container.cpp:91
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
identity-container.hpp
ndn::security::pib::IdentityContainer::reset
void reset()
Reset state of the container.
Definition: identity-container.cpp:149
ndn::security::pib::IdentityContainer::add
Identity add(const Name &identityName)
Add identity into the container.
Definition: identity-container.cpp:115
ndn::security::pib::IdentityContainer::const_iterator::operator!=
bool operator!=(const const_iterator &other)
Definition: identity-container.cpp:78
ndn::security::pib::IdentityContainer::size
size_t size() const
Definition: identity-container.cpp:109
ndn::security::pib::IdentityContainer::const_iterator::operator==
bool operator==(const const_iterator &other)
Definition: identity-container.cpp:68
ndn::security::pib::IdentityContainer::const_iterator::operator++
const_iterator & operator++()
Definition: identity-container.cpp:53
ndn::security::pib::IdentityContainer::const_iterator::const_iterator
const_iterator()
Definition: identity-container.cpp:33
ndn::security::pib::IdentityContainer
Container of identities of a Pib.
Definition: identity-container.hpp:48
ndn::security::pib::Identity
A frontend handle of an Identity.
Definition: identity.hpp:43
ndn::security::pib::IdentityContainer::isConsistent
bool isConsistent() const
Check if the container is consistent with the backend storage.
Definition: identity-container.cpp:156
pib-impl.hpp
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::security::pib::NDN_CXX_ASSERT_FORWARD_ITERATOR
NDN_CXX_ASSERT_FORWARD_ITERATOR(CertificateContainer::const_iterator)
ndn::security::pib::IdentityContainer::const_iterator
Definition: identity-container.hpp:51
ndn::security::pib::IdentityContainer::find
const_iterator find(const Name &keyId) const
Definition: identity-container.cpp:103