accumulators/pubkey.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2021 Ilias Khairullin <ilias@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_ACCUMULATORS_PUBKEY_HPP
27 #define CRYPTO3_ACCUMULATORS_PUBKEY_HPP
28 
29 #include <iterator>
30 #include <type_traits>
31 
32 #include <boost/parameter/value_type.hpp>
33 
34 #include <boost/accumulators/framework/accumulator_base.hpp>
35 #include <boost/accumulators/framework/extractor.hpp>
36 #include <boost/accumulators/framework/depends_on.hpp>
37 #include <boost/accumulators/framework/parameters/sample.hpp>
38 
40 
41 namespace nil {
42  namespace crypto3 {
43  namespace pubkey {
44  namespace accumulators {
45  namespace impl {
46  template<typename ProcessingMode, typename = void>
47  struct pubkey_impl;
48 
49  template<typename ProcessingMode>
50  struct pubkey_impl<ProcessingMode> : boost::accumulators::accumulator_base {
51  protected:
52  typedef ProcessingMode processing_mode_type;
53  typedef typename processing_mode_type::internal_accumulator_type internal_accumulator_type;
54 
55  public:
56  typedef typename processing_mode_type::result_type result_type;
57 
58  template<typename Args>
59  pubkey_impl(const Args &args) :
60  acc(processing_mode_type::init_accumulator(args[boost::accumulators::sample])) {
61  }
62 
63  template<typename Args>
64  inline void operator()(const Args &args) {
65  resolve_type(args[boost::accumulators::sample | nullptr],
66  args[nil::crypto3::accumulators::iterator_last | nullptr]);
67  }
68 
69  inline result_type result(boost::accumulators::dont_care) const {
70  return processing_mode_type::process(acc);
71  }
72 
73  protected:
74  inline void resolve_type(std::nullptr_t, std::nullptr_t) {
75  }
76 
77  template<typename InputRange>
78  inline void resolve_type(const InputRange &range, std::nullptr_t) {
79  processing_mode_type::update(acc, range);
80  }
81 
82  template<typename InputIterator>
83  inline void resolve_type(InputIterator first, InputIterator last) {
84  processing_mode_type::update(acc, first, last);
85  }
86 
88  };
89  } // namespace impl
90 
91  namespace tag {
92  template<typename ProcessingMode>
93  struct pubkey : boost::accumulators::depends_on<> {
94  typedef ProcessingMode processing_mode_type;
95 
98 
99  typedef boost::mpl::always<accumulators::impl::pubkey_impl<processing_mode_type>> impl;
100  };
101  } // namespace tag
102 
103  namespace extract {
104  template<typename ProcessingMode, typename AccumulatorSet>
105  typename boost::mpl::apply<AccumulatorSet, tag::pubkey<ProcessingMode>>::type::result_type
106  pubkey(const AccumulatorSet &acc) {
107  return boost::accumulators::extract_result<tag::pubkey<ProcessingMode>>(acc);
108  }
109  } // namespace extract
110  } // namespace accumulators
111  } // namespace pubkey
112  } // namespace crypto3
113 } // namespace nil
114 
115 #endif // CRYPTO3_ACCUMULATORS_PUBKEY_HPP
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
processing_mode_type::result_type result_type
Definition: accumulators/pubkey.hpp:56
void resolve_type(const InputRange &range, std::nullptr_t)
Definition: accumulators/pubkey.hpp:78
result_type result(boost::accumulators::dont_care) const
Definition: accumulators/pubkey.hpp:69
pubkey_impl(const Args &args)
Definition: accumulators/pubkey.hpp:59
void resolve_type(std::nullptr_t, std::nullptr_t)
Definition: accumulators/pubkey.hpp:74
ProcessingMode processing_mode_type
Definition: accumulators/pubkey.hpp:52
processing_mode_type::internal_accumulator_type internal_accumulator_type
Definition: accumulators/pubkey.hpp:53
void resolve_type(InputIterator first, InputIterator last)
Definition: accumulators/pubkey.hpp:83
void operator()(const Args &args)
Definition: accumulators/pubkey.hpp:64
internal_accumulator_type acc
Definition: accumulators/pubkey.hpp:87
Definition: accumulators/pubkey.hpp:47
Definition: accumulators/pubkey.hpp:93
ProcessingMode processing_mode_type
Definition: accumulators/pubkey.hpp:94
boost::mpl::always< accumulators::impl::pubkey_impl< processing_mode_type > > impl
Definition: accumulators/pubkey.hpp:99