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; -*- */
22 #include "identity-container.hpp"
23 #include "pib-impl.hpp"
24 #include "detail/identity-impl.hpp"
25 #include "util/concepts.hpp"
26 
27 namespace ndn {
28 namespace security {
29 namespace pib {
30 
31 NDN_CXX_ASSERT_FORWARD_ITERATOR(IdentityContainer::const_iterator);
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(pibImpl)
85 {
86  BOOST_ASSERT(pibImpl != nullptr);
87  m_identityNames = 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] =
120  shared_ptr<detail::IdentityImpl>(new detail::IdentityImpl(identityName, m_pibImpl, true));
121  }
122  return get(identityName);
123 }
124 
125 void
126 IdentityContainer::remove(const Name& identityName)
127 {
128  m_identityNames.erase(identityName);
129  m_identities.erase(identityName);
130  m_pibImpl->removeIdentity(identityName);
131 }
132 
133 Identity
134 IdentityContainer::get(const Name& identityName) const
135 {
136  shared_ptr<detail::IdentityImpl> id;
137  auto it = m_identities.find(identityName);
138 
139  if (it != m_identities.end()) {
140  id = it->second;
141  }
142  else {
143  id = shared_ptr<detail::IdentityImpl>(new detail::IdentityImpl(identityName, m_pibImpl, false));
144  m_identities[identityName] = id;
145  }
146  return Identity(id);
147 }
148 
149 void
151 {
152  m_identities.clear();
153  m_identityNames = m_pibImpl->getIdentities();
154 }
155 
156 bool
158 {
159  return m_identityNames == m_pibImpl->getIdentities();
160 }
161 
162 } // namespace pib
163 } // namespace security
164 } // namespace ndn
Identity get(const Name &identity) const
Get identity from the container.
Backend instance of Identity.
void remove(const Name &identity)
Remove identity from the container.
Copyright (c) 2011-2015 Regents of the University of California.
void reset()
Reset state of the container.
NDN_CXX_ASSERT_FORWARD_ITERATOR(CertificateContainer::const_iterator)
Identity add(const Name &identityName)
Add identity into the container.
const_iterator find(const Name &keyId) const
Represents an absolute name.
Definition: name.hpp:42
Container of identities of a Pib.
bool isConsistent() const
Check if the container is consistent with the backend storage.
A frontend handle of an Identity.
Definition: identity.hpp:42