All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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  : changeCount_(0), getDefaultWireEncodingChangeCount_(0)
45  {
46  }
47 
52  DelegationSet(const DelegationSet& delegationSet)
53  // A DelegationSet::Delegation is immutable, so just make a shallow copy.
54  : delegations_(delegationSet.delegations_),
55  changeCount_(delegationSet.changeCount_)
56  {
57  setDefaultWireEncoding
58  (delegationSet.getDefaultWireEncoding(),
59  delegationSet.defaultWireEncodingFormat_);
60  }
61 
62  DelegationSet& operator=(const DelegationSet& delegationSet);
63 
67  class Delegation {
68  public:
74  Delegation(int preference, const Name& name)
75  : preference_(preference), name_(name)
76  {
77  }
78 
83  Delegation(const DelegationSetLite::Delegation& delegationLite);
84 
89  int
90  getPreference() const { return preference_; }
91 
96  const Name&
97  getName() const { return name_; }
98 
106  int
107  compare(const Delegation& other);
108 
117  void
118  get(DelegationSetLite::Delegation& delegationLite) const;
119 
120  private:
121  int preference_;
122  Name name_;
123  };
124 
133  void
134  add(int preference, const Name& name);
135 
144  void
145  addUnsorted(const ptr_lib::shared_ptr<Delegation>& delegation)
146  {
147  delegations_.push_back(delegation);
148  ++changeCount_;
149  }
150 
156  bool
157  remove(const Name& name);
158 
162  void
164  {
165  delegations_.clear();
166  ++changeCount_;
167  }
168 
173  size_t
174  size() const { return delegations_.size(); }
175 
183  const Delegation&
184  get(size_t i) const;
185 
191  int
192  find(const Name& name) const;
193 
203  Blob
204  wireEncode
205  (WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const;
206 
217  void
218  wireDecode
219  (const uint8_t *input, size_t inputLength,
221 
231  void
232  wireDecode
233  (const std::vector<uint8_t>& input,
235  {
236  wireDecode(&input[0], input.size(), wireFormat);
237  }
238 
247  void
248  wireDecode
249  (const Blob& input,
251 
256  const Blob&
258  {
259  if (getDefaultWireEncodingChangeCount_ != getChangeCount()) {
260  // The values have changed, so the default wire encoding is invalidated.
261  // This method can be called on a const object, but we want to be able to
262  // update the default cached value.
263  const_cast<DelegationSet*>(this)->defaultWireEncoding_ = Blob();
264  const_cast<DelegationSet*>(this)->defaultWireEncodingFormat_ = 0;
265  const_cast<DelegationSet*>(this)->getDefaultWireEncodingChangeCount_ =
266  getChangeCount();
267  }
268 
269  return defaultWireEncoding_;
270  }
271 
277  WireFormat*
278  getDefaultWireEncodingFormat() const { return defaultWireEncodingFormat_; }
279 
284  uint64_t
285  getChangeCount() const { return changeCount_; }
286 
287 private:
288  void
289  setDefaultWireEncoding
290  (const Blob& defaultWireEncoding, WireFormat *defaultWireEncodingFormat)
291  {
292  defaultWireEncoding_ = defaultWireEncoding;
293  defaultWireEncodingFormat_ = defaultWireEncodingFormat;
294  // Set getDefaultWireEncodingChangeCount_ so that the next call to
295  // getDefaultWireEncoding() won't clear defaultWireEncoding_.
296  getDefaultWireEncodingChangeCount_ = getChangeCount();
297  }
298 
299  std::vector<ptr_lib::shared_ptr<Delegation> > delegations_;
300  Blob defaultWireEncoding_;
301  WireFormat *defaultWireEncodingFormat_;
302  uint64_t getDefaultWireEncodingChangeCount_;
303  uint64_t changeCount_;
304 };
305 
306 }
307 
308 #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:66
DelegationSet()
Create a DelegationSet with an empty list of delegations.
Definition: delegation-set.hpp:43
const Blob & getDefaultWireEncoding() const
Return a reference to the defaultWireEncoding, which was encoded with getDefaultWireEncodingFormat()...
Definition: delegation-set.hpp:257
DelegationSet(const DelegationSet &delegationSet)
Create a DelegationSet, copying values from the other DelegationSet.
Definition: delegation-set.hpp:52
Delegation(int preference, const Name &name)
Create a new DelegationSet::Delegation with the given values.
Definition: delegation-set.hpp:74
void clear()
Clear the list of delegations.
Definition: delegation-set.hpp:163
int find(const Name &name) const
Find the first delegation with the given name and return its index.
Definition: delegation-set.cpp:111
WireFormat * getDefaultWireEncodingFormat() const
Get the WireFormat which is used by getDefaultWireEncoding().
Definition: delegation-set.hpp:278
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<uint8_t>.
Definition: blob.hpp:42
const Name & getName() const
Get the delegation name.
Definition: delegation-set.hpp:97
A DelegationSet::Delegation holds a preference number and delegation name.
Definition: delegation-set.hpp:67
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:90
size_t size() const
Get the number of delegation entries.
Definition: delegation-set.hpp:174
Blob wireEncode(WireFormat &wireFormat=*WireFormat::getDefaultWireFormat()) const
Encode this DelegationSet for a particular wire format.
Definition: delegation-set.cpp:122
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.cpp:140
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:145
Definition: wire-format.hpp:39
uint64_t getChangeCount() const
Get the change count, which is incremented each time this object is changed.
Definition: delegation-set.hpp:285