hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
soci_std_optional.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SOCI_STD_OPTIONAL_HPP
7 #define IROHA_SOCI_STD_OPTIONAL_HPP
8 
9 #include <soci/type-conversion-traits.h>
10 
11 #include <optional>
12 
13 namespace soci {
14 
15  // simple fall-back for std::optional
16  template <typename T>
17  struct type_conversion<std::optional<T>> {
18  typedef typename type_conversion<T>::base_type base_type;
19 
20  static void from_base(base_type const &in,
21  indicator ind,
22  std::optional<T> &out) {
23  if (ind == i_null) {
24  out.reset();
25  } else {
26  T tmp = T();
27  type_conversion<T>::from_base(in, ind, tmp);
28  out = tmp;
29  }
30  }
31 
32  static void to_base(std::optional<T> const &in,
33  base_type &out,
34  indicator &ind) {
35  if (in) {
36  type_conversion<T>::to_base(in.value(), out, ind);
37  } else {
38  ind = i_null;
39  }
40  }
41  };
42 
43  template <>
44  struct type_conversion<std::nullopt_t> {
45  typedef int base_type;
46 
47  static void from_base(base_type const & /*in*/,
48  indicator /*ind*/,
49  std::nullopt_t & /*out*/) {}
50 
51  static void to_base(std::nullopt_t const & /*in*/,
52  base_type & /*out*/,
53  indicator &ind) {
54  ind = i_null;
55  }
56  };
57 
58 } // namespace soci
59 
60 #endif // IROHA_SOCI_STD_OPTIONAL_HPP
type_conversion< T >::base_type base_type
Definition: soci_std_optional.hpp:18
Definition: peer.hpp:48
int base_type
Definition: soci_std_optional.hpp:45
static void from_base(base_type const &, indicator, std::nullopt_t &)
Definition: soci_std_optional.hpp:47
static void to_base(std::optional< T > const &in, base_type &out, indicator &ind)
Definition: soci_std_optional.hpp:32
static void to_base(std::nullopt_t const &, base_type &, indicator &ind)
Definition: soci_std_optional.hpp:51
static void from_base(base_type const &in, indicator ind, std::optional< T > &out)
Definition: soci_std_optional.hpp:20
Definition: pool_wrapper.hpp:11