|
NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
|
API Documentation
|
Go to the documentation of this file.
32 #include <boost/functional/hash.hpp>
33 #include <boost/range/adaptor/reversed.hpp>
34 #include <boost/range/concepts.hpp>
38 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Name>));
42 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::iterator>));
43 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_iterator>));
44 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::reverse_iterator>));
45 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_reverse_iterator>));
46 BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept<Name>));
47 static_assert(std::is_base_of<tlv::Error, Name::Error>::value,
48 "Name::Error must inherit from tlv::Error");
50 const size_t Name::npos = std::numeric_limits<size_t>::max();
66 :
Name(std::string(uri))
75 size_t iColon = uri.find(
':');
76 if (iColon != std::string::npos) {
78 size_t iFirstSlash = uri.find(
'/');
79 if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
81 uri.erase(0, iColon + 1);
87 if (uri.size() >= 2 && uri[1] ==
'/') {
89 size_t iAfterAuthority = uri.find(
'/', 2);
90 if (iAfterAuthority == std::string::npos)
94 uri.erase(0, iAfterAuthority + 1);
102 size_t iComponentStart = 0;
105 while (iComponentStart < uri.size()) {
106 size_t iComponentEnd = uri.find(
"/", iComponentStart);
107 if (iComponentEnd == std::string::npos)
108 iComponentEnd = uri.size();
111 iComponentStart = iComponentEnd + 1;
115 template<encoding::Tag TAG>
119 size_t totalLength = 0;
120 for (
const Component& comp : *
this | boost::adaptors::reversed) {
121 totalLength += comp.wireEncode(encoder);
124 totalLength += encoder.prependVarNumber(totalLength);
125 totalLength += encoder.prependVarNumber(
tlv::Name);
143 m_wire = buffer.block();
162 Name copiedName(*
this);
174 i +=
static_cast<ssize_t
>(
size());
177 if (i < 0 ||
static_cast<size_t>(i) >=
size()) {
178 NDN_THROW(
Error(
"Requested component does not exist (out of bounds)"));
189 if (iStartComponent < 0)
190 iStartComponent +=
static_cast<ssize_t
>(
size());
191 size_t iStart = iStartComponent < 0 ? 0 : static_cast<size_t>(iStartComponent);
193 size_t iEnd =
size();
194 if (nComponents !=
npos)
195 iEnd = std::min(
size(), iStart + nComponents);
197 for (
size_t i = iStart; i < iEnd; ++i)
209 i +=
static_cast<ssize_t
>(
size());
221 i +=
static_cast<ssize_t
>(
size());
248 for (
size_t i = 0; i <
name.size(); ++i)
255 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14,
256 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
257 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
258 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55,
266 return append(placeholder);
273 i +=
static_cast<ssize_t
>(
size());
291 static const Name n(
"/sha256digest=0000000000000000000000000000000000000000000000000000000000000000");
306 for (
size_t i = 0; i <
size(); ++i) {
307 if (
get(i) != other.
get(i))
320 for (
size_t i = 0; i <
size(); ++i) {
321 if (
get(i) != other.
get(i))
331 count1 = std::min(count1, this->
size() - pos1);
332 count2 = std::min(count2, other.
size() - pos2);
333 size_t count = std::min(count1, count2);
335 for (
size_t i = 0; i < count; ++i) {
342 return count1 - count2;
355 for (
const auto& component : *
this) {
357 component.toUri(os, format);
364 std::ostringstream os;
372 std::string inputString;
386 return boost::hash_range(
name.wireEncode().wire(),
387 name.wireEncode().wire() +
name.wireEncode().size());
const element_container & elements() const
Get container of sub-elements.
std::istream & operator>>(std::istream &is, Name &name)
Parse URI from stream as Name.
static Component fromTimestamp(const time::system_clock::TimePoint &timePoint)
Create sequence number component using NDN naming conventions.
void erase(ssize_t i)
Erase the component at the specified index.
int compare(const Name &other) const
Compare this to the other Name using NDN canonical ordering.
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
Name()
Create an empty name.
Name PartialName
Represents an arbitrary sequence of name components.
size_t size() const
Returns the number of components.
@ ParametersSha256DigestComponent
static constexpr uint8_t SHA256_OF_EMPTY_STRING[]
element_const_iterator elements_begin() const
Equivalent to elements().begin()
int compare(const Component &other) const
Compare this to the other Component using NDN canonical ordering.
static time_point now() noexcept
NDN_CXX_NODISCARD bool empty() const
Checks if the name is empty, i.e.
static const size_t npos
Indicates "until the end" in getSubName() and compare().
a concept check for TLV abstraction with .wireDecode method and constructible from Block
EncodingImpl< EstimatorTag > EncodingEstimator
Name getSuccessor() const
Get the successor of a name.
Represents an absolute name.
name::Component::Error Error
void wireDecode(const Block &wire)
Decode name from wire encoding.
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extracts some components as a sub-name (PartialName).
static Component fromVersion(uint64_t version)
Create version component using NDN naming conventions.
uint32_t type() const
Return the TLV-TYPE of the Block.
a concept check for TLV abstraction with .wireEncode method
Name & appendVersion(optional< uint64_t > version=nullopt)
Append a version component.
element_iterator erase(element_const_iterator position)
Erase a sub-element.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Name & set(ssize_t i, const Component &component)
Replace the component at the specified index.
std::vector< Block > element_container
Name & append(const Component &component)
Append a component.
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
const Block & wireEncode() const
Perform wire encoding, or return existing wire encoding.
void resetWire() noexcept
Reset wire buffer but keep TLV-TYPE and sub-elements (if any)
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
void parse() const
Parse TLV-VALUE into sub-elements.
size_t operator()(const ndn::Name &name) const
const Component & at(ssize_t i) const
Returns an immutable reference to the component at the specified index, with bounds checking.
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Interest)
Name & appendParametersSha256DigestPlaceholder()
Append a placeholder for a ParametersSha256Digest component.
Represents a name component.
Represents a TLV element of NDN packet format.
void clear()
Remove all components.
Name deepCopy() const
Make a deep copy of the name, reallocating the underlying memory buffer.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Name & appendTimestamp(optional< time::system_clock::TimePoint > timestamp=nullopt)
Append a timestamp component.
static Component fromEscapedString(const char *input, size_t beginOffset, size_t endOffset)
Decode NameComponent from a URI component.
represents an error in TLV encoding or decoding
const Component & get(ssize_t i) const
Returns an immutable reference to the component at the specified index.
a concept check for TLV abstraction with .wireEncode method
Copyright (c) 2011-2015 Regents of the University of California.
EncodingImpl< EncoderTag > EncodingBuffer
bool equals(const Name &other) const
Check if this name equals another name.
UriFormat
Identify a format of URI representation.