codec/include/nil/crypto3/codec/algorithm/encode.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 //
4 // MIT License
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //---------------------------------------------------------------------------//
24 
25 #ifndef CRYPTO3_ENCODE_HPP
26 #define CRYPTO3_ENCODE_HPP
27 
29 
32 
33 #include <nil/crypto3/detail/type_traits.hpp>
34 
35 namespace nil {
36  namespace crypto3 {
55  template<typename Encoder, typename InputIterator, typename OutputIterator>
56  typename std::enable_if<detail::is_iterator<OutputIterator>::value, OutputIterator>::type
57  encode(InputIterator first, InputIterator last, OutputIterator out) {
58 
59  typedef typename Encoder::stream_encoder_type EncodingMode;
60  typedef typename codec::accumulator_set<EncodingMode> CodecAccumulator;
61 
64 
65  return EncoderImpl(first, last, std::move(out), CodecAccumulator());
66  }
67 
88  template<typename Encoder,
89  typename InputIterator,
90  typename CodecAccumulator = typename codec::accumulator_set<typename Encoder::stream_encoder_type>>
92  InputIterator last) {
95 
96  return EncoderImpl(first, last, CodecAccumulator());
97  }
98 
117  template<typename Encoder,
118  typename InputIterator,
119  typename CodecAccumulator = typename codec::accumulator_set<typename Encoder::stream_encoder_type>>
120  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<CodecAccumulator>::value,
121  CodecAccumulator>::type &
122  encode(InputIterator first, InputIterator last, CodecAccumulator &acc) {
123 
124  typedef codec::detail::ref_codec_impl<CodecAccumulator> EncoderStateImpl;
126 
127  return EncoderImpl(first, last, std::forward<CodecAccumulator>(acc));
128  }
129 
147  template<typename Encoder, typename SinglePassRange, typename OutputIterator>
148  typename std::enable_if<detail::is_iterator<OutputIterator>::value, OutputIterator>::type
149  encode(const SinglePassRange &rng, OutputIterator out) {
150 
151  typedef typename Encoder::stream_encoder_type EncodingMode;
152  typedef typename codec::accumulator_set<EncodingMode> CodecAccumulator;
153 
154  typedef codec::detail::value_codec_impl<CodecAccumulator> EncoderStateImpl;
156 
157  return EncoderImpl(rng, std::move(out), CodecAccumulator());
158  }
159 
176  template<typename Encoder,
177  typename SinglePassRange,
178  typename CodecAccumulator = typename codec::accumulator_set<typename Encoder::stream_encoder_type>>
179  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<CodecAccumulator>::value,
180  CodecAccumulator>::type &
181  encode(const SinglePassRange &rng, CodecAccumulator &acc) {
182 
183  typedef codec::detail::ref_codec_impl<CodecAccumulator> EncoderStateImpl;
185 
186  return EncoderImpl(rng, std::forward<CodecAccumulator>(acc));
187  }
188 
207  template<typename Encoder,
208  typename SinglePassRange,
209  typename CodecAccumulator = typename codec::accumulator_set<typename Encoder::stream_encoder_type>>
210  codec::detail::range_codec_impl<codec::detail::value_codec_impl<CodecAccumulator>>
211  encode(const SinglePassRange &r) {
212 
213  typedef codec::detail::value_codec_impl<CodecAccumulator> EncoderStateImpl;
215 
216  return EncoderImpl(r, CodecAccumulator());
217  }
218 
236  template<typename Encoder, typename T, typename OutputIterator>
237  typename std::enable_if<detail::is_iterator<OutputIterator>::value, OutputIterator>::type
238  encode(std::initializer_list<T> rng, OutputIterator out) {
239 
240  typedef typename Encoder::stream_encoder_type EncodingMode;
241  typedef typename codec::accumulator_set<EncodingMode> CodecAccumulator;
242 
243  typedef codec::detail::value_codec_impl<CodecAccumulator> EncoderStateImpl;
245 
246  return EncoderImpl(rng, std::move(out), CodecAccumulator());
247  }
248 
265  template<typename Encoder,
266  typename T,
267  typename CodecAccumulator = typename codec::accumulator_set<typename Encoder::stream_encoder_type>>
268  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<CodecAccumulator>::value,
269  CodecAccumulator>::type &
270  encode(std::initializer_list<T> rng, CodecAccumulator &acc) {
271 
272  typedef codec::detail::ref_codec_impl<CodecAccumulator> EncoderStateImpl;
274 
275  return EncoderImpl(rng, std::forward<CodecAccumulator>(acc));
276  }
277 
296  template<typename Encoder,
297  typename T,
298  typename CodecAccumulator = typename codec::accumulator_set<typename Encoder::stream_encoder_type>>
299  codec::detail::range_codec_impl<codec::detail::value_codec_impl<CodecAccumulator>>
300  encode(std::initializer_list<T> r) {
301 
302  typedef codec::detail::value_codec_impl<CodecAccumulator> EncoderStateImpl;
304 
305  return EncoderImpl(r, CodecAccumulator());
306  }
307  } // namespace crypto3
308 } // namespace nil
309 
310 #endif
std::enable_if< detail::is_iterator< OutputIterator >::value, OutputIterator >::type encode(InputIterator first, InputIterator last, OutputIterator out)
Encodes the elements with particular codec defined with Encoder in the range, defined by [first,...
Definition: codec/include/nil/crypto3/codec/algorithm/encode.hpp:57
boost::accumulators::accumulator_set< digest< ProcessingMode::output_block_bits >, boost::accumulators::features< accumulators::tag::codec< ProcessingMode > >, std::size_t > accumulator_set
Accumulator set with codec accumulator predefined params.
Definition: codec_state.hpp:67
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
Definition: pair.hpp:31
Definition: codec_value.hpp:142
Definition: codec_value.hpp:72
Definition: codec_value.hpp:41
Definition: codec_value.hpp:56