Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 1 | /* -*- 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 Shi | a4c5048 | 2014-12-04 12:40:49 -0700 | [diff] [blame^] | 26 | #include "../encoding/block.hpp" |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | |
Junxiao Shi | a4c5048 | 2014-12-04 12:40:49 -0700 | [diff] [blame^] | 30 | /** \brief a concept check for TLV abstraction with .wireEncode method |
| 31 | */ |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 32 | template<class X> |
| 33 | class WireEncodable |
| 34 | { |
| 35 | public: |
| 36 | BOOST_CONCEPT_USAGE(WireEncodable) |
| 37 | { |
| 38 | X j; |
Junxiao Shi | a4c5048 | 2014-12-04 12:40:49 -0700 | [diff] [blame^] | 39 | Block block = j.wireEncode(); |
| 40 | block.size(); // avoid 'unused variable block' |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 41 | } |
| 42 | }; |
| 43 | |
Junxiao Shi | a4c5048 | 2014-12-04 12:40:49 -0700 | [diff] [blame^] | 44 | /** \brief a concept check for TLV abstraction with .wireDecode method |
| 45 | * and constructible from Block |
| 46 | */ |
Alexander Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 47 | template<class X> |
| 48 | class WireDecodable |
| 49 | { |
| 50 | public: |
| 51 | BOOST_CONCEPT_USAGE(WireDecodable) |
| 52 | { |
| 53 | Block block; |
| 54 | X j(block); |
| 55 | j.wireDecode(block); |
| 56 | } |
| 57 | }; |
| 58 | |
Junxiao Shi | a4c5048 | 2014-12-04 12:40:49 -0700 | [diff] [blame^] | 59 | /** \brief a concept check for CryptoPP hash algorithm |
| 60 | */ |
Yingdi Yu | de222c7 | 2014-08-15 16:06:52 -0700 | [diff] [blame] | 61 | template<class X> |
| 62 | class Hashable |
| 63 | { |
| 64 | public: |
| 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 Afanasyev | 4abdbf1 | 2014-08-11 12:48:54 -0700 | [diff] [blame] | 78 | } // namespace ndn |
| 79 | |
| 80 | #endif // NDN_UTIL_CONCEPTS_HPP |