delegation-set.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_DELEGATION_SET_HPP
23 #define NDN_DELEGATION_SET_HPP
24 
25 #include "name.hpp"
26 #include "lite/delegation-set-lite.hpp"
27 
28 namespace ndn {
29 
39 public:
44  {
45  }
46 
51  DelegationSet(const DelegationSet& delegationSet)
52  // A DelegationSet::Delegation is immutable, so just make a shallow copy.
53  : delegations_(delegationSet.delegations_)
54  {
55  }
56 
60  class Delegation {
61  public:
67  Delegation(int preference, const Name& name)
68  : preference_(preference), name_(name)
69  {
70  }
71 
76  Delegation(const DelegationSetLite::Delegation& delegationLite);
77 
82  int
83  getPreference() const { return preference_; }
84 
89  const Name&
90  getName() const { return name_; }
91 
99  int
100  compare(const Delegation& other);
101 
110  void
111  get(DelegationSetLite::Delegation& delegationLite) const;
112 
113  private:
114  int preference_;
115  Name name_;
116  };
117 
126  void
127  add(int preference, const Name& name);
128 
137  void
138  addUnsorted(const ptr_lib::shared_ptr<Delegation>& delegation)
139  {
140  delegations_.push_back(delegation);
141  }
142 
148  bool
149  remove(const Name& name);
150 
154  void
155  clear() { delegations_.clear(); }
156 
161  size_t
162  size() const { return delegations_.size(); }
163 
171  const Delegation&
172  get(size_t i) const;
173 
179  int
180  find(const Name& name) const;
181 
188  Blob
190  {
191  return wireFormat.encodeDelegationSet(*this);
192  }
193 
201  void
202  wireDecode
203  (const uint8_t *input, size_t inputLength,
205  {
206  wireFormat.decodeDelegationSet(*this, input, inputLength);
207  }
208 
215  void
216  wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
217  {
218  wireDecode(&input[0], input.size(), wireFormat);
219  }
220 
227  void
228  wireDecode
229  (const Blob& input,
231  {
232  wireDecode(input.buf(), input.size(), wireFormat);
233  }
234 
235 private:
236  std::vector<ptr_lib::shared_ptr<Delegation> > delegations_;
237 };
238 
239 }
240 
241 #endif
void add(int preference, const Name &name)
Add a new DelegationSet::Delegation to the list of delegations, sorted by preference number then by n...
Definition: delegation-set.cpp:55
DelegationSet()
Create a DelegationSet with an empty list of delegations.
Definition: delegation-set.hpp:43
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
void wireDecode(const std::vector< uint8_t > &input, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Decode the input using a particular wire format and update this DelegationSet.
Definition: delegation-set.hpp:216
DelegationSet(const DelegationSet &delegationSet)
Create a DelegationSet, copying values from the other DelegationSet.
Definition: delegation-set.hpp:51
Delegation(int preference, const Name &name)
Create a new DelegationSet::Delegation with the given values.
Definition: delegation-set.hpp:67
void clear()
Clear the list of delegations.
Definition: delegation-set.hpp:155
int find(const Name &name) const
Find the first delegation with the given name and return its index.
Definition: delegation-set.cpp:97
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
A DelegationSet holds a list of DelegationSet::Delegation entries which is used as the content of a L...
Definition: delegation-set.hpp:38
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
const Name & getName() const
Get the delegation name.
Definition: delegation-set.hpp:90
A DelegationSet::Delegation holds a preference number and delegation name.
Definition: delegation-set.hpp:60
const uint8_t * buf() const
Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null...
Definition: blob.hpp:159
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:147
int compare(const Delegation &other)
Compare this Delegation with other according to the ordering, based first on the preference number...
Definition: delegation-set.cpp:37
int getPreference() const
Get the preference number.
Definition: delegation-set.hpp:83
size_t size() const
Get the number of delegation entries.
Definition: delegation-set.hpp:162
Blob wireEncode(WireFormat &wireFormat=*WireFormat::getDefaultWireFormat()) const
Encode this DelegationSet for a particular wire format.
Definition: delegation-set.hpp:189
Definition: delegation-set-lite.hpp:32
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
void wireDecode(const uint8_t *input, size_t inputLength, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Decode the input using a particular wire format and update this DelegationSet.
Definition: delegation-set.hpp:203
void addUnsorted(const ptr_lib::shared_ptr< Delegation > &delegation)
Add the DelegationSet::Delegation to the end of the list of delegations, without sorting or updating ...
Definition: delegation-set.hpp:138
Definition: wire-format.hpp:39