BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
zeroed_array.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 BitShares Blockchain Foundation, and contributors
3  *
4  * The 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
14  * all 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
22  * THE SOFTWARE.
23  */
24 #pragma once
25 #include <fc/io/raw_fwd.hpp>
26 
27 namespace fc {
28 
29  template< typename T, size_t N >
31 
32  template< size_t N >
33  class zero_initialized_array< unsigned char, N > : public std::array< unsigned char, N > {
34  public:
35  zero_initialized_array() : std::array< unsigned char, N >() { }
36  };
37 
38  template<typename T,size_t N>
40  {
41  static const char* name()
42  {
43  static std::string _name = std::string("zero_initialized_array<")
44  + std::string(fc::get_typename<T>::name())
45  + "," + fc::to_string(N) + ">";
46  return _name.c_str();
47  }
48  };
49 
50  class variant;
51  template<size_t N>
52  void to_variant( const zero_initialized_array<unsigned char,N>& bi, variant& v, uint32_t max_depth = 1 )
53  {
54  to_variant( static_cast<const std::array<unsigned char,N>&>( bi ), v, max_depth );
55  }
56  template<size_t N>
57  void from_variant( const variant& v, zero_initialized_array<unsigned char,N>& bi, uint32_t max_depth = 1 )
58  {
59  from_variant( v, static_cast<std::array<unsigned char,N>&>( bi ), max_depth );
60  }
61 
62  namespace raw {
63  template<typename Stream, size_t N>
64  inline void pack( Stream& s, const zero_initialized_array<unsigned char,N>& v, uint32_t _max_depth ) {
65  pack( s, static_cast<const std::array<unsigned char,N>&>( v ), _max_depth );
66  }
67  template<typename Stream, size_t N>
68  inline void unpack( Stream& s, zero_initialized_array<unsigned char,N>& v, uint32_t _max_depth ) {
69  try {
70  unpack( s, static_cast<std::array<unsigned char,N>&>( v ), _max_depth );
71  } FC_RETHROW_EXCEPTIONS( warn, "zero_initialized_array<unsigned char,${length}>", ("length",N) )
72  }
73  }
74 }
75 
76 namespace std {
77  template< typename T, size_t N >
78  class tuple_size< fc::zero_initialized_array< T, N > > : public tuple_size< array< T, N > > {};
79 }
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception&#39;s, std::exceptions, and ... and rethrows them after appending the provided log m...
Definition: exception.hpp:463
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
void unpack(Stream &s, zero_initialized_array< unsigned char, N > &v, uint32_t _max_depth)
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
std::string to_string(double)
Definition: string.cpp:73
Definition: api.hpp:15
void pack(Stream &s, const zero_initialized_array< unsigned char, N > &v, uint32_t _max_depth)