ndn::DelegationList Class Reference

represents a list of Delegations More...

#include <delegation-list.hpp>

Classes

class  Error
 

Public Types

using const_iterator = std::vector< Delegation >::const_iterator
 
enum  InsertConflictResolution {
  INS_REPLACE,
  INS_APPEND,
  INS_SKIP
}
 what to do when inserting a duplicate name More...
 

Public Member Functions

 DelegationList ()
 construct an empty DelegationList More...
 
 DelegationList (std::initializer_list< Delegation > dels)
 construct a sorted DelegationList with specified delegations More...
 
 DelegationList (const Block &block, bool wantSort=true)
 decode a DelegationList More...
 
const Delegationat (size_t i) const
 get the i-th delegation More...
 
const_iterator begin () const noexcept
 
bool empty () const noexcept
 
const_iterator end () const noexcept
 
size_t erase (uint64_t preference, const Name &name)
 delete Delegation(s) with specified preference and name More...
 
size_t erase (const Delegation &del)
 delete Delegation(s) with matching preference and name More...
 
size_t erase (const Name &name)
 erase Delegation(s) with specified name More...
 
bool insert (uint64_t preference, const Name &name, InsertConflictResolution onConflict=INS_REPLACE)
 insert Delegation More...
 
bool insert (const Delegation &del, InsertConflictResolution onConflict=INS_REPLACE)
 insert Delegation More...
 
bool isSorted () const noexcept
 
const Delegationoperator[] (size_t i) const
 get the i-th delegation More...
 
size_t size () const noexcept
 
void sort ()
 sort the delegation list More...
 
void wireDecode (const Block &block, bool wantSort=true)
 decode a DelegationList More...
 
template<encoding::Tag TAG>
size_t wireEncode (EncodingImpl< TAG > &encoder, uint32_t type=tlv::ForwardingHint) const
 encode into wire format More...
 

Friends

bool operator== (const DelegationList &, const DelegationList &)
 compare whether two DelegationLists are equal More...
 

Detailed Description

represents a list of Delegations

See also
https://named-data.net/doc/ndn-tlv/link.html

Delegations are stored in an std::vector, under the assumption that there is usually only a small number of Delegations, so that copying is acceptable when they are modified.

Definition at line 36 of file delegation-list.hpp.

Member Typedef Documentation

Definition at line 89 of file delegation-list.hpp.

Member Enumeration Documentation

what to do when inserting a duplicate name

Enumerator
INS_REPLACE 

existing delegation(s) with the same name are replaced with the new delegation

INS_APPEND 

multiple delegations with the same name are kept in the DelegationList

Note
This is NOT RECOMMENDED by Link specification.
INS_SKIP 

new delegation is not inserted if an existing delegation has the same name

Definition at line 152 of file delegation-list.hpp.

Constructor & Destructor Documentation

ndn::DelegationList::DelegationList ( )

construct an empty DelegationList

Definition at line 40 of file delegation-list.cpp.

ndn::DelegationList::DelegationList ( std::initializer_list< Delegation dels)

construct a sorted DelegationList with specified delegations

This is equivalent to inserting each delegation into an empty DelegationList with INS_REPLACE conflict resolution.

Definition at line 45 of file delegation-list.cpp.

ndn::DelegationList::DelegationList ( const Block block,
bool  wantSort = true 
)
explicit

decode a DelegationList

See also
wireDecode

Definition at line 53 of file delegation-list.cpp.

Member Function Documentation

const Delegation& ndn::DelegationList::at ( size_t  i) const
inline

get the i-th delegation

Exceptions
std::out_of_rangei >= size()

Definition at line 129 of file delegation-list.hpp.

const_iterator ndn::DelegationList::begin ( ) const
inlinenoexcept

Definition at line 92 of file delegation-list.hpp.

bool ndn::DelegationList::empty ( ) const
inlinenoexcept

Definition at line 104 of file delegation-list.hpp.

const_iterator ndn::DelegationList::end ( ) const
inlinenoexcept

Definition at line 98 of file delegation-list.hpp.

size_t ndn::DelegationList::erase ( uint64_t  preference,
const Name name 
)
inline

delete Delegation(s) with specified preference and name

Returns
count of erased Delegation(s)

Definition at line 187 of file delegation-list.hpp.

size_t ndn::DelegationList::erase ( const Delegation del)
inline

delete Delegation(s) with matching preference and name

Returns
count of erased Delegation(s)

Definition at line 196 of file delegation-list.hpp.

size_t ndn::DelegationList::erase ( const Name name)
inline

erase Delegation(s) with specified name

Returns
count of erased Delegation(s)

Definition at line 205 of file delegation-list.hpp.

bool ndn::DelegationList::insert ( uint64_t  preference,
const Name name,
InsertConflictResolution  onConflict = INS_REPLACE 
)

insert Delegation

Returns
whether inserted

Definition at line 181 of file delegation-list.cpp.

bool ndn::DelegationList::insert ( const Delegation del,
InsertConflictResolution  onConflict = INS_REPLACE 
)
inline

insert Delegation

Returns
whether inserted

Definition at line 178 of file delegation-list.hpp.

bool ndn::DelegationList::isSorted ( ) const
inlinenoexcept

Definition at line 84 of file delegation-list.hpp.

const Delegation& ndn::DelegationList::operator[] ( size_t  i) const
inline

get the i-th delegation

Precondition
i < size()

Definition at line 119 of file delegation-list.hpp.

size_t ndn::DelegationList::size ( ) const
inlinenoexcept

Definition at line 110 of file delegation-list.hpp.

void ndn::DelegationList::sort ( )

sort the delegation list

Postcondition
isSorted() == true
Delegations are sorted in increasing preference order.

A DelegationList can be constructed as sorted or unsorted. In most cases, it is recommended to use a sorted DelegationList. An unsorted DelegationList is useful for extracting the i-th delegation from a received ForwardingHint or Link object.

This method turns an unsorted DelegationList into a sorted DelegationList. If access to unsorted DelegationList is not needed, it is more efficient to sort the DelegationList in wireDecode.

Definition at line 165 of file delegation-list.cpp.

void ndn::DelegationList::wireDecode ( const Block block,
bool  wantSort = true 
)

decode a DelegationList

Parameters
blockeither a Content block (from Link) or a ForwardingHint block
wantSortif true, delegations are sorted
Exceptions
Errorthe block cannot be parsed as a list of Delegations

Definition at line 114 of file delegation-list.cpp.

template<encoding::Tag TAG>
size_t ndn::DelegationList::wireEncode ( EncodingImpl< TAG > &  encoder,
uint32_t  type = tlv::ForwardingHint 
) const

encode into wire format

Parameters
encodereither an EncodingBuffer or an EncodingEstimator
typeTLV-TYPE number, either Content (for Link) or ForwardingHint
Exceptions
std::invalid_argumenttype is invalid
Errorthere is no Delegation

Definition at line 72 of file delegation-list.cpp.

Friends And Related Function Documentation

bool operator== ( const DelegationList ,
const DelegationList  
)
friend

compare whether two DelegationLists are equal

Note
Order matters! If two DelegationLists contain the same Delegations but at least one is unsorted, they may compare unequal if the Delegations appear in different order.

Definition at line 235 of file delegation-list.cpp.