Adopt more C++17 features throughout the codebase

Change-Id: I31af421d8a977ba2aae23afcda289ff53230897f
This commit is contained in:
Davide Pesavento committed 2023-03-23 23:28:27 -04:00
1 parent eb87c28200
commit 187e9f99b2
70 files changed
+356 -431

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Data>));
BOOST_CONCEPT_ASSERT((WireEncodable<Data>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Data>));
BOOST_CONCEPT_ASSERT((WireDecodable<Data>));
static_assert(std::is_base_of<tlv::Error, Data::Error>::value,
static_assert(std::is_convertible_v<Data::Error*, tlv::Error*>,
"Data::Error must inherit from tlv::Error");
Data::Data(const Name& name)
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2021 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -57,7 +57,7 @@ CancelHandle::CancelHandle() noexcept = default;
template<typename HandleT>
class ScopedCancelHandle
{
static_assert(std::is_convertible<HandleT*, CancelHandle*>::value,
static_assert(std::is_convertible_v<HandleT*, CancelHandle*>,
"HandleT must publicly derive from CancelHandle");
public:
+18 -15
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -35,24 +35,28 @@ namespace ndn {
class TagHost
{
public:
/** \brief Get a tag item.
* \tparam T type of the tag, which must be a subclass of ndn::Tag
* \retval nullptr if no Tag of type T is stored
/**
* \brief Get a tag item.
* \tparam T type of the tag, which must be a subclass of ndn::Tag
* \retval nullptr if no Tag of type T is stored
*/
template<typename T>
shared_ptr<T>
getTag() const;
/** \brief Set (add or replace) a tag item.
* \tparam T type of the tag, which must be a subclass of ndn::Tag
* \note Tag can be set even on a const tag host instance
/**
* \brief Set (add or replace) a tag item.
* \tparam T type of the tag, which must be a subclass of ndn::Tag
* \note Tag can be set even on a const tag host instance
*/
template<typename T>
void
setTag(shared_ptr<T> tag) const;
/** \brief Remove a tag item.
* \note Tag can be removed even on a const tag host instance
/**
* \brief Remove a tag item.
* \tparam T type of the tag, which must be a subclass of ndn::Tag
* \note Tag can be removed even on a const tag host instance
*/
template<typename T>
void
@@ -66,20 +70,19 @@ template<typename T>
shared_ptr<T>
TagHost::getTag() const
{
static_assert(std::is_base_of<Tag, T>::value, "T must inherit from Tag");
static_assert(std::is_convertible_v<T*, Tag*>, "T must inherit from ndn::Tag");
auto it = m_tags.find(T::getTypeId());
if (it == m_tags.end()) {
return nullptr;
if (auto it = m_tags.find(T::getTypeId()); it != m_tags.end()) {
return static_pointer_cast<T>(it->second);
}
return static_pointer_cast<T>(it->second);
return nullptr;
}
template<typename T>
void
TagHost::setTag(shared_ptr<T> tag) const
{
static_assert(std::is_base_of<Tag, T>::value, "T must inherit from Tag");
static_assert(std::is_convertible_v<T*, Tag*>, "T must inherit from ndn::Tag");
if (tag == nullptr) {
m_tags.erase(T::getTypeId());
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -68,7 +68,7 @@ readNonNegativeInteger(const Block& block);
* represented in R
*/
template<typename R>
std::enable_if_t<std::is_integral<R>::value, R>
std::enable_if_t<std::is_integral_v<R>, R>
readNonNegativeIntegerAs(const Block& block)
{
uint64_t value = readNonNegativeInteger(block);
@@ -87,7 +87,7 @@ readNonNegativeIntegerAs(const Block& block)
* function may trigger unspecified behavior.
*/
template<typename R>
std::enable_if_t<std::is_enum<R>::value, R>
std::enable_if_t<std::is_enum_v<R>, R>
readNonNegativeIntegerAs(const Block& block)
{
return static_cast<R>(readNonNegativeIntegerAs<std::underlying_type_t<R>>(block));
@@ -286,8 +286,8 @@ Block
makeBinaryBlock(uint32_t type, Iterator first, Iterator last)
{
using BinaryBlockHelper = std::conditional_t<
std::is_base_of<std::random_access_iterator_tag,
typename std::iterator_traits<Iterator>::iterator_category>::value,
std::is_base_of_v<std::random_access_iterator_tag,
typename std::iterator_traits<Iterator>::iterator_category>,
detail::BinaryBlockFast<Iterator>,
detail::BinaryBlockSlow<Iterator>>;
+11 -13
View File
@@ -170,22 +170,22 @@ Block::fromBuffer(ConstBufferPtr buffer, size_t offset)
uint32_t type = 0;
bool isOk = tlv::readType(pos, end, type);
if (!isOk) {
return std::make_tuple(false, Block());
return {false, {}};
}
uint64_t length = 0;
isOk = tlv::readVarNumber(pos, end, length);
if (!isOk) {
return std::make_tuple(false, Block());
return {false, {}};
}
// pos now points to TLV-VALUE
BOOST_ASSERT(pos <= end);
if (length > static_cast<uint64_t>(std::distance(pos, end))) {
return std::make_tuple(false, Block());
return {false, {}};
}
return std::make_tuple(true, Block(std::move(buffer), type, begin, pos + length, pos, pos + length));
return {true, Block(std::move(buffer), type, begin, pos + length, pos, pos + length)};
}
std::tuple<bool, Block>
@@ -197,25 +197,24 @@ Block::fromBuffer(span<const uint8_t> buffer)
uint32_t type = 0;
bool isOk = tlv::readType(pos, end, type);
if (!isOk) {
return std::make_tuple(false, Block());
return {false, {}};
}
uint64_t length = 0;
isOk = tlv::readVarNumber(pos, end, length);
if (!isOk) {
return std::make_tuple(false, Block());
return {false, {}};
}
// pos now points to TLV-VALUE
BOOST_ASSERT(pos <= end);
if (length > static_cast<uint64_t>(std::distance(pos, end))) {
return std::make_tuple(false, Block());
return {false, {}};
}
std::advance(pos, length);
// pos now points to the end of the TLV
auto b = std::make_shared<Buffer>(buffer.begin(), pos);
return std::make_tuple(true, Block(b, type, b->begin(), b->end(),
std::prev(b->end(), length), b->end()));
return {true, Block(b, type, b->begin(), b->end(), std::prev(b->end(), length), b->end())};
}
Block
@@ -413,13 +412,12 @@ Block::encode(EncodingBuffer& encoder)
const Block&
Block::get(uint32_t type) const
{
auto it = this->find(type);
if (it != m_elements.end()) {
if (auto it = find(type); it != m_elements.end()) {
return *it;
}
NDN_THROW(Error("No sub-element of type " + to_string(type) +
" found in block of type " + to_string(m_type)));
NDN_THROW(Error("No sub-element of type " + std::to_string(type) +
" found in block of type " + std::to_string(m_type)));
}
Block::element_const_iterator
+2 -2
View File
@@ -253,7 +253,7 @@ size_t
Encoder::prependRange(Iterator first, Iterator last)
{
using ValueType = typename std::iterator_traits<Iterator>::value_type;
static_assert(sizeof(ValueType) == 1 && !std::is_same<ValueType, bool>::value, "");
static_assert(sizeof(ValueType) == 1 && !std::is_same_v<ValueType, bool>, "");
size_t length = std::distance(first, last);
reserveFront(length);
@@ -268,7 +268,7 @@ size_t
Encoder::appendRange(Iterator first, Iterator last)
{
using ValueType = typename std::iterator_traits<Iterator>::value_type;
static_assert(sizeof(ValueType) == 1 && !std::is_same<ValueType, bool>::value, "");
static_assert(sizeof(ValueType) == 1 && !std::is_same_v<ValueType, bool>, "");
size_t length = std::distance(first, last);
reserveBack(length);
+2 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2020 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -182,11 +182,7 @@ operator<<(std::ostream& os, RouteFlags routeFlags)
};
auto join = make_ostream_joiner(os, '|');
for (const auto& pair : knownBits) {
RouteFlags bit = ROUTE_FLAGS_NONE;
std::string token;
std::tie(bit, token) = pair;
for (const auto& [bit, token] : knownBits) {
if ((routeFlags & bit) != 0) {
join = token;
routeFlags = static_cast<RouteFlags>(routeFlags & ~bit);
+4 -4
View File
@@ -358,11 +358,11 @@ template<typename Iterator,
constexpr bool
shouldSelectContiguousReadNumber()
{
return (std::is_convertible<DecayedIterator, const ValueType*>::value ||
std::is_convertible<DecayedIterator, typename std::basic_string<ValueType>::const_iterator>::value ||
std::is_convertible<DecayedIterator, typename std::vector<ValueType>::const_iterator>::value) &&
return (std::is_convertible_v<DecayedIterator, const ValueType*> ||
std::is_convertible_v<DecayedIterator, typename std::basic_string<ValueType>::const_iterator> ||
std::is_convertible_v<DecayedIterator, typename std::vector<ValueType>::const_iterator>) &&
sizeof(ValueType) == 1 &&
!std::is_same<ValueType, bool>::value;
!std::is_same_v<ValueType, bool>;
}
template<typename Iterator>
+20 -18
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -33,7 +33,8 @@ namespace ndn {
namespace name {
namespace {
/** \brief Declare rules for a NameComponent type.
/**
* \brief Declare rules for a NameComponent type.
*/
class ComponentType : noncopyable
{
@@ -43,7 +44,8 @@ public:
virtual
~ComponentType() = default;
/** \brief Throw Component::Error if \p comp is invalid.
/**
* \brief Throw Component::Error if \p comp is invalid.
*/
virtual void
check(const Component& comp) const
@@ -91,7 +93,7 @@ public:
* \pre getAltUriPrefix() != nullptr
*/
virtual Component
parseAltUriValue(const std::string&) const
parseAltUriValue(const std::string& input) const
{
NDN_CXX_UNREACHABLE;
}
@@ -153,10 +155,11 @@ protected:
}
};
/** \brief Rules for GenericNameComponent.
/**
* \brief Rules for GenericNameComponent.
*
* GenericNameComponent has an alternate URI representation that omits the `<type-number>` prefix.
* This must be special-cased in the caller, and is not handled by this class.
* GenericNameComponent has an alternate URI representation that omits the `<type-number>` prefix.
* This must be special-cased in the caller, and is not handled by this class.
*/
class GenericNameComponentType final : public ComponentType
{
@@ -168,8 +171,9 @@ public:
}
};
/** \brief Rules for a component type holding a SHA256 digest value, written as
* a hex string in URI representation.
/**
* \brief Rules for a component type holding a SHA256 digest value, written as
* a hex string in URI representation.
*/
class Sha256ComponentType final : public ComponentType
{
@@ -193,9 +197,7 @@ public:
std::tuple<bool, Component>
getSuccessor(const Component& comp) const final
{
bool isExtended = false;
Block successor;
std::tie(isExtended, successor) = getSuccessorImpl(comp);
auto [isExtended, successor] = getSuccessorImpl(comp);
return {isExtended, isExtended ? comp : Component(successor)};
}
@@ -238,8 +240,9 @@ private:
const std::string m_uriPrefix;
};
/** \brief Rules for a component type holding a NonNegativeInteger value, written as
* a decimal number in URI representation.
/**
* \brief Rules for a component type holding a NonNegativeInteger value, written as
* a decimal number in URI representation.
*/
class DecimalComponentType final : public ComponentType
{
@@ -324,11 +327,10 @@ public:
const ComponentType*
findByUriPrefix(const std::string& prefix) const
{
auto it = m_uriPrefixes.find(prefix);
if (it == m_uriPrefixes.end()) {
return nullptr;
if (auto it = m_uriPrefixes.find(prefix); it != m_uriPrefixes.end()) {
return it->second;
}
return it->second;
return nullptr;
}
private:
+13 -12
View File
@@ -23,7 +23,7 @@
#define NDN_CXX_IMPL_RECORD_CONTAINER_HPP
#include "ndn-cxx/detail/common.hpp"
#include "ndn-cxx/util/signal.hpp"
#include "ndn-cxx/util/signal/signal.hpp"
#include <atomic>
@@ -77,30 +77,30 @@ public:
using Record = T;
using Container = std::map<RecordId, Record>;
/** \brief Retrieve record by ID.
/**
* \brief Retrieve record by ID.
*/
Record*
get(RecordId id)
{
auto i = m_container.find(id);
if (i == m_container.end()) {
return nullptr;
if (auto it = m_container.find(id); it != m_container.end()) {
return &it->second;
}
return &i->second;
return nullptr;
}
/** \brief Insert a record with given ID.
/**
* \brief Insert a record with given ID.
*/
template<typename ...TArgs>
Record&
put(RecordId id, TArgs&&... args)
{
BOOST_ASSERT(id != 0);
auto it = m_container.emplace(std::piecewise_construct, std::forward_as_tuple(id),
std::forward_as_tuple(std::forward<decltype(args)>(args)...));
BOOST_ASSERT(it.second);
auto [it, isNew] = m_container.try_emplace(id, std::forward<decltype(args)>(args)...);
BOOST_VERIFY(isNew);
Record& record = it.first->second;
Record& record = it->second;
record.m_container = this;
record.m_id = id;
return record;
@@ -112,7 +112,8 @@ public:
return ++m_lastId;
}
/** \brief Insert a record with newly assigned ID.
/**
* \brief Insert a record with newly assigned ID.
*/
template<typename ...TArgs>
Record&
+1 -1
View File
@@ -38,7 +38,7 @@ namespace ndn {
BOOST_CONCEPT_ASSERT((WireEncodable<Interest>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Interest>));
BOOST_CONCEPT_ASSERT((WireDecodable<Interest>));
static_assert(std::is_base_of<tlv::Error, Interest::Error>::value,
static_assert(std::is_convertible_v<Interest::Error*, tlv::Error*>,
"Interest::Error must inherit from tlv::Error");
bool Interest::s_autoCheckParametersDigest = true;
+1 -1
View File
@@ -31,7 +31,7 @@ BOOST_CONCEPT_ASSERT((boost::EqualityComparable<KeyLocator>));
BOOST_CONCEPT_ASSERT((WireEncodable<KeyLocator>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<KeyLocator>));
BOOST_CONCEPT_ASSERT((WireDecodable<KeyLocator>));
static_assert(std::is_base_of<tlv::Error, KeyLocator::Error>::value,
static_assert(std::is_convertible_v<KeyLocator::Error*, tlv::Error*>,
"KeyLocator::Error must inherit from tlv::Error");
constexpr size_t MAX_KEY_DIGEST_OCTETS_TO_SHOW = 8;
+1 -1
View File
@@ -29,7 +29,7 @@ BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Link>));
BOOST_CONCEPT_ASSERT((WireEncodable<Link>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Link>));
BOOST_CONCEPT_ASSERT((WireDecodable<Link>));
static_assert(std::is_base_of<Data::Error, Link::Error>::value,
static_assert(std::is_convertible_v<Link::Error*, Data::Error*>,
"Link::Error should inherit from Data::Error");
Link::Link() = default;
+7 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -35,7 +35,8 @@
namespace ndn {
namespace lp {
/** \brief Indicate a uint64_t field shall be decoded and encoded as a non-negative integer.
/**
* \brief Indicates that a `uint64_t` field shall be decoded and encoded as a non-negative integer.
*/
struct NonNegativeIntegerTag;
@@ -176,10 +177,10 @@ template<typename LOCATION, typename VALUE, uint64_t TYPE, bool REPEATABLE = fal
class FieldDecl
{
public:
typedef LOCATION FieldLocation;
typedef VALUE ValueType;
typedef std::integral_constant<uint64_t, TYPE> TlvType;
typedef std::integral_constant<bool, REPEATABLE> IsRepeatable;
using FieldLocation = LOCATION;
using ValueType = VALUE;
using TlvType = std::integral_constant<uint64_t, TYPE>;
using IsRepeatable = std::bool_constant<REPEATABLE>;
/** \brief Decode a field.
* \param wire an element with top-level TLV-TYPE \c TlvType::value.
+6 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -60,11 +60,11 @@ class Fragment : public Base
template<class X>
struct Field
{
static_assert(std::is_base_of<field_location_tags::Base, typename X::FieldLocation>::value, "");
static_assert(std::is_same<typename X::TlvType::value_type, uint64_t>::value, "");
static_assert(std::is_same<typename X::IsRepeatable::value_type, bool>::value, "");
static_assert(std::is_default_constructible<typename X::ValueType>::value, "");
static_assert(std::is_copy_constructible<typename X::ValueType>::value, "");
static_assert(std::is_base_of_v<field_location_tags::Base, typename X::FieldLocation>, "");
static_assert(std::is_same_v<typename X::TlvType::value_type, uint64_t>, "");
static_assert(std::is_same_v<typename X::IsRepeatable::value_type, bool>, "");
static_assert(std::is_default_constructible_v<typename X::ValueType>, "");
static_assert(std::is_copy_constructible_v<typename X::ValueType>, "");
BOOST_CONCEPT_USAGE(Field)
{
Block wire;
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -24,7 +24,7 @@
#ifndef NDN_CXX_LP_SEQUENCE_HPP
#define NDN_CXX_LP_SEQUENCE_HPP
#include "ndn-cxx/detail/common.hpp"
#include <cstdint>
namespace ndn {
namespace lp {
@@ -32,7 +32,7 @@ namespace lp {
/**
* \brief Represents a sequence number.
*/
typedef uint64_t Sequence;
using Sequence = uint64_t;
} // namespace lp
} // namespace ndn
+1 -1
View File
@@ -30,7 +30,7 @@ namespace ndn {
BOOST_CONCEPT_ASSERT((WireEncodable<MetaInfo>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<MetaInfo>));
BOOST_CONCEPT_ASSERT((WireDecodable<MetaInfo>));
static_assert(std::is_base_of<tlv::Error, MetaInfo::Error>::value,
static_assert(std::is_convertible_v<MetaInfo::Error*, tlv::Error*>,
"MetaInfo::Error must inherit from tlv::Error");
MetaInfo::MetaInfo()
+1 -1
View File
@@ -25,7 +25,7 @@
namespace ndn {
static_assert(std::is_base_of<tlv::Error, MetadataObject::Error>::value,
static_assert(std::is_convertible_v<MetadataObject::Error*, tlv::Error*>,
"MetadataObject::Error must inherit from tlv::Error");
MetadataObject::MetadataObject() = default;
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2019 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -29,7 +29,7 @@ namespace mgmt {
// BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ControlResponse>));
BOOST_CONCEPT_ASSERT((WireEncodable<ControlResponse>));
BOOST_CONCEPT_ASSERT((WireDecodable<ControlResponse>));
static_assert(std::is_base_of<tlv::Error, ControlResponse::Error>::value,
static_assert(std::is_convertible_v<ControlResponse::Error*, tlv::Error*>,
"ControlResponse::Error must inherit from tlv::Error");
ControlResponse::ControlResponse()
+31 -24
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -42,25 +42,29 @@ namespace mgmt {
* the Authorization function; this value is intended for logging only,
* and should not affect how the request is processed
*/
typedef std::function<void(const std::string& requester)> AcceptContinuation;
using AcceptContinuation = std::function<void(const std::string& requester)>;
/** \brief Indicate how to reply in case authorization is rejected.
/**
* \brief Indicates how to reply in case authorization is rejected.
*/
enum class RejectReply {
/** \brief Do not reply.
/**
* \brief Do not reply.
*/
SILENT,
/** \brief Reply with a ControlResponse where StatusCode is 403.
/**
* \brief Reply with a ControlResponse where StatusCode is 403.
*/
STATUS403
};
/** \brief A function to be called if authorization is rejected.
/**
* \brief A function to be called if authorization is rejected.
*/
typedef std::function<void(RejectReply reply)> RejectContinuation;
using RejectContinuation = std::function<void(RejectReply)>;
/** \brief A function that performs authorization.
* \param prefix top-level prefix, e.g., "/localhost/nfd";
* \param prefix top-level prefix, e.g., `/localhost/nfd`;
* This argument can be inspected to allow Interests only under a subset of
* top-level prefixes (e.g., allow "/localhost/nfd" only),
* or to use different trust model regarding to the prefix.
@@ -69,14 +73,15 @@ typedef std::function<void(RejectReply reply)> RejectContinuation;
* This is guaranteed to be not-null and have correct type for the command,
* but may not be valid (e.g., can have missing fields).
*
* Either accept or reject must be called after authorization completes.
* Either \p accept or \p reject must be called after authorization completes.
*/
typedef std::function<void(const Name& prefix, const Interest& interest,
const ControlParameters* params,
const AcceptContinuation& accept,
const RejectContinuation& reject)> Authorization;
using Authorization = std::function<void(const Name& prefix, const Interest& interest,
const ControlParameters* params,
const AcceptContinuation& accept,
const RejectContinuation& reject)>;
/** \brief Return an Authorization that accepts all Interests, with empty string as requester.
/**
* \brief Return an Authorization that accepts all Interests, with empty string as requester.
*/
Authorization
makeAcceptAllAuthorization();
@@ -87,12 +92,12 @@ makeAcceptAllAuthorization();
* \param params parsed ControlParameters;
* This is guaranteed to have correct type for the command.
*/
typedef std::function<bool(const ControlParameters& params)> ValidateParameters;
using ValidateParameters = std::function<bool(const ControlParameters& params)>;
/** \brief A function to be called after ControlCommandHandler completes.
* \param resp the response to be sent to requester
*/
typedef std::function<void(const ControlResponse& resp)> CommandContinuation;
using CommandContinuation = std::function<void(const ControlResponse& resp)>;
/** \brief A function to handle an authorized ControlCommand.
* \param prefix top-level prefix, e.g., "/localhost/nfd";
@@ -101,9 +106,9 @@ typedef std::function<void(const ControlResponse& resp)> CommandContinuation;
* This is guaranteed to have correct type for the command,
* and is valid (e.g., has all required fields).
*/
typedef std::function<void(const Name& prefix, const Interest& interest,
const ControlParameters& params,
const CommandContinuation& done)> ControlCommandHandler;
using ControlCommandHandler = std::function<void(const Name& prefix, const Interest& interest,
const ControlParameters& params,
const CommandContinuation& done)>;
// ---- STATUS DATASET ----
@@ -114,18 +119,20 @@ typedef std::function<void(const Name& prefix, const Interest& interest,
* This function can generate zero or more blocks and pass them to \p append,
* and must call \p end upon completion.
*/
typedef std::function<void(const Name& prefix, const Interest& interest,
StatusDatasetContext& context)> StatusDatasetHandler;
using StatusDatasetHandler = std::function<void(const Name& prefix, const Interest& interest,
StatusDatasetContext& context)>;
//---- NOTIFICATION STREAM ----
/** \brief A function to post a notification.
/**
* \brief A function to post a notification.
*/
typedef std::function<void(const Block& notification)> PostNotification;
using PostNotification = std::function<void(const Block& notification)>;
// ---- DISPATCHER ----
/** \brief Implements a request dispatcher on server side of NFD Management protocol.
/**
* \brief Implements a request dispatcher on server side of NFD Management protocol.
*/
class Dispatcher : noncopyable
{
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2019 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -31,7 +31,7 @@ namespace nfd {
//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ControlParameters>));
BOOST_CONCEPT_ASSERT((WireEncodable<ControlParameters>));
BOOST_CONCEPT_ASSERT((WireDecodable<ControlParameters>));
static_assert(std::is_base_of<tlv::Error, ControlParameters::Error>::value,
static_assert(std::is_convertible_v<ControlParameters::Error*, tlv::Error*>,
"ControlParameters::Error must inherit from tlv::Error");
ControlParameters::ControlParameters()
+8 -8
View File
@@ -48,8 +48,8 @@ Controller::~Controller()
void
Controller::startCommand(const shared_ptr<ControlCommand>& command,
const ControlParameters& parameters,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure,
const CommandSuccessCallback& onSuccess,
const CommandFailureCallback& onFailure,
const CommandOptions& options)
{
Interest interest;
@@ -75,8 +75,8 @@ Controller::startCommand(const shared_ptr<ControlCommand>& command,
void
Controller::processCommandResponse(const Data& data,
const shared_ptr<ControlCommand>& command,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure)
const CommandSuccessCallback& onSuccess,
const CommandFailureCallback& onFailure)
{
m_validator.validate(data,
[=] (const Data& data) {
@@ -92,8 +92,8 @@ Controller::processCommandResponse(const Data& data,
void
Controller::processValidatedCommandResponse(const Data& data,
const shared_ptr<ControlCommand>& command,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure)
const CommandSuccessCallback& onSuccess,
const CommandFailureCallback& onFailure)
{
ControlResponse response;
try {
@@ -138,7 +138,7 @@ Controller::processValidatedCommandResponse(const Data& data,
void
Controller::fetchDataset(const Name& prefix,
const std::function<void(ConstBufferPtr)>& processResponse,
const DatasetFailCallback& onFailure,
const DatasetFailureCallback& onFailure,
const CommandOptions& options)
{
SegmentFetcher::Options fetcherOptions;
@@ -160,7 +160,7 @@ Controller::fetchDataset(const Name& prefix,
}
void
Controller::processDatasetFetchError(const DatasetFailCallback& onFailure,
Controller::processDatasetFetchError(const DatasetFailureCallback& onFailure,
uint32_t code, std::string msg)
{
BOOST_ASSERT(onFailure);
+49 -58
View File
@@ -53,17 +53,26 @@ public:
/**
* \brief Callback on command success.
*/
using CommandSucceedCallback = std::function<void(const ControlParameters&)>;
using CommandSuccessCallback = std::function<void(const ControlParameters&)>;
/**
* \brief Callback on command failure.
*/
using CommandFailCallback = std::function<void(const ControlResponse&)>;
using CommandFailureCallback = std::function<void(const ControlResponse&)>;
using CommandFailCallback = CommandFailureCallback; // backward compat
/**
* \brief Callback on dataset retrieval success.
*/
template<typename Dataset>
using DatasetSuccessCallback = std::function<void(const std::invoke_result_t<decltype(&Dataset::parseResult),
Dataset, ConstBufferPtr>&)>;
/**
* \brief Callback on dataset retrieval failure.
*/
using DatasetFailCallback = std::function<void(uint32_t code, const std::string& reason)>;
using DatasetFailureCallback = std::function<void(uint32_t code, const std::string& reason)>;
using DatasetFailCallback = DatasetFailureCallback; // backward compat
/**
* \brief Construct a Controller that uses \p face as transport and \p keyChain to sign commands.
@@ -79,80 +88,74 @@ public:
template<typename Command>
void
start(const ControlParameters& parameters,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure,
const CommandSuccessCallback& onSuccess,
const CommandFailureCallback& onFailure,
const CommandOptions& options = CommandOptions())
{
startCommand(make_shared<Command>(), parameters, onSuccess, onFailure, options);
startCommand(std::make_shared<Command>(), parameters, onSuccess, onFailure, options);
}
/**
* \brief Start dataset fetching.
*/
template<typename Dataset>
std::enable_if_t<std::is_default_constructible<Dataset>::value>
fetch(const std::function<void(typename Dataset::ResultType)>& onSuccess,
const DatasetFailCallback& onFailure,
std::enable_if_t<std::is_default_constructible_v<Dataset>>
fetch(const DatasetSuccessCallback<Dataset>& onSuccess,
const DatasetFailureCallback& onFailure,
const CommandOptions& options = CommandOptions())
{
fetchDataset(make_shared<Dataset>(), onSuccess, onFailure, options);
fetchDataset(std::make_shared<Dataset>(), onSuccess, onFailure, options);
}
/**
* \brief Start dataset fetching.
*/
template<typename Dataset, typename ParamType = typename Dataset::ParamType>
template<typename Dataset, typename ParamType>
void
fetch(const ParamType& param,
const std::function<void(typename Dataset::ResultType)>& onSuccess,
const DatasetFailCallback& onFailure,
fetch(ParamType&& param,
const DatasetSuccessCallback<Dataset>& onSuccess,
const DatasetFailureCallback& onFailure,
const CommandOptions& options = CommandOptions())
{
fetchDataset(make_shared<Dataset>(param), onSuccess, onFailure, options);
fetchDataset(std::make_shared<Dataset>(std::forward<ParamType>(param)),
onSuccess, onFailure, options);
}
private:
void
startCommand(const shared_ptr<ControlCommand>& command,
const ControlParameters& parameters,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure,
const CommandSuccessCallback& onSuccess,
const CommandFailureCallback& onFailure,
const CommandOptions& options);
void
processCommandResponse(const Data& data,
const shared_ptr<ControlCommand>& command,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure);
const CommandSuccessCallback& onSuccess,
const CommandFailureCallback& onFailure);
void
processValidatedCommandResponse(const Data& data,
const shared_ptr<ControlCommand>& command,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure);
const CommandSuccessCallback& onSuccess,
const CommandFailureCallback& onFailure);
template<typename Dataset>
void
fetchDataset(shared_ptr<Dataset> dataset,
const std::function<void(typename Dataset::ResultType)>& onSuccess,
const DatasetFailCallback& onFailure,
const DatasetSuccessCallback<Dataset>& onSuccess,
const DatasetFailureCallback& onFailure,
const CommandOptions& options);
void
fetchDataset(const Name& prefix,
const std::function<void(ConstBufferPtr)>& processResponse,
const DatasetFailCallback& onFailure,
const DatasetFailureCallback& onFailure,
const CommandOptions& options);
template<typename Dataset>
void
processDatasetResponse(shared_ptr<Dataset> dataset,
const std::function<void(typename Dataset::ResultType)>& onSuccess,
const DatasetFailCallback& onFailure,
ConstBufferPtr payload);
void
processDatasetFetchError(const DatasetFailCallback& onFailure, uint32_t code, std::string msg);
processDatasetFetchError(const DatasetFailureCallback& onFailure, uint32_t code, std::string msg);
public:
/// Error code for timeout.
@@ -183,40 +186,28 @@ NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
template<typename Dataset>
void
Controller::fetchDataset(shared_ptr<Dataset> dataset,
const std::function<void(typename Dataset::ResultType)>& onSuccess,
const DatasetFailCallback& onFailure,
const DatasetSuccessCallback<Dataset>& onSuccess,
const DatasetFailureCallback& onFailure,
const CommandOptions& options)
{
Name prefix = dataset->getDatasetPrefix(options.getPrefix());
fetchDataset(prefix,
[=, d = std::move(dataset)] (ConstBufferPtr p) {
processDatasetResponse(std::move(d), onSuccess, onFailure, std::move(p));
[dataset = std::move(dataset), onSuccess, onFailure] (ConstBufferPtr payload) {
std::invoke_result_t<decltype(&Dataset::parseResult), Dataset, ConstBufferPtr> result;
try {
result = dataset->parseResult(std::move(payload));
}
catch (const tlv::Error& e) {
if (onFailure)
onFailure(ERROR_SERVER, e.what());
return;
}
if (onSuccess)
onSuccess(result);
},
onFailure, options);
}
template<typename Dataset>
void
Controller::processDatasetResponse(shared_ptr<Dataset> dataset,
const std::function<void(typename Dataset::ResultType)>& onSuccess,
const DatasetFailCallback& onFailure,
ConstBufferPtr payload)
{
typename Dataset::ResultType result;
try {
result = dataset->parseResult(std::move(payload));
}
catch (const tlv::Error& e) {
if (onFailure)
onFailure(ERROR_SERVER, e.what());
return;
}
if (onSuccess)
onSuccess(result);
}
} // namespace nfd
} // namespace ndn
+1 -1
View File
@@ -30,7 +30,7 @@ namespace nfd {
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<FaceQueryFilter>));
BOOST_CONCEPT_ASSERT((WireEncodable<FaceQueryFilter>));
BOOST_CONCEPT_ASSERT((WireDecodable<FaceQueryFilter>));
static_assert(std::is_base_of<tlv::Error, FaceQueryFilter::Error>::value,
static_assert(std::is_convertible_v<FaceQueryFilter::Error*, tlv::Error*>,
"FaceQueryFilter::Error must inherit from tlv::Error");
FaceQueryFilter::FaceQueryFilter() = default;
+9 -11
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -63,9 +63,7 @@ parseDatasetVector(const ConstBufferPtr& payload)
size_t offset = 0;
while (offset < payload->size()) {
bool isOk = false;
Block block;
std::tie(isOk, block) = Block::fromBuffer(payload, offset);
auto [isOk, block] = Block::fromBuffer(payload, offset);
if (!isOk) {
NDN_THROW(StatusDataset::ParseResultError("cannot decode Block"));
}
@@ -82,7 +80,7 @@ ForwarderGeneralStatusDataset::ForwarderGeneralStatusDataset()
{
}
ForwarderGeneralStatusDataset::ResultType
ForwarderStatus
ForwarderGeneralStatusDataset::parseResult(ConstBufferPtr payload) const
{
return ForwarderStatus(Block(tlv::Content, std::move(payload)));
@@ -93,7 +91,7 @@ FaceDatasetBase::FaceDatasetBase(const PartialName& datasetName)
{
}
FaceDatasetBase::ResultType
std::vector<FaceStatus>
FaceDatasetBase::parseResult(ConstBufferPtr payload) const
{
return parseDatasetVector<FaceStatus>(payload);
@@ -121,7 +119,7 @@ ChannelDataset::ChannelDataset()
{
}
ChannelDataset::ResultType
std::vector<ChannelStatus>
ChannelDataset::parseResult(ConstBufferPtr payload) const
{
return parseDatasetVector<ChannelStatus>(payload);
@@ -132,7 +130,7 @@ FibDataset::FibDataset()
{
}
FibDataset::ResultType
std::vector<FibEntry>
FibDataset::parseResult(ConstBufferPtr payload) const
{
return parseDatasetVector<FibEntry>(payload);
@@ -143,7 +141,7 @@ CsInfoDataset::CsInfoDataset()
{
}
CsInfoDataset::ResultType
CsInfo
CsInfoDataset::parseResult(ConstBufferPtr payload) const
{
return CsInfo(Block(payload));
@@ -154,7 +152,7 @@ StrategyChoiceDataset::StrategyChoiceDataset()
{
}
StrategyChoiceDataset::ResultType
std::vector<StrategyChoice>
StrategyChoiceDataset::parseResult(ConstBufferPtr payload) const
{
return parseDatasetVector<StrategyChoice>(payload);
@@ -165,7 +163,7 @@ RibDataset::RibDataset()
{
}
RibDataset::ResultType
std::vector<RibEntry>
RibDataset::parseResult(ConstBufferPtr payload) const
{
return parseDatasetVector<RibEntry>(payload);
+18 -47
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -46,31 +46,17 @@ public:
virtual
~StatusDataset();
#ifdef DOXYGEN
/**
* \brief If defined, specifies constructor argument type;
* otherwise, the constructor has no arguments.
*/
using ParamType = int;
#endif
/**
* \brief Constructs a name prefix for the dataset.
* \param prefix top-level prefix, such as ndn:/localhost/nfd
* \param prefix Top-level prefix, such as `/localhost/nfd`.
* \return %Name prefix without version and segment components.
*/
Name
getDatasetPrefix(const Name& prefix) const;
#ifdef DOXYGEN
/**
* \brief Specifies the result type, usually a vector.
*/
using ResultType = std::vector<int>;
#endif
/**
* \brief Indicates reassembled payload cannot be parsed as ResultType.
* \brief Indicates the reassembled payload cannot be parsed successfully.
* \sa parseResult()
*/
class ParseResultError : public tlv::Error
{
@@ -80,9 +66,10 @@ public:
#ifdef DOXYGEN
/**
* \brief Parses a result from reassembled payload.
* \param payload reassembled payload
* \throw tlv::Error cannot parse payload
* \brief Parses a result from a reassembled payload.
* \param payload The reassembled payload.
* \return The parsed result, usually a vector.
* \throw tlv::Error Cannot parse the payload.
*/
ResultType
parseResult(ConstBufferPtr payload) const;
@@ -90,8 +77,8 @@ public:
protected:
/**
* \brief Constructs a StatusDataset instance with given sub-prefix.
* \param datasetName dataset name after top-level prefix, such as faces/list
* \brief Constructs a StatusDataset instance with the given sub-prefix.
* \param datasetName Dataset name after top-level prefix, such as `faces/list`.
*/
explicit
StatusDataset(const PartialName& datasetName);
@@ -99,7 +86,7 @@ protected:
private:
/**
* \brief Appends parameters to the dataset name prefix.
* \param[in,out] the dataset name prefix onto which parameter components can be appended
* \param[in,out] name The dataset name prefix onto which parameter components can be appended.
*/
virtual void
addParameters(Name& name) const;
@@ -118,9 +105,7 @@ class ForwarderGeneralStatusDataset : public StatusDataset
public:
ForwarderGeneralStatusDataset();
using ResultType = ForwarderStatus;
ResultType
ForwarderStatus
parseResult(ConstBufferPtr payload) const;
};
@@ -131,9 +116,7 @@ public:
class FaceDatasetBase : public StatusDataset
{
public:
using ResultType = std::vector<FaceStatus>;
ResultType
std::vector<FaceStatus>
parseResult(ConstBufferPtr payload) const;
protected:
@@ -160,8 +143,6 @@ public:
class FaceQueryDataset : public FaceDatasetBase
{
public:
using ParamType = FaceQueryFilter;
explicit
FaceQueryDataset(const FaceQueryFilter& filter);
@@ -183,9 +164,7 @@ class ChannelDataset : public StatusDataset
public:
ChannelDataset();
using ResultType = std::vector<ChannelStatus>;
ResultType
std::vector<ChannelStatus>
parseResult(ConstBufferPtr payload) const;
};
@@ -199,9 +178,7 @@ class FibDataset : public StatusDataset
public:
FibDataset();
using ResultType = std::vector<FibEntry>;
ResultType
std::vector<FibEntry>
parseResult(ConstBufferPtr payload) const;
};
@@ -215,9 +192,7 @@ class CsInfoDataset : public StatusDataset
public:
CsInfoDataset();
using ResultType = CsInfo;
ResultType
CsInfo
parseResult(ConstBufferPtr payload) const;
};
@@ -231,9 +206,7 @@ class StrategyChoiceDataset : public StatusDataset
public:
StrategyChoiceDataset();
using ResultType = std::vector<StrategyChoice>;
ResultType
std::vector<StrategyChoice>
parseResult(ConstBufferPtr payload) const;
};
@@ -247,9 +220,7 @@ class RibDataset : public StatusDataset
public:
RibDataset();
using ResultType = std::vector<RibEntry>;
ResultType
std::vector<RibEntry>
parseResult(ConstBufferPtr payload) const;
};
+3 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -39,7 +39,7 @@ BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Component>));
BOOST_CONCEPT_ASSERT((WireEncodable<Component>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Component>));
BOOST_CONCEPT_ASSERT((WireDecodable<Component>));
static_assert(std::is_base_of<tlv::Error, Component::Error>::value,
static_assert(std::is_convertible_v<Component::Error*, tlv::Error*>,
"name::Component::Error must inherit from tlv::Error");
static Convention g_conventionEncoding = Convention::TYPED;
@@ -498,9 +498,7 @@ Component::compare(const Component& other) const
Component
Component::getSuccessor() const
{
bool isOverflow = false;
Component successor;
std::tie(isOverflow, successor) = getComponentTypeTable().get(type()).getSuccessor(*this);
auto [isOverflow, successor] = getComponentTypeTable().get(type()).getSuccessor(*this);
if (!isOverflow) {
return successor;
}
+2 -3
View File
@@ -44,7 +44,7 @@ BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_iterator>));
BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::reverse_iterator>));
BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_reverse_iterator>));
BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept<Name>));
static_assert(std::is_base_of<tlv::Error, Name::Error>::value,
static_assert(std::is_convertible_v<Name::Error*, tlv::Error*>,
"Name::Error must inherit from tlv::Error");
// ---- constructors, encoding, decoding ----
@@ -70,8 +70,7 @@ Name::Name(std::string uri)
if (uri.empty())
return;
size_t iColon = uri.find(':');
if (iColon != std::string::npos) {
if (size_t iColon = uri.find(':'); iColon != std::string::npos) {
// Make sure the colon came before a '/'.
size_t iFirstSlash = uri.find('/');
if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
+2 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California,
* Copyright (c) 2013-2023 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -356,9 +356,7 @@ private:
const FaceUri::CanonizeFailureCallback& onFailure,
const dns::IpAddress& ipAddress) const
{
bool isOk = false;
std::string reason;
std::tie(isOk, reason) = this->checkAddress(ipAddress);
auto [isOk, reason] = this->checkAddress(ipAddress);
if (!isOk) {
return onFailure(reason);
}
+3 -3
View File
@@ -262,7 +262,7 @@ private:
}
template<typename Integral>
static std::enable_if_t<std::is_integral<Integral>::value, std::optional<Integral>>
static std::enable_if_t<std::is_integral_v<Integral>, std::optional<Integral>>
convertAttrValue(const uint8_t* val, size_t len, AttrValueTypeTag<Integral>)
{
if (len < sizeof(Integral))
@@ -293,8 +293,8 @@ private:
}
template<typename IpAddress>
static std::enable_if_t<std::is_same<IpAddress, boost::asio::ip::address_v4>::value ||
std::is_same<IpAddress, boost::asio::ip::address_v6>::value,
static std::enable_if_t<std::is_same_v<IpAddress, boost::asio::ip::address_v4> ||
std::is_same_v<IpAddress, boost::asio::ip::address_v6>,
std::optional<IpAddress>>
convertAttrValue(const uint8_t* val, size_t len, AttrValueTypeTag<IpAddress>)
{
+5 -7
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2020 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -198,7 +198,7 @@ NetlinkSocket::registerRequestCallback(uint32_t seq, MessageCallback cb)
}
else {
bool wasEmpty = m_pendingRequests.empty();
m_pendingRequests.emplace(seq, std::move(cb));
m_pendingRequests.try_emplace(seq, std::move(cb));
if (wasEmpty)
asyncWait();
}
@@ -445,11 +445,9 @@ GenlSocket::sendRequest(const std::string& familyName, uint8_t command,
return;
}
auto ret = m_familyResolvers.emplace(std::piecewise_construct,
std::forward_as_tuple(familyName),
std::forward_as_tuple(familyName, *this));
auto& resolver = ret.first->second;
if (ret.second) {
auto [resIt, isNew] = m_familyResolvers.try_emplace(familyName, familyName, *this);
auto& resolver = resIt->second;
if (isNew) {
// cache the result
resolver.onResolved.connectSingleShot([=] (uint16_t familyId) {
m_cachedFamilyIds[familyName] = familyId;
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2019 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -69,7 +69,7 @@ public: // internal
addInterface(shared_ptr<NetworkInterface> netif)
{
BOOST_ASSERT(netif != nullptr);
bool isNew = m_interfaces.emplace(netif->getName(), netif).second;
bool isNew = m_interfaces.try_emplace(netif->getName(), netif).second;
if (!isNew) {
NDN_THROW(std::invalid_argument("duplicate ifname"));
}
+1 -1
View File
@@ -24,7 +24,7 @@
namespace ndn {
static_assert(std::is_base_of<tlv::Error, PrefixAnnouncement::Error>::value,
static_assert(std::is_convertible_v<PrefixAnnouncement::Error*, tlv::Error*>,
"PrefixAnnouncement::Error must inherit from tlv::Error");
PrefixAnnouncement::PrefixAnnouncement() = default;
+6 -6
View File
@@ -32,7 +32,7 @@ BOOST_CONCEPT_ASSERT((boost::EqualityComparable<AdditionalDescription>));
BOOST_CONCEPT_ASSERT((WireEncodable<AdditionalDescription>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<AdditionalDescription>));
BOOST_CONCEPT_ASSERT((WireDecodable<AdditionalDescription>));
static_assert(std::is_base_of<tlv::Error, AdditionalDescription::Error>::value,
static_assert(std::is_convertible_v<AdditionalDescription::Error*, tlv::Error*>,
"AdditionalDescription::Error must inherit from tlv::Error");
constexpr size_t KEY_OFFSET = 0;
@@ -46,11 +46,11 @@ AdditionalDescription::AdditionalDescription(const Block& block)
const std::string&
AdditionalDescription::get(const std::string& key) const
{
auto it = m_info.find(key);
if (it == m_info.end())
NDN_THROW(Error("Entry does not exist for key (" + key + ")"));
if (auto it = m_info.find(key); it != m_info.end()) {
return it->second;
}
return it->second;
NDN_THROW(Error("Entry does not exist for key (" + key + ")"));
}
void
@@ -62,7 +62,7 @@ AdditionalDescription::set(const std::string& key, const std::string& value)
bool
AdditionalDescription::has(const std::string& key) const
{
return (m_info.find(key) != m_info.end());
return m_info.find(key) != m_info.end();
}
AdditionalDescription::iterator
+6 -9
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2020 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -34,21 +34,18 @@ CertificateStorage::CertificateStorage()
const Certificate*
CertificateStorage::findTrustedCert(const Interest& interestForCert) const
{
auto cert = m_trustAnchors.find(interestForCert);
if (cert != nullptr) {
if (auto cert = m_trustAnchors.find(interestForCert); cert != nullptr) {
return cert;
}
cert = m_verifiedCertCache.find(interestForCert);
return cert;
return m_verifiedCertCache.find(interestForCert);
}
bool
CertificateStorage::isCertKnown(const Name& certName) const
{
return (m_trustAnchors.find(certName) != nullptr ||
m_verifiedCertCache.find(certName) != nullptr ||
m_unverifiedCertCache.find(certName) != nullptr);
return m_trustAnchors.find(certName) != nullptr ||
m_verifiedCertCache.find(certName) != nullptr ||
m_unverifiedCertCache.find(certName) != nullptr;
}
void
+1 -1
View File
@@ -33,7 +33,7 @@ inline namespace v2 {
BOOST_CONCEPT_ASSERT((WireEncodable<Certificate>));
BOOST_CONCEPT_ASSERT((WireDecodable<Certificate>));
static_assert(std::is_base_of<Data::Error, Certificate::Error>::value,
static_assert(std::is_convertible_v<Certificate::Error*, Data::Error*>,
"Certificate::Error must inherit from Data::Error");
Certificate::Certificate()
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -43,9 +43,7 @@ CertificateBundleDecoder::decode()
auto onThrow = make_scope_fail([this] { m_hasError = true; });
while (!m_bufferedData.empty()) {
bool isOk;
Block element;
std::tie(isOk, element) = Block::fromBuffer(m_bufferedData);
auto [isOk, element] = Block::fromBuffer(m_bufferedData);
if (!isOk) {
return;
}
+5 -15
View File
@@ -402,12 +402,9 @@ KeyChain::importPrivateKey(const Name& keyName, shared_ptr<transform::PrivateKey
void
KeyChain::sign(Data& data, const SigningInfo& params)
{
Name keyName;
SignatureInfo sigInfo;
std::tie(keyName, sigInfo) = prepareSignatureInfo(params);
auto [keyName, sigInfo] = prepareSignatureInfo(params);
data.setSignatureInfo(sigInfo);
EncodingBuffer encoder;
data.wireEncode(encoder, true);
@@ -418,9 +415,7 @@ KeyChain::sign(Data& data, const SigningInfo& params)
void
KeyChain::sign(Interest& interest, const SigningInfo& params)
{
Name keyName;
SignatureInfo sigInfo;
std::tie(keyName, sigInfo) = prepareSignatureInfo(params);
auto [keyName, sigInfo] = prepareSignatureInfo(params);
if (params.getSignedInterestFormat() == SignedInterestFormat::V03) {
interest.setSignatureInfo(sigInfo);
@@ -473,8 +468,7 @@ KeyChain::makeCertificate(const Certificate& certRequest, const SigningInfo& par
static std::tuple<std::string/*scheme*/, std::string/*location*/>
parseLocatorUri(const std::string& uri)
{
auto pos = uri.find(':');
if (pos != std::string::npos) {
if (auto pos = uri.find(':'); pos != std::string::npos) {
return {uri.substr(0, pos), uri.substr(pos + 1)};
}
else {
@@ -485,9 +479,7 @@ parseLocatorUri(const std::string& uri)
KeyChain::Locator
KeyChain::parseAndCheckPibLocator(const std::string& pibLocator)
{
std::string pibScheme, pibLocation;
std::tie(pibScheme, pibLocation) = parseLocatorUri(pibLocator);
auto [pibScheme, pibLocation] = parseLocatorUri(pibLocator);
if (pibScheme.empty()) {
pibScheme = getDefaultPibScheme();
}
@@ -503,9 +495,7 @@ KeyChain::parseAndCheckPibLocator(const std::string& pibLocator)
KeyChain::Locator
KeyChain::parseAndCheckTpmLocator(const std::string& tpmLocator)
{
std::string tpmScheme, tpmLocation;
std::tie(tpmScheme, tpmLocation) = parseLocatorUri(tpmLocator);
auto [tpmScheme, tpmLocation] = parseLocatorUri(tpmLocator);
if (tpmScheme.empty()) {
tpmScheme = getDefaultTpmScheme();
}
+6 -6
View File
@@ -34,26 +34,26 @@ namespace ndn {
namespace security {
/**
* @brief Options to KeyChain::makeCertificate() .
* @brief Options to KeyChain::makeCertificate().
*/
struct MakeCertificateOptions
{
/**
* @brief Certificate name IssuerId component.
* @brief %Certificate name IssuerId component.
*
* Default is "NA".
*/
name::Component issuerId = Certificate::DEFAULT_ISSUER_ID;
/**
* @brief Certificate name version component.
* @brief %Certificate name version component.
*
* Default is deriving from current timestamp using the logic of Name::appendVersion() .
* Default is deriving from current timestamp using the logic of Name::appendVersion().
*/
std::optional<uint64_t> version;
/**
* @brief Certificate packet FreshnessPeriod.
* @brief %Certificate packet FreshnessPeriod.
*
* As required by the certificate format, this must be positive.
* Setting this to zero or negative causes @c std::invalid_argument exception.
@@ -63,7 +63,7 @@ struct MakeCertificateOptions
time::milliseconds freshnessPeriod = 1_h;
/**
* @brief Certificate ValidityPeriod.
* @brief %Certificate ValidityPeriod.
*
* It isn't an error to specify a ValidityPeriod that does not include the current time
* or has zero duration, but the certificate won't be valid.
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -196,10 +196,10 @@ private:
};
/// @brief RsaKeyParams carries parameters for RSA key.
typedef SimplePublicKeyParams<detail::RsaKeyParamsInfo> RsaKeyParams;
using RsaKeyParams = SimplePublicKeyParams<detail::RsaKeyParamsInfo>;
/// @brief EcKeyParams carries parameters for EC key.
typedef SimplePublicKeyParams<detail::EcKeyParamsInfo> EcKeyParams;
using EcKeyParams = SimplePublicKeyParams<detail::EcKeyParamsInfo>;
namespace detail {
@@ -303,10 +303,10 @@ private:
};
/// @brief AesKeyParams carries parameters for AES key.
typedef SimpleSymmetricKeyParams<detail::AesKeyParamsInfo> AesKeyParams;
using AesKeyParams = SimpleSymmetricKeyParams<detail::AesKeyParamsInfo>;
/// @brief HmacKeyParams carries parameters for HMAC key.
typedef SimpleSymmetricKeyParams<detail::HmacKeyParamsInfo> HmacKeyParams;
using HmacKeyParams = SimpleSymmetricKeyParams<detail::HmacKeyParamsInfo>;
} // namespace ndn
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -113,8 +113,7 @@ CertificateContainer::get(const Name& certName) const
"does not match key `" + m_keyName.toUri() + "`"));
}
auto it = m_certs.find(certName);
if (it != m_certs.end()) {
if (auto it = m_certs.find(certName); it != m_certs.end()) {
return it->second;
}
+2 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -106,8 +106,7 @@ IdentityContainer::remove(const Name& identityName)
Identity
IdentityContainer::get(const Name& identityName) const
{
auto it = m_identities.find(identityName);
if (it != m_identities.end()) {
if (auto it = m_identities.find(identityName); it != m_identities.end()) {
return Identity(it->second);
}
+2 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -115,8 +115,7 @@ KeyContainer::get(const Name& keyName) const
"`" + m_identity.toUri() + "`"));
}
auto it = m_keys.find(keyName);
if (it != m_keys.end()) {
if (auto it = m_keys.find(keyName); it != m_keys.end()) {
return Key(it->second);
}
+8 -8
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -41,7 +41,7 @@ public:
};
BackEndMem::BackEndMem(const std::string&)
: m_impl(make_unique<Impl>())
: m_impl(std::make_unique<Impl>())
{
}
@@ -63,10 +63,10 @@ BackEndMem::doHasKey(const Name& keyName) const
unique_ptr<KeyHandle>
BackEndMem::doGetKeyHandle(const Name& keyName) const
{
auto it = m_impl->keys.find(keyName);
if (it == m_impl->keys.end())
return nullptr;
return make_unique<KeyHandleMem>(it->second);
if (auto it = m_impl->keys.find(keyName); it != m_impl->keys.end()) {
return std::make_unique<KeyHandleMem>(it->second);
}
return nullptr;
}
unique_ptr<KeyHandle>
@@ -83,7 +83,7 @@ BackEndMem::doCreateKey(const Name& identityName, const KeyParams& params)
}
shared_ptr<PrivateKey> key(transform::generatePrivateKey(params).release());
unique_ptr<KeyHandle> keyHandle = make_unique<KeyHandleMem>(key);
unique_ptr<KeyHandle> keyHandle = std::make_unique<KeyHandleMem>(key);
Name keyName;
if (params.getKeyType() == KeyType::HMAC) {
@@ -115,7 +115,7 @@ BackEndMem::doExportKey(const Name& keyName, const char* pw, size_t pwLen)
void
BackEndMem::doImportKey(const Name& keyName, span<const uint8_t> pkcs8, const char* pw, size_t pwLen)
{
auto key = make_shared<PrivateKey>();
auto key = std::make_shared<PrivateKey>();
try {
key->loadPkcs8(pkcs8, pw, pwLen);
}
+4 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -21,7 +21,7 @@
#include "ndn-cxx/security/tpm/tpm.hpp"
#include "ndn-cxx/security/tpm/back-end.hpp"
#include "ndn-cxx/encoding/buffer-stream.hpp"
#include "ndn-cxx/encoding/buffer.hpp"
#include <boost/lexical_cast.hpp>
@@ -55,8 +55,7 @@ Tpm::createKey(const Name& identityName, const KeyParams& params)
void
Tpm::deleteKey(const Name& keyName)
{
auto it = m_keys.find(keyName);
if (it != m_keys.end())
if (auto it = m_keys.find(keyName); it != m_keys.end())
m_keys.erase(it);
m_backEnd->deleteKey(keyName);
@@ -139,8 +138,7 @@ Tpm::importPrivateKey(const Name& keyName, shared_ptr<transform::PrivateKey> key
const KeyHandle*
Tpm::findKey(const Name& keyName) const
{
auto it = m_keys.find(keyName);
if (it != m_keys.end())
if (auto it = m_keys.find(keyName); it != m_keys.end())
return it->second.get();
auto handle = m_backEnd->getKeyHandle(keyName);
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2021 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -45,7 +45,7 @@ static const int8_t C2H[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 224-239
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 240-255
};
static_assert(std::extent<decltype(C2H)>::value == 256, "");
static_assert(std::extent_v<decltype(C2H)> == 256, "");
HexDecode::HexDecode()
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2021 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -29,13 +29,13 @@ static const uint8_t H2CL[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
static_assert(std::extent<decltype(H2CL)>::value == 16, "");
static_assert(std::extent_v<decltype(H2CL)> == 16, "");
static const uint8_t H2CU[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
static_assert(std::extent<decltype(H2CU)>::value == 16, "");
static_assert(std::extent_v<decltype(H2CU)> == 16, "");
HexEncode::HexEncode(bool useUpperCase)
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -50,10 +50,7 @@ void
ValidationPolicyCommandInterest::checkPolicy(const Interest& interest, const shared_ptr<ValidationState>& state,
const ValidationContinuation& continueValidation)
{
bool isOk;
Name keyName;
time::system_clock::TimePoint timestamp;
std::tie(isOk, keyName, timestamp) = parseCommandInterest(interest, state);
auto [isOk, keyName, timestamp] = parseCommandInterest(interest, state);
if (!isOk) {
return;
}
@@ -65,16 +62,16 @@ ValidationPolicyCommandInterest::checkPolicy(const Interest& interest, const sha
getInnerPolicy().checkPolicy(interest, state, continueValidation);
}
std::tuple<bool, Name, time::system_clock::TimePoint>
std::tuple<bool, Name, time::system_clock::time_point>
ValidationPolicyCommandInterest::parseCommandInterest(const Interest& interest,
const shared_ptr<ValidationState>& state)
{
auto sigInfo = getSignatureInfo(interest, *state);
if (!state->getOutcome()) { // already failed
return std::make_tuple(false, Name(), time::system_clock::TimePoint{});
return {false, {}, {}};
}
time::system_clock::TimePoint timestamp;
time::system_clock::time_point timestamp;
auto fmt = state->getTag<SignedInterestFormatTag>();
BOOST_ASSERT(fmt);
@@ -85,7 +82,7 @@ ValidationPolicyCommandInterest::parseCommandInterest(const Interest& interest,
if (!optionalTimestamp) {
state->fail({ValidationError::POLICY_ERROR, "Signed Interest `" +
interest.getName().toUri() + "` lacks required SignatureTime element"});
return std::make_tuple(false, Name(), time::system_clock::TimePoint{});
return {false, {}, {}};
}
timestamp = *optionalTimestamp;
@@ -95,14 +92,14 @@ ValidationPolicyCommandInterest::parseCommandInterest(const Interest& interest,
if (name.size() < command_interest::MIN_SIZE) {
state->fail({ValidationError::POLICY_ERROR,
"Command Interest name too short `" + interest.getName().toUri() + "`"});
return std::make_tuple(false, Name(), time::system_clock::TimePoint{});
return {false, {}, {}};
}
const auto& timestampComp = name.at(command_interest::POS_TIMESTAMP);
if (!timestampComp.isNumber()) {
state->fail({ValidationError::POLICY_ERROR, "Command Interest `" +
interest.getName().toUri() + "` lacks required timestamp component"});
return std::make_tuple(false, Name(), time::system_clock::TimePoint{});
return {false, {}, {}};
}
timestamp = time::fromUnixTimestamp(time::milliseconds(timestampComp.toNumber()));
@@ -110,10 +107,10 @@ ValidationPolicyCommandInterest::parseCommandInterest(const Interest& interest,
Name klName = getKeyLocatorName(sigInfo, *state);
if (!state->getOutcome()) { // already failed
return std::make_tuple(false, Name(), time::system_clock::TimePoint{});
return {false, {}, {}};
}
return std::make_tuple(true, klName, timestamp);
return {true, klName, timestamp};
}
void
@@ -130,7 +127,7 @@ ValidationPolicyCommandInterest::cleanup()
bool
ValidationPolicyCommandInterest::checkTimestamp(const shared_ptr<ValidationState>& state,
const Name& keyName, time::system_clock::TimePoint timestamp)
const Name& keyName, time::system_clock::time_point timestamp)
{
this->cleanup();
@@ -158,14 +155,11 @@ ValidationPolicyCommandInterest::checkTimestamp(const shared_ptr<ValidationState
}
void
ValidationPolicyCommandInterest::insertNewRecord(const Name& keyName, time::system_clock::TimePoint timestamp)
ValidationPolicyCommandInterest::insertNewRecord(const Name& keyName, time::system_clock::time_point timestamp)
{
// try to insert new record
auto now = time::steady_clock::now();
auto i = m_queue.end();
bool isNew = false;
LastTimestampRecord newRecord{keyName, timestamp, now};
std::tie(i, isNew) = m_queue.push_back(newRecord);
LastTimestampRecord newRecord{keyName, timestamp, time::steady_clock::now()};
auto [i, isNew] = m_queue.push_back(newRecord);
if (!isNew) {
BOOST_ASSERT(i->keyName == keyName);
@@ -147,9 +147,7 @@ ValidationPolicySignedInterest::insertRecord(const Name& keyName,
std::optional<SigNonce> nonce)
{
// If key record exists, update last refreshed time. Otherwise, create new record.
Container::nth_index<0>::type::iterator it;
bool isOk;
std::tie(it, isOk) = m_byKeyName.emplace(keyName, timestamp, seqNum);
auto [it, isOk] = m_byKeyName.emplace(keyName, timestamp, seqNum);
if (!isOk) {
// There was already a record for this key, we just need to update it
isOk = m_byKeyName.modify(it, [&] (LastInterestRecord& record) {
+1 -1
View File
@@ -30,7 +30,7 @@ BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ValidityPeriod>));
BOOST_CONCEPT_ASSERT((WireEncodable<ValidityPeriod>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<ValidityPeriod>));
BOOST_CONCEPT_ASSERT((WireDecodable<ValidityPeriod>));
static_assert(std::is_base_of<tlv::Error, ValidityPeriod::Error>::value,
static_assert(std::is_convertible_v<ValidityPeriod::Error*, tlv::Error*>,
"ValidityPeriod::Error must inherit from tlv::Error");
constexpr size_t ISO_DATETIME_SIZE = 15;
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -133,7 +133,7 @@ private: // EqualityComparable concept
}
private:
typedef boost::chrono::time_point<time::system_clock, time::seconds> TimePoint;
using TimePoint = boost::chrono::time_point<time::system_clock, time::seconds>;
TimePoint m_notBefore;
TimePoint m_notAfter;
+1 -1
View File
@@ -33,7 +33,7 @@ BOOST_CONCEPT_ASSERT((boost::EqualityComparable<SignatureInfo>));
BOOST_CONCEPT_ASSERT((WireEncodable<SignatureInfo>));
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<SignatureInfo>));
BOOST_CONCEPT_ASSERT((WireDecodable<SignatureInfo>));
static_assert(std::is_base_of<tlv::Error, SignatureInfo::Error>::value,
static_assert(std::is_convertible_v<SignatureInfo::Error*, tlv::Error*>,
"SignatureInfo::Error must inherit from tlv::Error");
SignatureInfo::SignatureInfo() = default;
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -221,12 +221,10 @@ protected:
processAllReceived(uint8_t* buffer, size_t& offset, size_t nBytesAvailable)
{
while (offset < nBytesAvailable) {
bool isOk = false;
Block element;
std::tie(isOk, element) = Block::fromBuffer({buffer + offset, nBytesAvailable - offset});
if (!isOk)
auto [isOk, element] = Block::fromBuffer({buffer + offset, nBytesAvailable - offset});
if (!isOk) {
return false;
}
m_transport.m_receiveCallback(element);
offset += element.size();
}
+1 -1
View File
@@ -44,7 +44,7 @@ template<typename T>
to_underlying(T val) noexcept
{
// instantiating underlying_type with a non-enum type is UB before C++20
static_assert(std::is_enum<T>::value, "");
static_assert(std::is_enum_v<T>, "");
return static_cast<std::underlying_type_t<T>>(val);
}
#endif // __cpp_lib_to_underlying
+5 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022 Regents of the University of California,
* Copyright (c) 2014-2023 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -98,11 +98,12 @@ class NfdMgmtProtocolStruct : public WireEncodable<X>
public:
BOOST_CONCEPT_USAGE(NfdMgmtProtocolStruct)
{
static_assert(std::is_default_constructible<X>::value, "");
static_assert(std::is_default_constructible_v<X>, "");
static_assert(boost::has_equal_to<X, X, bool>::value, "");
static_assert(boost::has_not_equal_to<X, X, bool>::value, "");
static_assert(boost::has_left_shift<std::ostream, X, std::ostream&>::value, "");
static_assert(std::is_base_of<tlv::Error, typename X::Error>::value, "");
static_assert(std::is_convertible_v<typename X::Error*, tlv::Error*>,
"ndn::tlv::Error must be a public base of X::Error");
}
};
@@ -145,8 +146,7 @@ class StlForwardIteratorConcept : public boost::ForwardIterator<T>
* SGI standard which doesn't require DefaultConstructible, so a separate check is needed.
*/
#define NDN_CXX_ASSERT_FORWARD_ITERATOR(T) \
static_assert(std::is_default_constructible<T>::value, \
#T " must be default-constructible"); \
static_assert(std::is_default_constructible_v<T>, #T " must be default-constructible"); \
BOOST_CONCEPT_ASSERT((::ndn::detail::StlForwardIteratorConcept<T>))
#endif // NDN_CXX_UTIL_CONCEPTS_HPP
+1 -1
View File
@@ -63,7 +63,7 @@ template<typename T>
static void
checkNestedError(typename T::Error*)
{
static_assert(std::is_convertible<typename T::Error*, tlv::Error*>::value,
static_assert(std::is_convertible_v<typename T::Error*, tlv::Error*>,
"T::Error, if defined, must be a subclass of ndn::tlv::Error");
}
+2 -3
View File
@@ -61,7 +61,7 @@ makeTimestamp()
std::string buffer(10 + 1 + 6 + 1, '\0'); // note 1 extra byte still needed for snprintf
BOOST_ASSERT_MSG(usecs / usecsPerSec <= 9999999999, "whole seconds cannot fit in 10 characters");
static_assert(std::is_same<microseconds::rep, int_least64_t>::value,
static_assert(std::is_same_v<microseconds::rep, int_least64_t>,
"PRIdLEAST64 is incompatible with microseconds::rep");
std::snprintf(&buffer.front(), buffer.size(), "%" PRIdLEAST64 ".%06" PRIdLEAST64,
usecs / usecsPerSec, usecs % usecsPerSec);
@@ -140,8 +140,7 @@ LogLevel
Logging::findLevel(std::string mn) const
{
while (!mn.empty()) {
auto it = m_enabledLevel.find(mn);
if (it != m_enabledLevel.end()) {
if (auto it = m_enabledLevel.find(mn); it != m_enabledLevel.end()) {
return it->second;
}
size_t pos = mn.find_last_of('.');
+2 -2
View File
@@ -66,13 +66,13 @@ public:
typedef void reference;
ostream_joiner(ostream_type& os, const DelimT& delimiter)
noexcept(std::is_nothrow_copy_constructible<DelimT>::value)
noexcept(std::is_nothrow_copy_constructible_v<DelimT>)
: m_os(std::addressof(os)), m_delim(delimiter)
{
}
ostream_joiner(ostream_type& os, DelimT&& delimiter)
noexcept(std::is_nothrow_move_constructible<DelimT>::value)
noexcept(std::is_nothrow_move_constructible_v<DelimT>)
: m_os(std::addressof(os)), m_delim(std::move(delimiter))
{
}
+4 -5
View File
@@ -198,7 +198,7 @@ SegmentFetcher::sendInterest(uint64_t segNum, const Interest& interest, bool isR
PendingSegment pendingSegment{SegmentState::FirstInterest, time::steady_clock::now(),
pendingInterest, timeoutEvent};
bool isNew = m_pendingSegments.emplace(segNum, std::move(pendingSegment)).second;
bool isNew = m_pendingSegments.try_emplace(segNum, std::move(pendingSegment)).second;
BOOST_VERIFY(isNew);
m_highInterest = segNum;
}
@@ -271,11 +271,10 @@ SegmentFetcher::afterValidationSuccess(const Data& data, const Interest& origInt
m_pendingSegments.erase(pendingSegmentIt);
// Copy data in segment to temporary buffer
auto receivedSegmentIt = m_segmentBuffer.emplace(std::piecewise_construct,
std::forward_as_tuple(currentSegment),
std::forward_as_tuple(data.getContent().value_size()));
auto receivedSegmentIt = m_segmentBuffer.try_emplace(currentSegment, data.getContent().value_size())
.first;
std::copy(data.getContent().value_begin(), data.getContent().value_end(),
receivedSegmentIt.first->second.begin());
receivedSegmentIt->second.begin());
m_nBytesReceived += data.getContent().value_size();
afterSegmentValidated(data);
+2 -2
View File
@@ -101,7 +101,7 @@ private: // API for owner
friend Owner;
private: // internal implementation
typedef Signal<Owner, TArgs...> Self;
using Self = Signal<Owner, TArgs...>;
/** \brief Stores a handler function, and a function to disconnect this handler.
*/
@@ -128,7 +128,7 @@ private: // internal implementation
* \note std::list is used because iterators must not be invalidated
* when other slots are added or removed
*/
typedef std::list<Slot> SlotList;
using SlotList = std::list<Slot>;
SlotList m_slots;
/** \brief Is a signal handler executing?
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2020 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -29,10 +29,10 @@ namespace tests {
template<typename F>
time::nanoseconds
timedExecute(const F& f)
timedExecute(F&& f)
{
auto before = time::steady_clock::now();
f();
std::invoke(std::forward<F>(f));
auto after = time::steady_clock::now();
return after - before;
}
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -59,10 +59,10 @@ using ArrayStream = boost::iostreams::stream<boost::iostreams::array_source>;
using StreamIterator = std::istream_iterator<uint8_t>;
#define ASSERT_READ_NUMBER_IS_FAST(T) \
static_assert(std::is_base_of<detail::ReadNumberFast<T>, detail::ReadNumber<T>>::value, \
static_assert(std::is_base_of_v<detail::ReadNumberFast<T>, detail::ReadNumber<T>>, \
# T " should use ReadNumberFast")
#define ASSERT_READ_NUMBER_IS_SLOW(T) \
static_assert(std::is_base_of<detail::ReadNumberSlow<T>, detail::ReadNumber<T>>::value, \
static_assert(std::is_base_of_v<detail::ReadNumberSlow<T>, detail::ReadNumber<T>>, \
# T " should use ReadNumberSlow")
ASSERT_READ_NUMBER_IS_FAST(const uint8_t*);
+3 -4
View File
@@ -25,7 +25,6 @@
#include "ndn-cxx/transport/unix-transport.hpp"
#include "ndn-cxx/util/config-file.hpp"
#include "ndn-cxx/util/dummy-client-face.hpp"
#include "ndn-cxx/util/scheduler.hpp"
#include "tests/test-common.hpp"
#include "tests/unit/io-key-chain-fixture.hpp"
@@ -46,10 +45,10 @@ class FaceFixture : public IoKeyChainFixture
{
protected:
FaceFixture()
: face(m_io, m_keyChain, {true, !std::is_same<PrefixRegReply, NoPrefixRegReply>::value})
: face(m_io, m_keyChain, {true, !std::is_same_v<PrefixRegReply, NoPrefixRegReply>})
{
static_assert(std::is_same<PrefixRegReply, WantPrefixRegReply>::value ||
std::is_same<PrefixRegReply, NoPrefixRegReply>::value, "");
static_assert(std::is_same_v<PrefixRegReply, WantPrefixRegReply> ||
std::is_same_v<PrefixRegReply, NoPrefixRegReply>, "");
}
/** \brief Execute a prefix registration, and optionally check the name in callback.
+3 -5
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -213,8 +213,7 @@ BOOST_AUTO_TEST_CASE(DecodeNormal)
BOOST_CHECK_EQUAL(packet.get<AckField>(2), 2);
BOOST_CHECK_EQUAL(packet.count<FragmentField>(), 1);
Buffer::const_iterator first, last;
std::tie(first, last) = packet.get<FragmentField>(0);
auto [first, last] = packet.get<FragmentField>(0);
BOOST_CHECK_EQUAL(2, last - first);
BOOST_CHECK_EQUAL(0x03, *first);
BOOST_CHECK_EQUAL(0xe8, *(last - 1));
@@ -253,8 +252,7 @@ BOOST_AUTO_TEST_CASE(DecodeFragment)
packet.wireDecode(wire);
BOOST_CHECK_EQUAL(1, packet.count<FragmentField>());
BOOST_CHECK_EQUAL(0, packet.count<FragIndexField>());
Buffer::const_iterator first, last;
std::tie(first, last) = packet.get<FragmentField>(0);
auto [first, last] = packet.get<FragmentField>(0);
BOOST_CHECK_EQUAL(2, last - first);
BOOST_CHECK_EQUAL(0x03, *first);
BOOST_CHECK_EQUAL(0xe8, *(last - 1));
+3 -4
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -23,7 +23,6 @@
#define NDN_CXX_TESTS_UNIT_MGMT_NFD_CONTROLLER_FIXTURE_HPP
#include "ndn-cxx/mgmt/nfd/controller.hpp"
#include "ndn-cxx/security/certificate-fetcher-offline.hpp"
#include "ndn-cxx/util/dummy-client-face.hpp"
#include "tests/unit/dummy-validator.hpp"
@@ -63,8 +62,8 @@ protected:
ndn::util::DummyClientFace face;
DummyValidator m_validator;
Controller controller;
Controller::CommandFailCallback commandFailCallback;
Controller::DatasetFailCallback datasetFailCallback;
Controller::CommandFailureCallback commandFailCallback;
Controller::DatasetFailureCallback datasetFailCallback;
std::vector<uint32_t> failCodes;
};
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -47,7 +47,7 @@ protected:
}
protected:
Controller::CommandSucceedCallback succeedCallback = [this] (const auto& params) {
Controller::CommandSuccessCallback succeedCallback = [this] (const auto& params) {
succeeds.push_back(params);
};
std::vector<ControlParameters> succeeds;
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -85,7 +85,7 @@ BOOST_FIXTURE_TEST_CASE(ConstructorSetter, ClockFixture)
BOOST_CHECK_EQUAL(validity2.isValid(), false);
validity2.setPeriod(notBefore, notAfter);
BOOST_CHECK(validity2.getPeriod() != std::make_pair(time::getUnixEpoch(), time::getUnixEpoch()));
BOOST_CHECK(validity2.getPeriod() != std::pair(time::getUnixEpoch(), time::getUnixEpoch()));
BOOST_CHECK_EQUAL(validity2, validity1);
validity1.setPeriod(time::getUnixEpoch(), time::getUnixEpoch() + 10 * 365_days);
+1 -1
View File
@@ -447,7 +447,7 @@ BOOST_AUTO_TEST_CASE(ValidityPeriod)
info2.setValidityPeriod(security::ValidityPeriod(notBefore, notBefore + 42_days));
BOOST_CHECK_NE(info2.getValidityPeriod(), vp1);
BOOST_CHECK(info2.getValidityPeriod().getPeriod() == std::make_pair(notBefore, notBefore + 42_days));
BOOST_CHECK(info2.getValidityPeriod().getPeriod() == std::pair(notBefore, notBefore + 42_days));
BOOST_CHECK_EQUAL(info2.hasWire(), false);
info2.wireEncode();
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE(Basic)
auto joiner1 = ostream_joiner<char>(os, ' ');
auto joiner2 = make_ostream_joiner(os, ' ');
static_assert(std::is_same<decltype(joiner1), decltype(joiner2)>::value, "");
static_assert(std::is_same_v<decltype(joiner1), decltype(joiner2)>, "");
std::vector<int> v(5);
std::iota(v.begin(), v.end(), 1);
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -100,8 +100,8 @@ ndnsec_cert_gen(int argc, char** argv)
additionalDescription.set(key, value);
}
time::system_clock::TimePoint notBefore;
time::system_clock::TimePoint notAfter;
time::system_clock::time_point notBefore;
time::system_clock::time_point notAfter;
if (vm.count("not-before") == 0) {
notBefore = time::system_clock::now();