blob: 8d4567ef0ddda3a7764f96fb33b35554799d1bd1 [file] [log] [blame]
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevd5c48e02015-06-24 11:58:14 -07003 * Copyright (c) 2013-2015 Regents of the University of California.
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_UTIL_CONCEPTS_HPP
23#define NDN_UTIL_CONCEPTS_HPP
24
25#include <boost/concept/usage.hpp>
Junxiao Shia4c50482014-12-04 12:40:49 -070026#include "../encoding/block.hpp"
Alexander Afanasyevd5c48e02015-06-24 11:58:14 -070027#include "../encoding/encoding-buffer.hpp"
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070028
29namespace ndn {
30
Junxiao Shia4c50482014-12-04 12:40:49 -070031/** \brief a concept check for TLV abstraction with .wireEncode method
32 */
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070033template<class X>
34class WireEncodable
35{
36public:
37 BOOST_CONCEPT_USAGE(WireEncodable)
38 {
Junxiao Shia4c50482014-12-04 12:40:49 -070039 Block block = j.wireEncode();
40 block.size(); // avoid 'unused variable block'
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070041 }
Alexander Afanasyevd5c48e02015-06-24 11:58:14 -070042
43private:
44 X j;
45};
46
47/** \brief a concept check for TLV abstraction with .wireEncode method
48 */
49template<class X>
50class WireEncodableWithEncodingBuffer
51{
52public:
53 BOOST_CONCEPT_USAGE(WireEncodableWithEncodingBuffer)
54 {
55 EncodingEstimator estimator;
56 size_t estimatedSize = j.wireEncode(estimator);
57
58 EncodingBuffer encoder(estimatedSize, 0);
59 j.wireEncode(encoder);
60 }
61
62private:
63 X j;
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070064};
65
Junxiao Shia4c50482014-12-04 12:40:49 -070066/** \brief a concept check for TLV abstraction with .wireDecode method
67 * and constructible from Block
68 */
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070069template<class X>
70class WireDecodable
71{
72public:
73 BOOST_CONCEPT_USAGE(WireDecodable)
74 {
75 Block block;
76 X j(block);
77 j.wireDecode(block);
78 }
79};
80
Junxiao Shia4c50482014-12-04 12:40:49 -070081/** \brief a concept check for CryptoPP hash algorithm
82 */
Yingdi Yude222c72014-08-15 16:06:52 -070083template<class X>
84class Hashable
85{
86public:
87 BOOST_CONCEPT_USAGE(Hashable)
88 {
89 X hash;
Yingdi Yude222c72014-08-15 16:06:52 -070090 uint8_t* buf = 0;
91 size_t size = hash.DigestSize();
92
93 hash.Update(buf, size);
94 hash.Final(buf);
95 hash.Restart();
96 }
97};
98
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070099} // namespace ndn
100
101#endif // NDN_UTIL_CONCEPTS_HPP