concepts.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2023 Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
12  *
13  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU Lesser General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any later version.
16  *
17  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20  *
21  * You should have received copies of the GNU General Public License and GNU Lesser
22  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
23  * <http://www.gnu.org/licenses/>.
24  *
25  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
26  */
27 
28 #ifndef NDN_CXX_UTIL_CONCEPTS_HPP
29 #define NDN_CXX_UTIL_CONCEPTS_HPP
30 
33 
34 #include <boost/concept_check.hpp>
35 #include <boost/concept/usage.hpp>
36 #include <boost/type_traits/has_equal_to.hpp>
37 #include <boost/type_traits/has_not_equal_to.hpp>
38 #include <boost/type_traits/has_left_shift.hpp>
39 
40 namespace ndn {
41 
44 template<class X>
46 {
47 public:
49  {
50  Block block = j.wireEncode();
51  block.size(); // avoid 'unused variable block'
52  }
53 
54 private:
55  X j;
56 };
57 
60 template<class X>
62 {
63 public:
65  {
66  EncodingEstimator estimator;
67  size_t estimatedSize = j.wireEncode(estimator);
68 
69  EncodingBuffer encoder(estimatedSize, 0);
70  j.wireEncode(encoder);
71  }
72 
73 private:
74  X j;
75 };
76 
80 template<class X>
82 {
83 public:
85  {
86  Block block;
87  X j(block);
88  j.wireDecode(block);
89  }
90 };
91 
92 namespace detail {
93 
94 template<class X>
97  , public WireDecodable<X>
98 {
99 public:
101  {
102  static_assert(std::is_default_constructible_v<X>);
103  static_assert(boost::has_equal_to<X, X, bool>::value);
104  static_assert(boost::has_not_equal_to<X, X, bool>::value);
105  static_assert(boost::has_left_shift<std::ostream, X, std::ostream&>::value);
106  static_assert(std::is_convertible_v<typename X::Error*, tlv::Error*>,
107  "ndn::tlv::Error must be a public base of X::Error");
108  }
109 };
110 
111 } // namespace detail
112 
116 template<class X>
118 {
119 };
120 
124 template<class X>
126 {
127 };
128 
129 // NDN_CXX_ASSERT_FORWARD_ITERATOR originally written as part of the NFD codebase
130 
131 namespace detail {
132 
133 // As of Boost 1.61.0, the internal implementation of BOOST_CONCEPT_ASSERT does not allow
134 // multiple assertions on the same line, so we have to combine multiple concepts together.
135 template<typename T>
136 class StlForwardIteratorConcept : public boost::ForwardIterator<T>
137  , public boost::DefaultConstructible<T>
138 {
139 };
140 
141 } // namespace detail
142 } // namespace ndn
143 
149 #define NDN_CXX_ASSERT_FORWARD_ITERATOR(T) \
150  static_assert(std::is_default_constructible_v<T>, #T " must be default-constructible"); \
151  BOOST_CONCEPT_ASSERT((::ndn::detail::StlForwardIteratorConcept<T>))
152 
153 #endif // NDN_CXX_UTIL_CONCEPTS_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
size_t size() const
Returns the size of the encoded wire, i.e., of the whole TLV.
Definition: block.cpp:265
Concept check for an item in a Notification Stream.
Definition: concepts.hpp:126
Concept check for an item in a Status Dataset.
Definition: concepts.hpp:118
A concept check for TLV abstraction with a wireDecode(Block) method and constructible from Block.
Definition: concepts.hpp:82
BOOST_CONCEPT_USAGE(WireDecodable)
Definition: concepts.hpp:84
A concept check for TLV abstraction with a wireEncode(EncodingBuffer) method.
Definition: concepts.hpp:62
BOOST_CONCEPT_USAGE(WireEncodableWithEncodingBuffer)
Definition: concepts.hpp:64
A concept check for TLV abstraction with a wireEncode() method.
Definition: concepts.hpp:46
BOOST_CONCEPT_USAGE(WireEncodable)
Definition: concepts.hpp:48
BOOST_CONCEPT_USAGE(NfdMgmtProtocolStruct)
Definition: concepts.hpp:100
EncodingImpl< EstimatorTag > EncodingEstimator
EncodingImpl< EncoderTag > EncodingBuffer
Definition: data.cpp:25