block/include/nil/crypto3/detail/pack_numeric.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_PACK_NUMERIC_HPP
26 #define CRYPTO3_PACK_NUMERIC_HPP
27 
28 #include <boost/assert.hpp>
29 #include <boost/static_assert.hpp>
30 
31 #include <nil/crypto3/multiprecision/cpp_int.hpp>
32 
33 namespace nil {
34  namespace crypto3 {
35  namespace detail {
36  using namespace nil::crypto3::multiprecision;
37 
38  template<typename Endianness, int InValueBits, int OutValueBits, typename InputIterator, typename Backend,
39  expression_template_option ExpressionTemplates>
40  inline void pack(InputIterator first, InputIterator last, number<Backend, ExpressionTemplates> &out) {
41  import_bits(out, first, last);
42  BOOST_ASSERT(msb(out) == OutValueBits);
43  }
44 
45  template<typename Endianness, int OutValueBits, typename InputType, typename Backend,
46  expression_template_option ExpressionTemplates>
47  inline void pack(const InputType &in, number<Backend, ExpressionTemplates> &out) {
48  import_bits(out, in.begin(), in.end());
49  BOOST_ASSERT(msb(out) == OutValueBits);
50  }
51 
52  template<typename Endianness, int OutValueBits, typename OutputType, typename Backend,
53  expression_template_option ExpressionTemplates>
54  inline void pack(const number<Backend, ExpressionTemplates> &in, OutputType &out) {
55  export_bits(in, out);
56  BOOST_ASSERT(msb(out) == OutValueBits);
57  }
58  } // namespace detail
59  } // namespace crypto3
60 } // namespace nil
61 
62 #endif // CRYPTO3_BLOCK_PACK_HPP
void pack(InputIterator first, InputIterator last, std::random_access_iterator_tag, OutputIterator out)
Packs elements from the range [first, last) into elements starting from out. Works for input containe...
Definition: block/include/nil/crypto3/detail/pack.hpp:835
Definition: pair.hpp:31