hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
variant_deserializer.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_VARIANT_DESERIALIZER_HPP
7 #define IROHA_VARIANT_DESERIALIZER_HPP
8 
9 #include <boost/serialization/variant.hpp>
10 
11 #define NORETURN [[noreturn]]
12 
13 namespace shared_model {
14  namespace detail {
20  template <class S>
21  struct variant_impl {
25  struct load_null {
31  template <class V, class Archive>
32  NORETURN static V invoke(Archive &&, int) {
33  BOOST_ASSERT_MSG(false, "Required type not found");
34  std::abort();
35  }
36  };
37 
41  struct load_impl {
53  template <class V, class Archive>
54  static V invoke(Archive &&ar, int which) {
55  if (which == 0) {
56  using head_type = typename boost::mpl::front<S>::type;
57  return head_type(std::forward<Archive>(ar));
58  } else {
59  using type = typename boost::mpl::pop_front<S>::type;
60  return variant_impl<type>::template load<V>(
61  std::forward<Archive>(ar), which - 1);
62  }
63  }
64  };
65 
75  template <class V, class Archive>
76  static V load(Archive &&ar, int which) {
77  using typex =
78  typename boost::mpl::eval_if<boost::mpl::empty<S>,
79  boost::mpl::identity<load_null>,
80  boost::mpl::identity<load_impl>>::type;
81  return typex::template invoke<V>(std::forward<Archive>(ar), which);
82  }
83  };
84  } // namespace detail
85 } // namespace shared_model
86 
87 #endif // IROHA_VARIANT_DESERIALIZER_HPP
static V invoke(Archive &&ar, int which)
Definition: variant_deserializer.hpp:54
#define NORETURN
Definition: variant_deserializer.hpp:11
Definition: variant_deserializer.hpp:25
static NORETURN V invoke(Archive &&, int)
Definition: variant_deserializer.hpp:32
static V load(Archive &&ar, int which)
Definition: variant_deserializer.hpp:76
Definition: variant_deserializer.hpp:21
Definition: variant_deserializer.hpp:41
Definition: command_executor.hpp:12