blob: b61c3014430fd6d3eb567b50e384e213d0b571d2 [file] [log] [blame]
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 Regents of the University of California.
4 *
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 Afanasyev4abdbf12014-08-11 12:48:54 -070027
28namespace ndn {
29
Junxiao Shia4c50482014-12-04 12:40:49 -070030/** \brief a concept check for TLV abstraction with .wireEncode method
31 */
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070032template<class X>
33class WireEncodable
34{
35public:
36 BOOST_CONCEPT_USAGE(WireEncodable)
37 {
38 X j;
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 }
42};
43
Junxiao Shia4c50482014-12-04 12:40:49 -070044/** \brief a concept check for TLV abstraction with .wireDecode method
45 * and constructible from Block
46 */
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070047template<class X>
48class WireDecodable
49{
50public:
51 BOOST_CONCEPT_USAGE(WireDecodable)
52 {
53 Block block;
54 X j(block);
55 j.wireDecode(block);
56 }
57};
58
Junxiao Shia4c50482014-12-04 12:40:49 -070059/** \brief a concept check for CryptoPP hash algorithm
60 */
Yingdi Yude222c72014-08-15 16:06:52 -070061template<class X>
62class Hashable
63{
64public:
65 BOOST_CONCEPT_USAGE(Hashable)
66 {
67 X hash;
68
69 uint8_t* buf = 0;
70 size_t size = hash.DigestSize();
71
72 hash.Update(buf, size);
73 hash.Final(buf);
74 hash.Restart();
75 }
76};
77
Alexander Afanasyev4abdbf12014-08-11 12:48:54 -070078} // namespace ndn
79
80#endif // NDN_UTIL_CONCEPTS_HPP