Use Boost.Operators in more places
Change-Id: I7024c3e7d4c30c99ec7a895d484f227cb60fb356
This commit is contained in:
1 parent
ce442c4c95
commit
fffdd62715
47 files changed
+258
-453
No files matched your search
+10
-14
@@ -29,6 +29,8 @@
|
||||
#include "ndn-cxx/encoding/tlv.hpp"
|
||||
#include "ndn-cxx/util/span.hpp"
|
||||
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
namespace boost::asio {
|
||||
class const_buffer;
|
||||
} // namespace boost::asio
|
||||
@@ -39,7 +41,7 @@ namespace ndn {
|
||||
* @brief Represents a TLV element of the NDN packet format.
|
||||
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/tlv.html
|
||||
*/
|
||||
class Block
|
||||
class Block : private boost::equality_comparable<Block>
|
||||
{
|
||||
public:
|
||||
using value_type = Buffer::value_type;
|
||||
@@ -463,13 +465,6 @@ public: // misc
|
||||
*/
|
||||
operator boost::asio::const_buffer() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Returns whether this Block has the same TLV-TYPE/TLV-LENGTH/TLV-VALUE as @p other.
|
||||
*/
|
||||
bool
|
||||
equals(const Block& other) const noexcept;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Estimate Block size as if sub-elements are encoded into TLV-VALUE.
|
||||
@@ -491,12 +486,19 @@ private:
|
||||
size_t
|
||||
encode(EncodingBuffer& encoder);
|
||||
|
||||
/**
|
||||
* @brief Returns whether this Block has the same TLV-TYPE/TLV-LENGTH/TLV-VALUE as @p other.
|
||||
*/
|
||||
bool
|
||||
equals(const Block& other) const noexcept;
|
||||
|
||||
void
|
||||
print(std::ostream& os) const;
|
||||
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
// boost::equality_comparable provides != operator.
|
||||
|
||||
/**
|
||||
* @brief Compare whether two Blocks have the same TLV-TYPE, TLV-LENGTH, and TLV-VALUE.
|
||||
@@ -507,12 +509,6 @@ private: // non-member operators
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const Block& lhs, const Block& rhs) noexcept
|
||||
{
|
||||
return !lhs.equals(rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Print @p block to @p os.
|
||||
*
|
||||
|
||||
@@ -252,7 +252,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_v<ValueType, bool>, "");
|
||||
static_assert(sizeof(ValueType) == 1 && !std::is_same_v<ValueType, bool>);
|
||||
|
||||
size_t length = std::distance(first, last);
|
||||
reserveFront(length);
|
||||
@@ -267,7 +267,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_v<ValueType, bool>, "");
|
||||
static_assert(sizeof(ValueType) == 1 && !std::is_same_v<ValueType, bool>);
|
||||
|
||||
size_t length = std::distance(first, last);
|
||||
reserveBack(length);
|
||||
|
||||
@@ -121,8 +121,8 @@ operator>>(std::istream& is, RouteOrigin& routeOrigin)
|
||||
routeOrigin = ROUTE_ORIGIN_STATIC;
|
||||
else {
|
||||
// To reject negative numbers, we parse as a wider signed type, and compare with the range.
|
||||
static_assert(std::numeric_limits<std::underlying_type_t<RouteOrigin>>::max() <=
|
||||
std::numeric_limits<int>::max(), "");
|
||||
using RouteOriginUnderlyingType = std::underlying_type_t<RouteOrigin>;
|
||||
static_assert(std::numeric_limits<RouteOriginUnderlyingType>::max() <= std::numeric_limits<int>::max());
|
||||
|
||||
int v = -1;
|
||||
try {
|
||||
@@ -131,8 +131,8 @@ operator>>(std::istream& is, RouteOrigin& routeOrigin)
|
||||
catch (const boost::bad_lexical_cast&) {
|
||||
}
|
||||
|
||||
if (v >= std::numeric_limits<std::underlying_type_t<RouteOrigin>>::min() &&
|
||||
v <= std::numeric_limits<std::underlying_type_t<RouteOrigin>>::max()) {
|
||||
if (v >= std::numeric_limits<RouteOriginUnderlyingType>::min() &&
|
||||
v <= std::numeric_limits<RouteOriginUnderlyingType>::max()) {
|
||||
routeOrigin = static_cast<RouteOrigin>(v);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <boost/multi_index/hashed_index.hpp>
|
||||
#include <boost/multi_index/ordered_index.hpp>
|
||||
#include <boost/multi_index/sequenced_index.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
#endif // NDN_CXX_IMPL_COMMON_PCH_HPP
|
||||
@@ -27,14 +27,6 @@ namespace ndn {
|
||||
constexpr size_t MIN_CAPACITY = 16;
|
||||
constexpr time::milliseconds ZERO_WINDOW = 0_ms;
|
||||
|
||||
InMemoryStorage::const_iterator::const_iterator(const Data* ptr, const Cache* cache,
|
||||
Cache::index<byFullName>::type::iterator it)
|
||||
: m_ptr(ptr)
|
||||
, m_cache(cache)
|
||||
, m_it(it)
|
||||
{
|
||||
}
|
||||
|
||||
InMemoryStorage::const_iterator&
|
||||
InMemoryStorage::const_iterator::operator++()
|
||||
{
|
||||
@@ -45,42 +37,9 @@ InMemoryStorage::const_iterator::operator++()
|
||||
else {
|
||||
m_ptr = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
InMemoryStorage::const_iterator
|
||||
InMemoryStorage::const_iterator::operator++(int)
|
||||
{
|
||||
InMemoryStorage::const_iterator i(*this);
|
||||
this->operator++();
|
||||
return i;
|
||||
}
|
||||
|
||||
InMemoryStorage::const_iterator::reference
|
||||
InMemoryStorage::const_iterator::operator*()
|
||||
{
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
InMemoryStorage::const_iterator::pointer
|
||||
InMemoryStorage::const_iterator::operator->()
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
bool
|
||||
InMemoryStorage::const_iterator::operator==(const const_iterator& rhs)
|
||||
{
|
||||
return m_it == rhs.m_it;
|
||||
}
|
||||
|
||||
bool
|
||||
InMemoryStorage::const_iterator::operator!=(const const_iterator& rhs)
|
||||
{
|
||||
return m_it != rhs.m_it;
|
||||
}
|
||||
|
||||
InMemoryStorage::InMemoryStorage(size_t limit)
|
||||
: m_limit(limit)
|
||||
, m_nPackets(0)
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "ndn-cxx/ims/in-memory-storage-entry.hpp"
|
||||
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <stack>
|
||||
|
||||
@@ -58,39 +57,35 @@ public:
|
||||
>
|
||||
>;
|
||||
|
||||
/** @brief Represents a self-defined const_iterator for the in-memory storage.
|
||||
*
|
||||
* @note Don't try to instantiate this class directly, use InMemoryStorage::begin() instead.
|
||||
/**
|
||||
* @brief Represents a const_iterator for the in-memory storage.
|
||||
* @note Do not instantiate this class directly, use InMemoryStorage::begin() instead.
|
||||
*/
|
||||
class const_iterator
|
||||
class const_iterator : public boost::forward_iterator_helper<const_iterator, const Data>
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
using value_type = const Data;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
|
||||
const_iterator(const Data* ptr, const Cache* cache,
|
||||
Cache::index<byFullName>::type::iterator it);
|
||||
Cache::index<byFullName>::type::iterator it) noexcept
|
||||
: m_ptr(ptr)
|
||||
, m_cache(cache)
|
||||
, m_it(it)
|
||||
{
|
||||
}
|
||||
|
||||
reference
|
||||
operator*() const noexcept
|
||||
{
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
const_iterator&
|
||||
operator++();
|
||||
|
||||
const_iterator
|
||||
operator++(int);
|
||||
|
||||
reference
|
||||
operator*();
|
||||
|
||||
pointer
|
||||
operator->();
|
||||
|
||||
bool
|
||||
operator==(const const_iterator& rhs);
|
||||
|
||||
bool
|
||||
operator!=(const const_iterator& rhs);
|
||||
friend bool
|
||||
operator==(const const_iterator& lhs, const const_iterator& rhs) noexcept
|
||||
{
|
||||
return lhs.m_it == rhs.m_it;
|
||||
}
|
||||
|
||||
private:
|
||||
const Data* m_ptr;
|
||||
|
||||
+3
-10
@@ -55,10 +55,8 @@ public:
|
||||
using tlv::Error::Error;
|
||||
};
|
||||
|
||||
class Nonce final : public std::array<uint8_t, 4>
|
||||
class Nonce final : public std::array<uint8_t, 4>, private boost::equality_comparable<Nonce>
|
||||
{
|
||||
using Base = std::array<uint8_t, 4>;
|
||||
|
||||
public:
|
||||
Nonce() = default;
|
||||
|
||||
@@ -80,17 +78,12 @@ public:
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
// boost::equality_comparable provides != operator.
|
||||
|
||||
friend bool
|
||||
operator==(const Nonce& lhs, const Nonce& rhs) noexcept
|
||||
{
|
||||
return static_cast<const Base&>(lhs) == static_cast<const Base&>(rhs);
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const Nonce& lhs, const Nonce& rhs) noexcept
|
||||
{
|
||||
return static_cast<const Base&>(lhs) != static_cast<const Base&>(rhs);
|
||||
return std::equal(lhs.begin(), lhs.end(), rhs.begin());
|
||||
}
|
||||
|
||||
friend std::ostream&
|
||||
|
||||
@@ -50,12 +50,12 @@ KeyLocator::wireEncode(EncodingImpl<TAG>& encoder) const
|
||||
|
||||
size_t totalLength = 0;
|
||||
|
||||
auto visitor = boost::hana::overload(
|
||||
std::visit(boost::hana::overload(
|
||||
[] (std::monostate) {}, // nothing to encode, TLV-VALUE is empty
|
||||
[&] (const Name& name) { totalLength += name.wireEncode(encoder); },
|
||||
[&] (const Block& digest) { totalLength += prependBlock(encoder, digest); },
|
||||
[] (uint32_t type) { NDN_THROW(Error("Unsupported KeyLocator type " + to_string(type))); });
|
||||
visit(visitor, m_locator);
|
||||
[] (uint32_t type) { NDN_THROW(Error("Unsupported KeyLocator type " + to_string(type))); }),
|
||||
m_locator);
|
||||
|
||||
totalLength += encoder.prependVarNumber(totalLength);
|
||||
totalLength += encoder.prependVarNumber(tlv::KeyLocator);
|
||||
@@ -183,10 +183,10 @@ KeyLocator::setKeyDigest(const ConstBufferPtr& keyDigest)
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const KeyLocator& keyLocator)
|
||||
void
|
||||
KeyLocator::print(std::ostream& os) const
|
||||
{
|
||||
auto visitor = boost::hana::overload(
|
||||
std::visit(boost::hana::overload(
|
||||
[&] (std::monostate) {
|
||||
os << "None";
|
||||
},
|
||||
@@ -202,9 +202,8 @@ operator<<(std::ostream& os, const KeyLocator& keyLocator)
|
||||
},
|
||||
[&] (uint32_t type) {
|
||||
os << "Unknown(" << type << ")";
|
||||
});
|
||||
visit(visitor, keyLocator.m_locator);
|
||||
return os;
|
||||
}),
|
||||
m_locator);
|
||||
}
|
||||
|
||||
} // namespace ndn
|
||||
+10
-9
@@ -28,7 +28,7 @@
|
||||
|
||||
namespace ndn {
|
||||
|
||||
class KeyLocator
|
||||
class KeyLocator : private boost::equality_comparable<KeyLocator>
|
||||
{
|
||||
public:
|
||||
class Error : public tlv::Error
|
||||
@@ -124,9 +124,14 @@ public: // attributes
|
||||
KeyLocator&
|
||||
setKeyDigest(const ConstBufferPtr& keyDigest);
|
||||
|
||||
private:
|
||||
void
|
||||
print(std::ostream& os) const;
|
||||
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
// boost::equality_comparable provides != operator.
|
||||
|
||||
friend bool
|
||||
operator==(const KeyLocator& lhs, const KeyLocator& rhs)
|
||||
@@ -134,10 +139,11 @@ private: // non-member operators
|
||||
return lhs.m_locator == rhs.m_locator;
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const KeyLocator& lhs, const KeyLocator& rhs)
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& os, const KeyLocator& kl)
|
||||
{
|
||||
return lhs.m_locator != rhs.m_locator;
|
||||
kl.print(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -148,15 +154,10 @@ private:
|
||||
std::variant<std::monostate, Name, Block, uint32_t> m_locator;
|
||||
|
||||
mutable Block m_wire;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&, const KeyLocator&);
|
||||
};
|
||||
|
||||
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(KeyLocator);
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const KeyLocator& keyLocator);
|
||||
|
||||
} // namespace ndn
|
||||
|
||||
#endif // NDN_CXX_KEY_LOCATOR_HPP
|
||||
@@ -51,10 +51,10 @@ struct Fragment {};
|
||||
template<typename X>
|
||||
struct Field
|
||||
{
|
||||
static_assert(std::is_same_v<typename X::TlvType::value_type, uint32_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>, "");
|
||||
static_assert(std::is_same_v<typename X::TlvType::value_type, uint32_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)
|
||||
{
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
|
||||
namespace ndn {
|
||||
|
||||
static_assert(std::is_convertible_v<MetadataObject::Error*, tlv::Error*>,
|
||||
"MetadataObject::Error must inherit from tlv::Error");
|
||||
|
||||
MetadataObject::MetadataObject() = default;
|
||||
|
||||
MetadataObject::MetadataObject(const Data& data)
|
||||
|
||||
@@ -109,7 +109,7 @@ setConventionDecoding(Convention convention);
|
||||
* or, if it is an `ImplicitSha256DigestComponent` or a `ParametersSha256DigestComponent`,
|
||||
* its TLV-LENGTH is not 32.
|
||||
*/
|
||||
class Component : public Block
|
||||
class Component : public Block, private boost::less_than_comparable<Component>
|
||||
{
|
||||
public:
|
||||
class Error : public Block::Error
|
||||
@@ -482,23 +482,12 @@ public: // comparison
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check whether this is the same component as @p other.
|
||||
* @param other The name component to compare with
|
||||
* @return true if the components are equal, false otherwise.
|
||||
*/
|
||||
bool
|
||||
equals(const Component& other) const noexcept
|
||||
{
|
||||
return Block::equals(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compare this to the other Component using NDN canonical ordering.
|
||||
* @brief Compare this component to @p other using NDN canonical ordering.
|
||||
*
|
||||
* @param other The other Component to compare with.
|
||||
* @retval negative this comes before other in canonical ordering
|
||||
* @retval zero this equals other
|
||||
* @retval positive this comes after other in canonical ordering
|
||||
* @param other The name component to compare with.
|
||||
* @retval negative This component comes before @p other in canonical ordering
|
||||
* @retval zero This component equals @p other
|
||||
* @retval positive This component comes after @p other in canonical ordering
|
||||
*
|
||||
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/name.html#canonical-order
|
||||
*/
|
||||
@@ -543,18 +532,8 @@ private:
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
|
||||
friend bool
|
||||
operator==(const Component& lhs, const Component& rhs) noexcept
|
||||
{
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const Component& lhs, const Component& rhs) noexcept
|
||||
{
|
||||
return !lhs.equals(rhs);
|
||||
}
|
||||
// Block provides == and != operators.
|
||||
// boost::less_than_comparable provides <=, >=, and > operators.
|
||||
|
||||
friend bool
|
||||
operator<(const Component& lhs, const Component& rhs)
|
||||
@@ -562,24 +541,6 @@ private: // non-member operators
|
||||
return lhs.compare(rhs) < 0;
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator<=(const Component& lhs, const Component& rhs)
|
||||
{
|
||||
return lhs.compare(rhs) <= 0;
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator>(const Component& lhs, const Component& rhs)
|
||||
{
|
||||
return lhs.compare(rhs) > 0;
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator>=(const Component& lhs, const Component& rhs)
|
||||
{
|
||||
return lhs.compare(rhs) >= 0;
|
||||
}
|
||||
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& os, const Component& component)
|
||||
{
|
||||
@@ -589,7 +550,7 @@ private: // non-member operators
|
||||
|
||||
// !!! NOTE TO IMPLEMENTOR !!!
|
||||
//
|
||||
// This class MUST NOT contain any data fields.
|
||||
// This class MUST NOT contain any non-static data members.
|
||||
// Block can be reinterpret_cast'ed as Component type.
|
||||
};
|
||||
|
||||
|
||||
+2
-25
@@ -41,7 +41,7 @@ using PartialName = Name;
|
||||
* @brief Represents an absolute name.
|
||||
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/name.html
|
||||
*/
|
||||
class Name
|
||||
class Name : private boost::totally_ordered<Name>
|
||||
{
|
||||
public: // nested types
|
||||
using Error = name::Component::Error;
|
||||
@@ -646,6 +646,7 @@ public: // algorithms
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
// boost::totally_ordered provides !=, <=, >=, and > operators.
|
||||
|
||||
friend bool
|
||||
operator==(const Name& lhs, const Name& rhs) noexcept
|
||||
@@ -653,36 +654,12 @@ private: // non-member operators
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const Name& lhs, const Name& rhs) noexcept
|
||||
{
|
||||
return !lhs.equals(rhs);
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator<(const Name& lhs, const Name& rhs)
|
||||
{
|
||||
return lhs.compare(rhs) < 0;
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator<=(const Name& lhs, const Name& rhs)
|
||||
{
|
||||
return lhs.compare(rhs) <= 0;
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator>(const Name& lhs, const Name& rhs)
|
||||
{
|
||||
return lhs.compare(rhs) > 0;
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator>=(const Name& lhs, const Name& rhs)
|
||||
{
|
||||
return lhs.compare(rhs) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Print the URI representation of a name.
|
||||
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/name.html#ndn-uri-scheme
|
||||
|
||||
+10
-11
@@ -181,25 +181,24 @@ std::string
|
||||
FaceUri::toString() const
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << *this;
|
||||
print(os);
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const FaceUri& uri)
|
||||
void
|
||||
FaceUri::print(std::ostream& os) const
|
||||
{
|
||||
os << uri.m_scheme << "://";
|
||||
if (uri.m_isV6) {
|
||||
os << "[" << uri.m_host << "]";
|
||||
os << m_scheme << "://";
|
||||
if (m_isV6) {
|
||||
os << "[" << m_host << "]";
|
||||
}
|
||||
else {
|
||||
os << uri.m_host;
|
||||
os << m_host;
|
||||
}
|
||||
if (!uri.m_port.empty()) {
|
||||
os << ":" << uri.m_port;
|
||||
if (!m_port.empty()) {
|
||||
os << ":" << m_port;
|
||||
}
|
||||
os << uri.m_path;
|
||||
return os;
|
||||
os << m_path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -178,13 +178,17 @@ public: // canonical FaceUri
|
||||
boost::asio::io_service& io,
|
||||
time::nanoseconds timeout) const;
|
||||
|
||||
private:
|
||||
void
|
||||
print(std::ostream& os) const;
|
||||
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
// boost::totally_ordered provides !=, <=, >=, and > operators.
|
||||
|
||||
friend bool
|
||||
operator==(const FaceUri& lhs, const FaceUri& rhs)
|
||||
operator==(const FaceUri& lhs, const FaceUri& rhs) noexcept
|
||||
{
|
||||
return lhs.m_isV6 == rhs.m_isV6 &&
|
||||
lhs.m_scheme == rhs.m_scheme &&
|
||||
@@ -194,25 +198,27 @@ private: // non-member operators
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator<(const FaceUri& lhs, const FaceUri& rhs)
|
||||
operator<(const FaceUri& lhs, const FaceUri& rhs) noexcept
|
||||
{
|
||||
return std::tie(lhs.m_scheme, lhs.m_isV6, lhs.m_host, lhs.m_port, lhs.m_path) <
|
||||
std::tie(rhs.m_scheme, rhs.m_isV6, rhs.m_host, rhs.m_port, rhs.m_path);
|
||||
}
|
||||
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& os, const FaceUri& uri)
|
||||
{
|
||||
uri.print(os);
|
||||
return os;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_scheme;
|
||||
std::string m_host;
|
||||
std::string m_port;
|
||||
std::string m_path;
|
||||
bool m_isV6 = false; ///< whether to add [] around host when converting to string representation
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const FaceUri& uri);
|
||||
};
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const FaceUri& uri);
|
||||
|
||||
} // namespace ndn
|
||||
|
||||
#endif // NDN_CXX_NET_FACE_URI_HPP
|
||||
@@ -366,7 +366,7 @@ RtnlSocket::sendDumpRequest(uint16_t nlmsgType, const void* payload, size_t payl
|
||||
{
|
||||
alignas(NLMSG_ALIGNTO) nlmsghdr nlh;
|
||||
};
|
||||
static_assert(sizeof(RtnlMessageHeader) == NLMSG_HDRLEN, "");
|
||||
static_assert(sizeof(RtnlMessageHeader) == NLMSG_HDRLEN);
|
||||
|
||||
auto hdr = make_shared<RtnlMessageHeader>();
|
||||
hdr->nlh.nlmsg_len = sizeof(RtnlMessageHeader) + payloadLen;
|
||||
@@ -472,7 +472,7 @@ GenlSocket::sendRequest(uint16_t familyId, uint8_t command,
|
||||
alignas(NLMSG_ALIGNTO) nlmsghdr nlh;
|
||||
alignas(NLMSG_ALIGNTO) genlmsghdr genlh;
|
||||
};
|
||||
static_assert(sizeof(GenlMessageHeader) == NLMSG_SPACE(GENL_HDRLEN), "");
|
||||
static_assert(sizeof(GenlMessageHeader) == NLMSG_SPACE(GENL_HDRLEN));
|
||||
|
||||
auto hdr = make_shared<GenlMessageHeader>();
|
||||
hdr->nlh.nlmsg_len = sizeof(GenlMessageHeader) + payloadLen;
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
|
||||
namespace ndn {
|
||||
|
||||
static_assert(std::is_convertible_v<PrefixAnnouncement::Error*, tlv::Error*>,
|
||||
"PrefixAnnouncement::Error must inherit from tlv::Error");
|
||||
|
||||
PrefixAnnouncement::PrefixAnnouncement() = default;
|
||||
|
||||
PrefixAnnouncement::PrefixAnnouncement(Data data)
|
||||
@@ -126,14 +123,6 @@ PrefixAnnouncement::getKeywordComponent()
|
||||
return nc;
|
||||
}
|
||||
|
||||
bool
|
||||
operator==(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs)
|
||||
{
|
||||
return lhs.getAnnouncedName() == rhs.getAnnouncedName() &&
|
||||
lhs.getExpiration() == rhs.getExpiration() &&
|
||||
lhs.getValidityPeriod() == rhs.getValidityPeriod();
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const PrefixAnnouncement& pa)
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace ndn {
|
||||
*
|
||||
* \sa https://redmine.named-data.net/projects/nfd/wiki/PrefixAnnouncement
|
||||
*/
|
||||
class PrefixAnnouncement
|
||||
class PrefixAnnouncement : private boost::equality_comparable<PrefixAnnouncement>
|
||||
{
|
||||
public:
|
||||
class Error : public tlv::Error
|
||||
@@ -126,26 +126,31 @@ public: // static methods
|
||||
static const name::Component&
|
||||
getKeywordComponent();
|
||||
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
// boost::equality_comparable provides != operator.
|
||||
|
||||
/**
|
||||
* \brief Test whether two prefix announcements have the same name, expiration period,
|
||||
* and validity period.
|
||||
*/
|
||||
friend bool
|
||||
operator==(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs)
|
||||
{
|
||||
return lhs.m_announcedName == rhs.m_announcedName &&
|
||||
lhs.m_expiration == rhs.m_expiration &&
|
||||
lhs.m_validity == rhs.m_validity;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::optional<Data> m_data;
|
||||
Name m_announcedName;
|
||||
time::milliseconds m_expiration = 0_ms;
|
||||
std::optional<security::ValidityPeriod> m_validity;
|
||||
|
||||
mutable std::optional<Data> m_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Test whether two prefix announcements have the same name, expiration period,
|
||||
* and validity period.
|
||||
*/
|
||||
bool
|
||||
operator==(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs);
|
||||
|
||||
inline bool
|
||||
operator!=(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Print prefix announcement to a stream.
|
||||
*
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace ndn::security {
|
||||
* @brief Represents an %AdditionalDescription TLV element.
|
||||
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/certificate.html
|
||||
*/
|
||||
class AdditionalDescription
|
||||
class AdditionalDescription : private boost::equality_comparable<AdditionalDescription>
|
||||
{
|
||||
public:
|
||||
class Error : public tlv::Error
|
||||
@@ -107,9 +107,10 @@ public:
|
||||
void
|
||||
wireDecode(const Block& wire);
|
||||
|
||||
private: // EqualityComparable concept
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
// boost::equality_comparable provides != operator.
|
||||
|
||||
friend bool
|
||||
operator==(const AdditionalDescription& lhs, const AdditionalDescription& rhs)
|
||||
@@ -117,12 +118,6 @@ private: // EqualityComparable concept
|
||||
return lhs.m_info == rhs.m_info;
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const AdditionalDescription& lhs, const AdditionalDescription& rhs)
|
||||
{
|
||||
return lhs.m_info != rhs.m_info;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> m_info;
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ class KeyChain::Locator
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] bool
|
||||
empty() const
|
||||
empty() const noexcept
|
||||
{
|
||||
return scheme.empty();
|
||||
}
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator==(const Locator& lhs, const Locator& rhs)
|
||||
operator==(const Locator& lhs, const Locator& rhs) noexcept
|
||||
{
|
||||
return lhs.scheme == rhs.scheme && lhs.location == rhs.location;
|
||||
}
|
||||
|
||||
@@ -27,22 +27,8 @@ namespace ndn::security::pib {
|
||||
|
||||
NDN_LOG_INIT(ndn.security.CertificateContainer);
|
||||
|
||||
CertificateContainer::const_iterator::const_iterator(NameSet::const_iterator it,
|
||||
const CertificateContainer& container) noexcept
|
||||
: m_it(it)
|
||||
, m_container(&container)
|
||||
{
|
||||
}
|
||||
|
||||
Certificate
|
||||
CertificateContainer::const_iterator::operator*()
|
||||
{
|
||||
BOOST_ASSERT(m_container != nullptr);
|
||||
return m_container->get(*m_it);
|
||||
}
|
||||
|
||||
bool
|
||||
CertificateContainer::const_iterator::operator==(const const_iterator& other) const
|
||||
CertificateContainer::const_iterator::equals(const const_iterator& other) const noexcept
|
||||
{
|
||||
bool isThisEnd = m_container == nullptr || m_it == m_container->m_certNames.end();
|
||||
bool isOtherEnd = other.m_container == nullptr || other.m_it == other.m_container->m_certNames.end();
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "ndn-cxx/security/certificate.hpp"
|
||||
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -46,19 +45,17 @@ private:
|
||||
using NameSet = std::set<Name>;
|
||||
|
||||
public:
|
||||
class const_iterator
|
||||
class const_iterator : public boost::forward_iterator_helper<const_iterator, const Certificate>
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = const Certificate;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
|
||||
const_iterator() = default;
|
||||
|
||||
Certificate
|
||||
operator*();
|
||||
operator*() const
|
||||
{
|
||||
BOOST_ASSERT(m_container != nullptr);
|
||||
return m_container->get(*m_it);
|
||||
}
|
||||
|
||||
const_iterator&
|
||||
operator++()
|
||||
@@ -67,25 +64,21 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_iterator
|
||||
operator++(int)
|
||||
friend bool
|
||||
operator==(const const_iterator& lhs, const const_iterator& rhs) noexcept
|
||||
{
|
||||
const_iterator it(*this);
|
||||
++m_it;
|
||||
return it;
|
||||
}
|
||||
|
||||
bool
|
||||
operator==(const const_iterator& other) const;
|
||||
|
||||
bool
|
||||
operator!=(const const_iterator& other) const
|
||||
{
|
||||
return !this->operator==(other);
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
const_iterator(NameSet::const_iterator it, const CertificateContainer& container) noexcept;
|
||||
const_iterator(NameSet::const_iterator it, const CertificateContainer& container) noexcept
|
||||
: m_it(it)
|
||||
, m_container(&container)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
equals(const const_iterator& other) const noexcept;
|
||||
|
||||
private:
|
||||
NameSet::const_iterator m_it;
|
||||
|
||||
@@ -28,22 +28,8 @@ namespace ndn::security::pib {
|
||||
|
||||
NDN_LOG_INIT(ndn.security.IdentityContainer);
|
||||
|
||||
IdentityContainer::const_iterator::const_iterator(NameSet::const_iterator it,
|
||||
const IdentityContainer& container) noexcept
|
||||
: m_it(it)
|
||||
, m_container(&container)
|
||||
{
|
||||
}
|
||||
|
||||
Identity
|
||||
IdentityContainer::const_iterator::operator*()
|
||||
{
|
||||
BOOST_ASSERT(m_container != nullptr);
|
||||
return m_container->get(*m_it);
|
||||
}
|
||||
|
||||
bool
|
||||
IdentityContainer::const_iterator::operator==(const const_iterator& other) const
|
||||
IdentityContainer::const_iterator::equals(const const_iterator& other) const noexcept
|
||||
{
|
||||
bool isThisEnd = m_container == nullptr || m_it == m_container->m_identityNames.end();
|
||||
bool isOtherEnd = other.m_container == nullptr || other.m_it == other.m_container->m_identityNames.end();
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "ndn-cxx/security/pib/identity.hpp"
|
||||
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -46,19 +45,17 @@ private:
|
||||
using NameSet = std::set<Name>;
|
||||
|
||||
public:
|
||||
class const_iterator
|
||||
class const_iterator : public boost::forward_iterator_helper<const_iterator, const Identity>
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = const Identity;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
|
||||
const_iterator() = default;
|
||||
|
||||
Identity
|
||||
operator*();
|
||||
operator*() const
|
||||
{
|
||||
BOOST_ASSERT(m_container != nullptr);
|
||||
return m_container->get(*m_it);
|
||||
}
|
||||
|
||||
const_iterator&
|
||||
operator++()
|
||||
@@ -67,25 +64,21 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_iterator
|
||||
operator++(int)
|
||||
friend bool
|
||||
operator==(const const_iterator& lhs, const const_iterator& rhs) noexcept
|
||||
{
|
||||
const_iterator it(*this);
|
||||
++m_it;
|
||||
return it;
|
||||
}
|
||||
|
||||
bool
|
||||
operator==(const const_iterator& other) const;
|
||||
|
||||
bool
|
||||
operator!=(const const_iterator& other) const
|
||||
{
|
||||
return !this->operator==(other);
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
const_iterator(NameSet::const_iterator it, const IdentityContainer& container) noexcept;
|
||||
const_iterator(NameSet::const_iterator it, const IdentityContainer& container) noexcept
|
||||
: m_it(it)
|
||||
, m_container(&container)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
equals(const const_iterator& other) const noexcept;
|
||||
|
||||
private:
|
||||
NameSet::const_iterator m_it;
|
||||
|
||||
@@ -40,7 +40,7 @@ class IdentityImpl;
|
||||
* name, and contains zero or more keys, at most one of which is set as the default key of that
|
||||
* identity. The properties of a key can be accessed after obtaining a Key object.
|
||||
*/
|
||||
class Identity
|
||||
class Identity : private boost::equality_comparable<Identity>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -154,19 +154,14 @@ private:
|
||||
// NOTE
|
||||
// The following "hidden friend" non-member operators are available
|
||||
// via argument-dependent lookup only and must be defined inline.
|
||||
// boost::equality_comparable provides != operator.
|
||||
|
||||
friend bool
|
||||
operator==(const Identity& lhs, const Identity& rhs)
|
||||
operator==(const Identity& lhs, const Identity& rhs) noexcept
|
||||
{
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const Identity& lhs, const Identity& rhs)
|
||||
{
|
||||
return !lhs.equals(rhs);
|
||||
}
|
||||
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& os, const Identity& id)
|
||||
{
|
||||
|
||||
@@ -28,22 +28,8 @@ namespace ndn::security::pib {
|
||||
|
||||
NDN_LOG_INIT(ndn.security.KeyContainer);
|
||||
|
||||
KeyContainer::const_iterator::const_iterator(NameSet::const_iterator it,
|
||||
const KeyContainer& container) noexcept
|
||||
: m_it(it)
|
||||
, m_container(&container)
|
||||
{
|
||||
}
|
||||
|
||||
Key
|
||||
KeyContainer::const_iterator::operator*()
|
||||
{
|
||||
BOOST_ASSERT(m_container != nullptr);
|
||||
return m_container->get(*m_it);
|
||||
}
|
||||
|
||||
bool
|
||||
KeyContainer::const_iterator::operator==(const const_iterator& other) const
|
||||
KeyContainer::const_iterator::equals(const const_iterator& other) const noexcept
|
||||
{
|
||||
bool isThisEnd = m_container == nullptr || m_it == m_container->m_keyNames.end();
|
||||
bool isOtherEnd = other.m_container == nullptr || other.m_it == other.m_container->m_keyNames.end();
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "ndn-cxx/security/pib/key.hpp"
|
||||
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -46,19 +45,17 @@ private:
|
||||
using NameSet = std::set<Name>;
|
||||
|
||||
public:
|
||||
class const_iterator
|
||||
class const_iterator : public boost::forward_iterator_helper<const_iterator, const Key>
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = const Key;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
|
||||
const_iterator() = default;
|
||||
|
||||
Key
|
||||
operator*();
|
||||
operator*() const
|
||||
{
|
||||
BOOST_ASSERT(m_container != nullptr);
|
||||
return m_container->get(*m_it);
|
||||
}
|
||||
|
||||
const_iterator&
|
||||
operator++()
|
||||
@@ -67,25 +64,21 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_iterator
|
||||
operator++(int)
|
||||
friend bool
|
||||
operator==(const const_iterator& lhs, const const_iterator& rhs) noexcept
|
||||
{
|
||||
const_iterator it(*this);
|
||||
++m_it;
|
||||
return it;
|
||||
}
|
||||
|
||||
bool
|
||||
operator==(const const_iterator& other) const;
|
||||
|
||||
bool
|
||||
operator!=(const const_iterator& other) const
|
||||
{
|
||||
return !this->operator==(other);
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
const_iterator(NameSet::const_iterator it, const KeyContainer& container) noexcept;
|
||||
const_iterator(NameSet::const_iterator it, const KeyContainer& container) noexcept
|
||||
: m_it(it)
|
||||
, m_container(&container)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
equals(const const_iterator& other) const noexcept;
|
||||
|
||||
private:
|
||||
NameSet::const_iterator m_it;
|
||||
|
||||
@@ -41,7 +41,7 @@ class KeyImpl;
|
||||
* `/<Identity>/KEY/<KeyId>`, and contains one or more certificates, one of which is set as
|
||||
* default certificate of that key. Certificates can be directly accessed from a Key object.
|
||||
*/
|
||||
class Key
|
||||
class Key : private boost::equality_comparable<Key>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -173,19 +173,14 @@ private:
|
||||
// NOTE
|
||||
// The following "hidden friend" non-member operators are available
|
||||
// via argument-dependent lookup only and must be defined inline.
|
||||
// boost::equality_comparable provides != operator.
|
||||
|
||||
friend bool
|
||||
operator==(const Key& lhs, const Key& rhs)
|
||||
operator==(const Key& lhs, const Key& rhs) noexcept
|
||||
{
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const Key& lhs, const Key& rhs)
|
||||
{
|
||||
return !lhs.equals(rhs);
|
||||
}
|
||||
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& os, const Key& key)
|
||||
{
|
||||
|
||||
@@ -43,7 +43,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_v<decltype(C2H)> == 256, "");
|
||||
static_assert(std::extent_v<decltype(C2H)> == 256);
|
||||
|
||||
|
||||
HexDecode::HexDecode()
|
||||
|
||||
@@ -27,13 +27,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_v<decltype(H2CL)> == 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_v<decltype(H2CU)> == 16, "");
|
||||
static_assert(std::extent_v<decltype(H2CU)> == 16);
|
||||
|
||||
|
||||
HexEncode::HexEncode(bool useUpperCase)
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace ndn::security {
|
||||
* @brief Represents a %ValidityPeriod TLV element.
|
||||
* @sa https://docs.named-data.net/NDN-packet-spec/0.3/certificate.html
|
||||
*/
|
||||
class ValidityPeriod
|
||||
class ValidityPeriod : private boost::equality_comparable<ValidityPeriod>
|
||||
{
|
||||
public:
|
||||
class Error : public tlv::Error
|
||||
@@ -135,21 +135,16 @@ private:
|
||||
static TimePoint
|
||||
decodeTimePoint(const Block& element);
|
||||
|
||||
private: // EqualityComparable concept
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
// boost::equality_comparable provides != operator.
|
||||
|
||||
friend bool
|
||||
operator==(const ValidityPeriod& lhs, const ValidityPeriod& rhs)
|
||||
{
|
||||
return !(lhs != rhs);
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const ValidityPeriod& lhs, const ValidityPeriod& rhs)
|
||||
{
|
||||
return lhs.m_notBefore != rhs.m_notBefore ||
|
||||
lhs.m_notAfter != rhs.m_notAfter;
|
||||
return lhs.m_notBefore == rhs.m_notBefore &&
|
||||
lhs.m_notAfter == rhs.m_notAfter;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -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_v<T>, "");
|
||||
static_assert(std::is_enum_v<T>);
|
||||
return static_cast<std::underlying_type_t<T>>(val);
|
||||
}
|
||||
#endif // __cpp_lib_to_underlying
|
||||
|
||||
@@ -99,10 +99,10 @@ class NfdMgmtProtocolStruct : public WireEncodable<X>
|
||||
public:
|
||||
BOOST_CONCEPT_USAGE(NfdMgmtProtocolStruct)
|
||||
{
|
||||
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_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_convertible_v<typename X::Error*, tlv::Error*>,
|
||||
"ndn::tlv::Error must be a public base of X::Error");
|
||||
}
|
||||
|
||||
@@ -67,12 +67,6 @@ EventId::reset() noexcept
|
||||
*this = {};
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const EventId& eventId)
|
||||
{
|
||||
return os << eventId.m_info.lock();
|
||||
}
|
||||
|
||||
bool
|
||||
Scheduler::EventQueueCompare::operator()(const shared_ptr<EventInfo>& a,
|
||||
const shared_ptr<EventInfo>& b) const noexcept
|
||||
|
||||
+22
-19
@@ -26,7 +26,9 @@
|
||||
#include "ndn-cxx/detail/cancel-handle.hpp"
|
||||
#include "ndn-cxx/util/time.hpp"
|
||||
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace ndn {
|
||||
@@ -55,32 +57,40 @@ using EventCallback = std::function<void()>;
|
||||
* \warning Canceling an event after the scheduler has been destructed may trigger undefined
|
||||
* behavior.
|
||||
*/
|
||||
class EventId : public detail::CancelHandle
|
||||
class EventId : public detail::CancelHandle, private boost::equality_comparable<EventId>
|
||||
{
|
||||
public:
|
||||
/** \brief Constructs an empty EventId
|
||||
/**
|
||||
* \brief Constructs an empty EventId.
|
||||
*/
|
||||
EventId() noexcept = default;
|
||||
|
||||
/** \brief Determine whether the event is valid.
|
||||
* \retval true The event is valid.
|
||||
* \retval false This EventId is empty, or the event is expired or cancelled.
|
||||
/**
|
||||
* \brief Determine whether the associated event is valid.
|
||||
* \retval true The event is valid.
|
||||
* \retval false This EventId is empty, or the event is expired or cancelled.
|
||||
*/
|
||||
explicit
|
||||
operator bool() const noexcept;
|
||||
|
||||
/** \brief Clear this EventId without canceling.
|
||||
* \post !(*this)
|
||||
/**
|
||||
* \brief Clear this EventId without canceling the associated event.
|
||||
* \post !(*this)
|
||||
*/
|
||||
void
|
||||
reset() noexcept;
|
||||
|
||||
private:
|
||||
EventId(Scheduler& sched, weak_ptr<EventInfo> info);
|
||||
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
// boost::equality_comparable provides != operator.
|
||||
|
||||
/** \brief Determine whether this and other refer to the same event, or are both
|
||||
* empty/expired/cancelled.
|
||||
/**
|
||||
* \brief Determine whether \p lhs and \p rhs refer to the same event, or are both
|
||||
* empty/expired/cancelled.
|
||||
*/
|
||||
friend bool
|
||||
operator==(const EventId& lhs, const EventId& rhs) noexcept
|
||||
@@ -90,25 +100,18 @@ private:
|
||||
!rhs.m_info.owner_before(lhs.m_info));
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const EventId& lhs, const EventId& rhs) noexcept
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& os, const EventId& eventId)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
return os << eventId.m_info.lock();
|
||||
}
|
||||
|
||||
private:
|
||||
EventId(Scheduler& sched, weak_ptr<EventInfo> info);
|
||||
|
||||
private:
|
||||
weak_ptr<EventInfo> m_info;
|
||||
|
||||
friend Scheduler;
|
||||
friend std::ostream& operator<<(std::ostream& os, const EventId& eventId);
|
||||
};
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const EventId& eventId);
|
||||
|
||||
/** \brief A scoped handle for a scheduled event.
|
||||
*
|
||||
* Upon destruction of this handle, the event is canceled automatically.
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
#include "ndn-cxx/detail/common.hpp"
|
||||
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
namespace ndn::signal {
|
||||
|
||||
using DisconnectFunction = std::function<void()>;
|
||||
@@ -32,22 +34,24 @@ using DisconnectFunction = std::function<void()>;
|
||||
* \brief Represents a connection to a signal.
|
||||
* \note This type is copyable. Any copy can be used to disconnect.
|
||||
*/
|
||||
class Connection
|
||||
class Connection : private boost::equality_comparable<Connection>
|
||||
{
|
||||
public:
|
||||
constexpr
|
||||
Connection() noexcept = default;
|
||||
|
||||
/** \brief Disconnects from the signal.
|
||||
* \note If the connection is already disconnected, or if the Signal has been destructed,
|
||||
* this operation has no effect.
|
||||
* \warning During signal emission, attempting to disconnect a connection other than
|
||||
* the executing handler's own connection results in undefined behavior.
|
||||
/**
|
||||
* \brief Disconnects from the signal.
|
||||
* \note If the connection is already disconnected, or if the Signal has been destructed,
|
||||
* this operation has no effect.
|
||||
* \warning During signal emission, attempting to disconnect a connection other than
|
||||
* the executing handler's own connection results in undefined behavior.
|
||||
*/
|
||||
void
|
||||
disconnect();
|
||||
|
||||
/** \brief Check if connected to the signal.
|
||||
/**
|
||||
* \brief Check if connected to the signal.
|
||||
*/
|
||||
bool
|
||||
isConnected() const noexcept
|
||||
@@ -56,22 +60,22 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
/** \param disconnect weak_ptr to a function that disconnects the handler
|
||||
*/
|
||||
explicit
|
||||
Connection(weak_ptr<DisconnectFunction> disconnect) noexcept;
|
||||
|
||||
template<typename Owner, typename... TArgs>
|
||||
friend class Signal;
|
||||
|
||||
private:
|
||||
private: // non-member operators
|
||||
// NOTE: the following "hidden friend" operators are available via
|
||||
// argument-dependent lookup only and must be defined inline.
|
||||
// boost::equality_comparable provides != operator.
|
||||
|
||||
/** \brief Compare for equality.
|
||||
/**
|
||||
* \brief Compare for equality.
|
||||
*
|
||||
* Two connections are equal if they both refer to the same connection that isn't disconnected,
|
||||
* or they are both disconnected.
|
||||
* Two connections are equal if they both refer to the same connection that isn't disconnected,
|
||||
* or they are both disconnected.
|
||||
*/
|
||||
friend bool
|
||||
operator==(const Connection& lhs, const Connection& rhs) noexcept
|
||||
@@ -81,12 +85,6 @@ private:
|
||||
!rhs.m_disconnect.owner_before(lhs.m_disconnect));
|
||||
}
|
||||
|
||||
friend bool
|
||||
operator!=(const Connection& lhs, const Connection& rhs) noexcept
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
/** \note The only shared_ptr to the disconnect function is stored in Signal<..>::Slot,
|
||||
* and will be destructed if the handler is disconnected (through another Connection
|
||||
|
||||
@@ -68,7 +68,7 @@ struct ReadVarNumberAlignTest : public ReadVarNumberTest<WIRE_SIZE>
|
||||
{
|
||||
using AlignmentOffset = std::integral_constant<size_t, ALIGNMENT_OFFSET>;
|
||||
|
||||
static_assert(sizeof(ReadVarNumberTest<WIRE_SIZE>::WIRE) == WIRE_SIZE, "");
|
||||
static_assert(sizeof(ReadVarNumberTest<WIRE_SIZE>::WIRE) == WIRE_SIZE);
|
||||
};
|
||||
|
||||
using ReadVarNumberTests = boost::mpl::vector<
|
||||
@@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ReadVarNumber, Test, ReadVarNumberTests)
|
||||
constexpr int N_ITERATIONS = 100000000;
|
||||
|
||||
alignas(8) uint8_t buffer[16];
|
||||
static_assert(Test::AlignmentOffset::value + sizeof(Test::WIRE) <= sizeof(buffer), "");
|
||||
static_assert(Test::AlignmentOffset::value + sizeof(Test::WIRE) <= sizeof(buffer));
|
||||
uint8_t* const begin = buffer + Test::AlignmentOffset::value;
|
||||
std::memcpy(begin, Test::WIRE, sizeof(Test::WIRE));
|
||||
const uint8_t* const end = begin + sizeof(Test::WIRE);
|
||||
|
||||
@@ -44,7 +44,7 @@ protected:
|
||||
: face(m_io, m_keyChain, {true, !std::is_same_v<PrefixRegReply, NoPrefixRegReply>})
|
||||
{
|
||||
static_assert(std::is_same_v<PrefixRegReply, WantPrefixRegReply> ||
|
||||
std::is_same_v<PrefixRegReply, NoPrefixRegReply>, "");
|
||||
std::is_same_v<PrefixRegReply, NoPrefixRegReply>);
|
||||
}
|
||||
|
||||
/** \brief Execute a prefix registration, and optionally check the name in callback.
|
||||
|
||||
@@ -31,6 +31,7 @@ BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Interest>));
|
||||
BOOST_CONCEPT_ASSERT((WireDecodable<Interest>));
|
||||
static_assert(std::is_convertible_v<Interest::Error*, tlv::Error*>,
|
||||
"Interest::Error must inherit from tlv::Error");
|
||||
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Interest::Nonce>));
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TestInterest)
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
|
||||
namespace ndn::tests {
|
||||
|
||||
static_assert(std::is_convertible_v<MetadataObject::Error*, tlv::Error*>,
|
||||
"MetadataObject::Error must inherit from tlv::Error");
|
||||
|
||||
class MetadataObjectFixture : public KeyChainFixture
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -35,7 +35,9 @@ namespace ndn::tests {
|
||||
using ndn::name::Component;
|
||||
using ndn::name::UriFormat;
|
||||
|
||||
static_assert(sizeof(Component) == sizeof(Block));
|
||||
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Component>));
|
||||
BOOST_CONCEPT_ASSERT((boost::Comparable<Component>));
|
||||
BOOST_CONCEPT_ASSERT((WireEncodable<Component>));
|
||||
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Component>));
|
||||
BOOST_CONCEPT_ASSERT((WireDecodable<Component>));
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace ndn::tests {
|
||||
using ndn::name::Component;
|
||||
|
||||
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Name>));
|
||||
BOOST_CONCEPT_ASSERT((boost::Comparable<Name>));
|
||||
BOOST_CONCEPT_ASSERT((WireEncodable<Name>));
|
||||
BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Name>));
|
||||
BOOST_CONCEPT_ASSERT((WireDecodable<Name>));
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
|
||||
namespace ndn::tests {
|
||||
|
||||
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<PrefixAnnouncement>));
|
||||
static_assert(std::is_convertible_v<PrefixAnnouncement::Error*, tlv::Error*>,
|
||||
"PrefixAnnouncement::Error must inherit from tlv::Error");
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TestPrefixAnnouncement)
|
||||
|
||||
static Data
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace ndn::tests {
|
||||
|
||||
using namespace ndn::security::pib;
|
||||
|
||||
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Identity>));
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(Security)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestIdentity, PibDataFixture)
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace ndn::tests {
|
||||
|
||||
using namespace ndn::security::pib;
|
||||
|
||||
BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Key>));
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(Security)
|
||||
BOOST_FIXTURE_TEST_SUITE(TestKey, PibDataFixture)
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(Basic)
|
||||
|
||||
auto joiner1 = ostream_joiner<char>(os, ' ');
|
||||
auto joiner2 = make_ostream_joiner(os, ' ');
|
||||
static_assert(std::is_same_v<decltype(joiner1), decltype(joiner2)>, "");
|
||||
static_assert(std::is_same_v<decltype(joiner1), decltype(joiner2)>);
|
||||
|
||||
std::vector<int> v(5);
|
||||
std::iota(v.begin(), v.end(), 1);
|
||||
|
||||
@@ -37,9 +37,9 @@ BOOST_AUTO_TEST_CASE(VersionNumber)
|
||||
NDN_CXX_VERSION_MINOR * 1000 +
|
||||
NDN_CXX_VERSION_PATCH);
|
||||
|
||||
static_assert(NDN_CXX_VERSION_MAJOR < 1000, "");
|
||||
static_assert(NDN_CXX_VERSION_MINOR < 1000, "");
|
||||
static_assert(NDN_CXX_VERSION_PATCH < 1000, "");
|
||||
static_assert(NDN_CXX_VERSION_MAJOR < 1000);
|
||||
static_assert(NDN_CXX_VERSION_MINOR < 1000);
|
||||
static_assert(NDN_CXX_VERSION_PATCH < 1000);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(VersionString)
|
||||
|
||||
Reference in new issue
Block a user