link.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_LINK_HPP
23 #define NDN_LINK_HPP
24 
25 #include <ndn-cpp/data.hpp>
26 #include <ndn-cpp/delegation-set.hpp>
27 
28 namespace ndn {
29 
35 class Link : public Data {
36 public:
41  Link()
42  {
43  getMetaInfo().setType(ndn_ContentType_LINK);
44  }
45 
51  Link(const Name& name)
52  : Data(name)
53  {
54  getMetaInfo().setType(ndn_ContentType_LINK);
55  }
56 
63  Link(const Data& data);
64 
72  virtual void
74  (const Blob& input,
76 
88  Link&
90  (int preference, const Name& name,
92  {
93  delegations_.add(preference, name);
94  encodeContent(wireFormat);
95 
96  return *this;
97  }
98 
107  bool
109  (const Name& name,
111  {
112  bool wasRemoved = delegations_.remove(name);
113  if (wasRemoved)
114  encodeContent(wireFormat);
115 
116  return wasRemoved;
117  }
118 
124  const DelegationSet&
125  getDelegations() const { return delegations_; }
126 
127 private:
133  void
134  encodeContent(WireFormat& wireFormat)
135  {
136  setContent(delegations_.wireEncode(wireFormat));
137  getMetaInfo().setType(ndn_ContentType_LINK);
138  }
139 
140  DelegationSet delegations_;
141 };
142 
143 }
144 
145 #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
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
Definition: data.hpp:37
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
Blob wireEncode(WireFormat &wireFormat=*WireFormat::getDefaultWireFormat()) const
Encode this DelegationSet for a particular wire format.
Definition: delegation-set.hpp:189
Data & setContent(const std::vector< uint8_t > &content)
Set the content to a copy of the data in the vector.
Definition: data.hpp:225
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
bool remove(const Name &name)
Remove every DelegationSet::Delegation with the given name.
Definition: delegation-set.cpp:73
Definition: wire-format.hpp:39