accumulators/aggregate.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-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_AGGREGATE_HPP
27 #define CRYPTO3_ACCUMULATORS_PUBKEY_AGGREGATE_HPP
28 
29 #include <iterator>
30 #include <type_traits>
31 
32 #include <boost/assert.hpp>
33 #include <boost/concept_check.hpp>
34 
35 #include <boost/range/concepts.hpp>
36 
37 #include <boost/parameter/value_type.hpp>
38 
39 #include <boost/accumulators/framework/accumulator_base.hpp>
40 #include <boost/accumulators/framework/extractor.hpp>
41 #include <boost/accumulators/framework/depends_on.hpp>
42 #include <boost/accumulators/framework/parameters/sample.hpp>
43 
45 
46 namespace nil {
47  namespace crypto3 {
48  namespace pubkey {
49  namespace accumulators {
50  namespace impl {
51  template<typename ProcessingMode>
52  struct aggregate_impl : boost::accumulators::accumulator_base {
53  protected:
54  typedef ProcessingMode processing_mode_type;
55  typedef typename processing_mode_type::op_type op_type;
56  typedef typename processing_mode_type::internal_accumulator_type internal_accumulator_type;
57 
58  public:
59  typedef typename processing_mode_type::result_type result_type;
60 
61  template<typename Args>
62  aggregate_impl(const Args &) {
63  processing_mode_type::init_accumulator(acc);
64  }
65 
66  template<typename Args>
67  inline void operator()(const Args &args) {
68  resolve_type(args[boost::accumulators::sample],
69  args[::nil::crypto3::accumulators::iterator_last | nullptr]);
70  }
71 
72  inline result_type result(boost::accumulators::dont_care) const {
73  return processing_mode_type::process(acc);
74  }
75 
76  protected:
77  template<typename InputRange, typename InputIterator>
78  inline void resolve_type(const InputRange &range, InputIterator) {
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 aggregate : boost::accumulators::depends_on<> {
94  typedef ProcessingMode processing_mode_type;
95 
98 
99  typedef boost::mpl::always<accumulators::impl::aggregate_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::aggregate<ProcessingMode>>::type::result_type
106  aggregate(const AccumulatorSet &acc) {
107  return boost::accumulators::extract_result<tag::aggregate<ProcessingMode>>(acc);
108  }
109  } // namespace extract
110  } // namespace accumulators
111  } // namespace pubkey
112  } // namespace crypto3
113 } // namespace nil
114 
115 #endif // CRYPTO3_ACCUMULATORS_PUBKEY_AGGREGATE_HPP
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
boost::mpl::apply< AccumulatorSet, tag::aggregate< ProcessingMode > >::type::result_type aggregate(const AccumulatorSet &acc)
Definition: accumulators/aggregate.hpp:106
Definition: pair.hpp:31
Definition: accumulators/aggregate.hpp:52
aggregate_impl(const Args &)
Definition: accumulators/aggregate.hpp:62
void resolve_type(const InputRange &range, InputIterator)
Definition: accumulators/aggregate.hpp:78
processing_mode_type::result_type result_type
Definition: accumulators/aggregate.hpp:59
internal_accumulator_type acc
Definition: accumulators/aggregate.hpp:87
processing_mode_type::op_type op_type
Definition: accumulators/aggregate.hpp:55
ProcessingMode processing_mode_type
Definition: accumulators/aggregate.hpp:54
void resolve_type(InputIterator first, InputIterator last)
Definition: accumulators/aggregate.hpp:83
void operator()(const Args &args)
Definition: accumulators/aggregate.hpp:67
result_type result(boost::accumulators::dont_care) const
Definition: accumulators/aggregate.hpp:72
processing_mode_type::internal_accumulator_type internal_accumulator_type
Definition: accumulators/aggregate.hpp:56
Definition: accumulators/aggregate.hpp:93
boost::mpl::always< accumulators::impl::aggregate_impl< processing_mode_type > > impl
Definition: accumulators/aggregate.hpp:99
ProcessingMode processing_mode_type
Definition: accumulators/aggregate.hpp:94