NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
delegation-list.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 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_DELEGATION_LIST_HPP
23 #define NDN_DELEGATION_LIST_HPP
24 
25 #include "ndn-cxx/delegation.hpp"
26 
27 #include <initializer_list>
28 
29 namespace ndn {
30 
38 {
39 public:
40  class Error : public tlv::Error
41  {
42  public:
43  using tlv::Error::Error;
44  };
45 
49 
55  DelegationList(std::initializer_list<Delegation> dels);
56 
60  explicit
61  DelegationList(const Block& block, bool wantSort = true);
62 
69  template<encoding::Tag TAG>
70  size_t
71  wireEncode(EncodingImpl<TAG>& encoder, uint32_t type = tlv::ForwardingHint) const;
72 
78  void
79  wireDecode(const Block& block, bool wantSort = true);
80 
81  bool
82  isSorted() const noexcept
83  {
84  return m_isSorted;
85  }
86 
87  using const_iterator = std::vector<Delegation>::const_iterator;
88 
90  begin() const noexcept
91  {
92  return m_dels.begin();
93  }
94 
96  end() const noexcept
97  {
98  return m_dels.end();
99  }
100 
101  NDN_CXX_NODISCARD bool
102  empty() const noexcept
103  {
104  return m_dels.empty();
105  }
106 
107  size_t
108  size() const noexcept
109  {
110  return m_dels.size();
111  }
112 
116  const Delegation&
117  operator[](size_t i) const
118  {
119  BOOST_ASSERT(i < size());
120  return m_dels[i];
121  }
122 
126  const Delegation&
127  at(size_t i) const
128  {
129  return m_dels.at(i);
130  }
131 
132 public: // modifiers
145  void
146  sort();
147 
154 
159 
162  INS_SKIP
163  };
164 
168  bool
169  insert(uint64_t preference, const Name& name,
171 
175  bool
177  {
178  return this->insert(del.preference, del.name, onConflict);
179  }
180 
184  size_t
185  erase(uint64_t preference, const Name& name)
186  {
187  return this->eraseImpl(preference, name);
188  }
189 
193  size_t
194  erase(const Delegation& del)
195  {
196  return this->eraseImpl(del.preference, del.name);
197  }
198 
202  size_t
203  erase(const Name& name)
204  {
205  return this->eraseImpl(nullopt, name);
206  }
207 
208 private:
209  static bool
210  isValidTlvType(uint32_t type);
211 
212  void
213  insertImpl(uint64_t preference, const Name& name);
214 
215  size_t
216  eraseImpl(optional<uint64_t> preference, const Name& name);
217 
218 private: // non-member operators
219  // NOTE: the following "hidden friend" operators are available via
220  // argument-dependent lookup only and must be defined inline.
221 
226  friend bool
227  operator==(const DelegationList& lhs, const DelegationList& rhs)
228  {
229  return lhs.m_dels == rhs.m_dels;
230  }
231 
232  friend bool
233  operator!=(const DelegationList& lhs, const DelegationList& rhs)
234  {
235  return lhs.m_dels != rhs.m_dels;
236  }
237 
238 private:
239  bool m_isSorted;
240 
248  std::vector<Delegation> m_dels;
249 };
250 
251 #ifndef DOXYGEN
252 extern template size_t
253 DelegationList::wireEncode<encoding::EncoderTag>(EncodingBuffer&, uint32_t) const;
254 
255 extern template size_t
256 DelegationList::wireEncode<encoding::EstimatorTag>(EncodingEstimator&, uint32_t) const;
257 #endif
258 
259 std::ostream&
260 operator<<(std::ostream& os, const DelegationList& dl);
261 
262 } // namespace ndn
263 
264 #endif // NDN_DELEGATION_LIST_HPP
ndn::DelegationList::empty
NDN_CXX_NODISCARD bool empty() const noexcept
Definition: delegation-list.hpp:102
ndn::DelegationList::size
size_t size() const noexcept
Definition: delegation-list.hpp:108
ndn::DelegationList::wireEncode
size_t wireEncode(EncodingImpl< TAG > &encoder, uint32_t type=tlv::ForwardingHint) const
encode into wire format
Definition: delegation-list.cpp:63
ndn::Delegation::name
Name name
Definition: delegation.hpp:84
ndn::DelegationList::operator!=
friend bool operator!=(const DelegationList &lhs, const DelegationList &rhs)
Definition: delegation-list.hpp:233
ndn::DelegationList::operator[]
const Delegation & operator[](size_t i) const
get the i-th delegation
Definition: delegation-list.hpp:117
ndn::tlv::ForwardingHint
@ ForwardingHint
Definition: tlv.hpp:73
ndn::DelegationList::INS_APPEND
@ INS_APPEND
multiple delegations with the same name are kept in the DelegationList
Definition: delegation-list.hpp:158
ndn::DelegationList::DelegationList
DelegationList()
construct an empty DelegationList
Definition: delegation-list.cpp:31
ndn::DelegationList::operator==
friend bool operator==(const DelegationList &lhs, const DelegationList &rhs)
Compare whether two DelegationLists are equal.
Definition: delegation-list.hpp:227
ndn::DelegationList::INS_SKIP
@ INS_SKIP
new delegation is not inserted if an existing delegation has the same name
Definition: delegation-list.hpp:162
ndn::DelegationList::isSorted
bool isSorted() const noexcept
Definition: delegation-list.hpp:82
ndn::DelegationList::Error
Definition: delegation-list.hpp:41
ndn::DelegationList::InsertConflictResolution
InsertConflictResolution
what to do when inserting a duplicate name
Definition: delegation-list.hpp:150
ndn::DelegationList::const_iterator
std::vector< Delegation >::const_iterator const_iterator
Definition: delegation-list.hpp:87
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition: encoding-buffer-fwd.hpp:39
ndn::Delegation
Represents a Delegation.
Definition: delegation.hpp:33
ndn::DelegationList::sort
void sort()
sort the delegation list
Definition: delegation-list.cpp:154
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
ndn::DelegationList::insert
bool insert(uint64_t preference, const Name &name, InsertConflictResolution onConflict=INS_REPLACE)
insert Delegation
Definition: delegation-list.cpp:170
NDN_CXX_NODISCARD
#define NDN_CXX_NODISCARD
Definition: backports.hpp:68
ndn::DelegationList::insert
bool insert(const Delegation &del, InsertConflictResolution onConflict=INS_REPLACE)
insert Delegation
Definition: delegation-list.hpp:176
ndn::DelegationList::end
const_iterator end() const noexcept
Definition: delegation-list.hpp:96
nonstd::optional_lite::nullopt
const nullopt_t nullopt((nullopt_t::init()))
ndn::DelegationList
represents a list of Delegations
Definition: delegation-list.hpp:38
ndn::DelegationList::INS_REPLACE
@ INS_REPLACE
existing delegation(s) with the same name are replaced with the new delegation
Definition: delegation-list.hpp:153
ndn::Delegation::preference
uint64_t preference
Definition: delegation.hpp:83
ndn::encoding::EncodingImpl
Definition: encoding-buffer-fwd.hpp:36
ndn::DelegationList::erase
size_t erase(const Delegation &del)
delete Delegation(s) with matching preference and name
Definition: delegation-list.hpp:194
ndn::Block
Represents a TLV element of NDN packet format.
Definition: block.hpp:43
ndn::operator<<
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:322
ndn::name
Definition: name-component-types.hpp:33
ndn::tlv::Error
represents an error in TLV encoding or decoding
Definition: tlv.hpp:53
ndn::DelegationList::wireDecode
void wireDecode(const Block &block, bool wantSort=true)
decode a DelegationList
Definition: delegation-list.cpp:105
ndn::tlv::Error::Error
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
ndn::DelegationList::begin
const_iterator begin() const noexcept
Definition: delegation-list.hpp:90
ndn::DelegationList::erase
size_t erase(const Name &name)
erase Delegation(s) with specified name
Definition: delegation-list.hpp:203
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition: encoding-buffer-fwd.hpp:38
ndn::DelegationList::erase
size_t erase(uint64_t preference, const Name &name)
delete Delegation(s) with specified preference and name
Definition: delegation-list.hpp:185
ndn::DelegationList::at
const Delegation & at(size_t i) const
get the i-th delegation
Definition: delegation-list.hpp:127
delegation.hpp