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-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_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  Error(const std::string& what, const std::exception& innerException);
46  };
47 
51 
57  DelegationList(std::initializer_list<Delegation> dels);
58 
62  explicit
63  DelegationList(const Block& block, bool wantSort = true);
64 
71  template<encoding::Tag TAG>
72  size_t
73  wireEncode(EncodingImpl<TAG>& encoder, uint32_t type = tlv::ForwardingHint) const;
74 
80  void
81  wireDecode(const Block& block, bool wantSort = true);
82 
83  bool
84  isSorted() const noexcept
85  {
86  return m_isSorted;
87  }
88 
89  using const_iterator = std::vector<Delegation>::const_iterator;
90 
92  begin() const noexcept
93  {
94  return m_dels.begin();
95  }
96 
98  end() const noexcept
99  {
100  return m_dels.end();
101  }
102 
103  bool
104  empty() const noexcept
105  {
106  return m_dels.empty();
107  }
108 
109  size_t
110  size() const noexcept
111  {
112  return m_dels.size();
113  }
114 
118  const Delegation&
119  operator[](size_t i) const
120  {
121  BOOST_ASSERT(i < size());
122  return m_dels[i];
123  }
124 
128  const Delegation&
129  at(size_t i) const
130  {
131  return m_dels.at(i);
132  }
133 
134 public: // modifiers
147  void
148  sort();
149 
156 
161 
165  };
166 
170  bool
171  insert(uint64_t preference, const Name& name,
173 
177  bool
179  {
180  return this->insert(del.preference, del.name, onConflict);
181  }
182 
186  size_t
187  erase(uint64_t preference, const Name& name)
188  {
189  return this->eraseImpl(preference, name);
190  }
191 
195  size_t
196  erase(const Delegation& del)
197  {
198  return this->eraseImpl(del.preference, del.name);
199  }
200 
204  size_t
205  erase(const Name& name)
206  {
207  return this->eraseImpl(nullopt, name);
208  }
209 
210 private:
211  static bool
212  isValidTlvType(uint32_t type);
213 
214  void
215  insertImpl(uint64_t preference, const Name& name);
216 
217  size_t
218  eraseImpl(optional<uint64_t> preference, const Name& name);
219 
220 private:
221  bool m_isSorted;
222 
230  std::vector<Delegation> m_dels;
231 
232  friend bool operator==(const DelegationList&, const DelegationList&);
233 };
234 
235 #ifndef DOXYGEN
236 extern template size_t
237 DelegationList::wireEncode<encoding::EncoderTag>(EncodingBuffer&, uint32_t) const;
238 
239 extern template size_t
240 DelegationList::wireEncode<encoding::EstimatorTag>(EncodingEstimator&, uint32_t) const;
241 #endif
242 
247 bool
248 operator==(const DelegationList& lhs, const DelegationList& rhs);
249 
250 inline bool
251 operator!=(const DelegationList& lhs, const DelegationList& rhs)
252 {
253  return !(lhs == rhs);
254 }
255 
256 std::ostream&
257 operator<<(std::ostream& os, const DelegationList& dl);
258 
259 } // namespace ndn
260 
261 #endif // NDN_DELEGATION_LIST_HPP
Copyright (c) 2011-2015 Regents of the University of California.
existing delegation(s) with the same name are replaced with the new delegation
const Delegation & at(size_t i) const
get the i-th delegation
new delegation is not inserted if an existing delegation has the same name
DelegationList()
construct an empty DelegationList
uint64_t preference
Definition: delegation.hpp:34
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:322
const Delegation & operator[](size_t i) const
get the i-th delegation
friend bool operator==(const DelegationList &, const DelegationList &)
compare whether two DelegationLists are equal
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
Error(const std::string &what, const std::exception &innerException)
represents a delegation
Definition: delegation.hpp:32
std::vector< Delegation >::const_iterator const_iterator
size_t erase(uint64_t preference, const Name &name)
delete Delegation(s) with specified preference and name
size_t erase(const Name &name)
erase Delegation(s) with specified name
bool operator!=(const Data &lhs, const Data &rhs)
Definition: data.hpp:262
void wireDecode(const Block &block, bool wantSort=true)
decode a DelegationList
const_iterator end() const noexcept
bool insert(const Delegation &del, InsertConflictResolution onConflict=INS_REPLACE)
insert Delegation
bool isSorted() const noexcept
size_t wireEncode(EncodingImpl< TAG > &encoder, uint32_t type=tlv::ForwardingHint) const
encode into wire format
size_t size() const noexcept
Represents an absolute name.
Definition: name.hpp:43
bool insert(uint64_t preference, const Name &name, InsertConflictResolution onConflict=INS_REPLACE)
insert Delegation
InsertConflictResolution
what to do when inserting a duplicate name
size_t erase(const Delegation &del)
delete Delegation(s) with matching preference and name
void sort()
sort the delegation list
bool empty() const noexcept
represents a list of Delegations
bool operator==(const Data &lhs, const Data &rhs)
Definition: data.cpp:313
multiple delegations with the same name are kept in the DelegationList
EncodingImpl< EncoderTag > EncodingBuffer
const nullopt_t nullopt((nullopt_t::init()))
represents an error in TLV encoding or decoding
Definition: tlv.hpp:52
EncodingImpl< EstimatorTag > EncodingEstimator
const_iterator begin() const noexcept