decode.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_DECODE_HPP
26 #define CRYPTO3_DECODE_HPP
27 
29 
32 
33 #include <nil/crypto3/detail/type_traits.hpp>
34 
35 namespace nil {
36  namespace crypto3 {
55  template<typename Decoder, typename InputIterator, typename OutputIterator>
56  typename std::enable_if<detail::is_iterator<OutputIterator>::value, OutputIterator>::type
57  decode(InputIterator first, InputIterator last, OutputIterator out) {
58 
59  typedef typename Decoder::stream_decoder_type DecodingMode;
60  typedef typename codec::accumulator_set<DecodingMode> CodecAccumulator;
61 
64 
65  return DecoderImpl(first, last, std::move(out), CodecAccumulator());
66  }
67 
88  template<typename Decoder,
89  typename InputIterator,
90  typename CodecAccumulator = typename codec::accumulator_set<typename Decoder::stream_decoder_type>>
92  InputIterator last) {
93 
96 
97  return DecoderImpl(first, last, CodecAccumulator());
98  }
99 
117  template<typename Decoder,
118  typename InputIterator,
119  typename CodecAccumulator = typename codec::accumulator_set<typename Decoder::stream_decoder_type>>
120  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<CodecAccumulator>::value,
121  CodecAccumulator>::type &
122  decode(InputIterator first, InputIterator last, CodecAccumulator &acc) {
123 
124  typedef codec::detail::ref_codec_impl<CodecAccumulator> DecoderStateImpl;
126 
127  return DecoderImpl(first, last, std::forward<CodecAccumulator>(acc));
128  }
129 
146  template<typename Decoder, typename SinglePassRange, typename OutputIterator>
147  typename std::enable_if<detail::is_iterator<OutputIterator>::value, OutputIterator>::type
148  decode(const SinglePassRange &rng, OutputIterator out) {
149 
150  typedef typename Decoder::stream_decoder_type DecodingMode;
151  typedef typename codec::accumulator_set<DecodingMode> CodecAccumulator;
152 
153  typedef codec::detail::value_codec_impl<CodecAccumulator> DecoderStateImpl;
155 
156  return DecoderImpl(rng, std::move(out), CodecAccumulator());
157  }
158 
175  template<typename Decoder,
176  typename SinglePassRange,
177  typename CodecAccumulator = typename codec::accumulator_set<typename Decoder::stream_decoder_type>>
178  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<CodecAccumulator>::value,
179  CodecAccumulator>::type &
180  decode(const SinglePassRange &rng, CodecAccumulator &acc) {
181 
182  typedef codec::detail::value_codec_impl<CodecAccumulator> DecoderStateImpl;
184 
185  return DecoderImpl(rng, std::forward<CodecAccumulator>(acc));
186  }
187 
206  template<typename Decoder,
207  typename SinglePassRange,
208  typename CodecAccumulator = typename codec::accumulator_set<typename Decoder::stream_decoder_type>>
209  codec::detail::range_codec_impl<codec::detail::value_codec_impl<CodecAccumulator>>
210  decode(const SinglePassRange &r) {
211 
212  typedef codec::detail::value_codec_impl<CodecAccumulator> DecoderStateImpl;
214 
215  return DecoderImpl(r, CodecAccumulator());
216  }
217 
234  template<typename Decoder, typename T, typename OutputIterator>
235  typename std::enable_if<detail::is_iterator<OutputIterator>::value, OutputIterator>::type
236  decode(std::initializer_list<T> rng, OutputIterator out) {
237 
238  typedef typename Decoder::stream_decoder_type DecodingMode;
239  typedef typename codec::accumulator_set<DecodingMode> CodecAccumulator;
240 
241  typedef codec::detail::value_codec_impl<CodecAccumulator> DecoderStateImpl;
243 
244  return DecoderImpl(rng, std::move(out), CodecAccumulator());
245  }
246 
263  template<typename Decoder,
264  typename T,
265  typename CodecAccumulator = typename codec::accumulator_set<typename Decoder::stream_decoder_type>>
266  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<CodecAccumulator>::value,
267  CodecAccumulator>::type &
268  decode(std::initializer_list<T> rng, CodecAccumulator &acc) {
269 
270  typedef codec::detail::value_codec_impl<CodecAccumulator> DecoderStateImpl;
272 
273  return DecoderImpl(rng, std::forward<CodecAccumulator>(acc));
274  }
275 
294  template<typename Decoder,
295  typename T,
296  typename CodecAccumulator = typename codec::accumulator_set<typename Decoder::stream_decoder_type>>
297  codec::detail::range_codec_impl<codec::detail::value_codec_impl<CodecAccumulator>>
298  decode(std::initializer_list<T> r) {
299 
300  typedef codec::detail::value_codec_impl<CodecAccumulator> DecoderStateImpl;
302 
303  return DecoderImpl(r, CodecAccumulator());
304  }
305  } // namespace crypto3
306 } // namespace nil
307 
308 #endif // include guard
std::enable_if< detail::is_iterator< OutputIterator >::value, OutputIterator >::type decode(InputIterator first, InputIterator last, OutputIterator out)
Decodes the elements with particular codec defined with Decoder in the range, defined by [first,...
Definition: decode.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