BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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 #if defined(__clang__)
78  // Fix: https://github.com/bitshares/bitshares-core/issues/2197
79  #pragma clang diagnostic push
80  #pragma clang diagnostic ignored "-Wmismatched-tags"
81 #endif
82  template< typename T, size_t N >
83  class tuple_size< fc::zero_initialized_array< T, N > > : public tuple_size< array< T, N > > {};
84 #if defined(__clang__)
85  #pragma clang diagnostic pop
86 #endif
87 }
fc::zero_initialized_array< unsigned char, N >
Definition: zeroed_array.hpp:33
fc::to_string
std::string to_string(double)
Definition: string.cpp:73
fc::raw::unpack
void unpack(Stream &s, flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:23
fc
Definition: api.hpp:15
fc::zero_initialized_array< unsigned char, N >::zero_initialized_array
zero_initialized_array()
Definition: zeroed_array.hpp:35
fc::zero_initialized_array
Definition: zeroed_array.hpp:30
fc::from_variant
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
fc::get_typename
Definition: typename.hpp:20
fc::to_variant
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
fc::get_typename< zero_initialized_array< T, N > >::name
static const char * name()
Definition: zeroed_array.hpp:41
fc::variant
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition: variant.hpp:198
std
Definition: zeroed_array.hpp:76
FC_RETHROW_EXCEPTIONS
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log m...
Definition: exception.hpp:464
raw_fwd.hpp
fc::raw::pack
void pack(Stream &s, const flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:11