36#include <boost/numeric/conversion/bounds.hpp>
45#define ASSERT_AND_THROW_WRONG_CONVERSION() ASSERT_MES_AND_THROW("WRONG DATA CONVERSION: from type=" << typeid(from).name() << " to type " << typeid(to).name())
47 template<
typename from_type,
typename to_type>
52 CHECK_AND_ASSERT_THROW_MES(from >=0,
"unexpected int value with signed storage value less than 0, and unsigned receiver value");
54 CHECK_AND_ASSERT_THROW_MES(from <= std::numeric_limits<to_type>::max(),
"int value overhead: try to set value " << from <<
" to type " <<
typeid(to_type).name() <<
" with max possible value = " << std::numeric_limits<to_type>::max());
55 to =
static_cast<to_type
>(from);
58 template<
typename from_type,
typename to_type>
61 CHECK_AND_ASSERT_THROW_MES(from >= boost::numeric::bounds<to_type>::lowest(),
"int value overhead: try to set value " << from <<
" to type " <<
typeid(to_type).name() <<
" with lowest possible value = " << boost::numeric::bounds<to_type>::lowest());
64 CHECK_AND_ASSERT_THROW_MES(from <= std::numeric_limits<to_type>::max(),
"int value overhead: try to set value " << from <<
" to type " <<
typeid(to_type).name() <<
" with max possible value = " << std::numeric_limits<to_type>::max());
66 to =
static_cast<to_type
>(from);
68 template<
typename from_type,
typename to_type>
74 CHECK_AND_ASSERT_THROW_MES(from <= std::numeric_limits<to_type>::max(),
"uint value overhead: try to set value " << from <<
" to type " <<
typeid(to_type).name() <<
" with max possible value = " << std::numeric_limits<to_type>::max());
75 to =
static_cast<to_type
>(from);
79 template<
typename from_type,
typename to_type,
bool,
bool>
82 template<
typename from_type,
typename to_type>
85 static void convert(
const from_type& from, to_type& to)
91 template<
typename from_type,
typename to_type>
94 static void convert(
const from_type& from, to_type& to)
100 template<
typename from_type,
typename to_type>
103 static void convert(
const from_type& from, to_type& to)
109 template<
typename from_type,
typename to_type>
112 static void convert(
const from_type& from, to_type& to)
119 template<
typename from_type,
typename to_type,
bool>
122 template<
typename from_type,
typename to_type>
125 static void convert(
const from_type& from, to_type& to)
131 template<
typename from_type,
typename to_type>
134 static void convert(
const from_type& from, to_type& to)
140 template<
class from_type,
class to_type>
142 std::is_integral<to_type>::value &&
143 std::is_integral<from_type>::value &&
144 !std::is_same<from_type, bool>::value &&
145 !std::is_same<to_type, bool>::value > {};
147 template<
typename from_type,
typename to_type,
bool>
150 template<
typename from_type,
typename to_type>
153 static void convert(
const from_type& from, to_type& to)
159 template<
typename from_type,
typename to_type>
162 static void convert(
const from_type& from, to_type& to)
169 template<
class from_type,
class to_type>
Definition keyvalue_serialization_overloads.h:49
void convert_t(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:170
void convert_int_to_int(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:59
void convert_uint_to_any_int(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:69
void convert_int_to_uint(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:48
TODO: (mj-xmr) This will be reduced in an another PR.
Definition byte_slice.h:40
#define ASSERT_AND_THROW_WRONG_CONVERSION()
Definition portable_storage_val_converters.h:45
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:134
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:125
Definition portable_storage_val_converters.h:120
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:162
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:153
Definition portable_storage_val_converters.h:148
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:112
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:103
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:94
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:85
Definition portable_storage_val_converters.h:80
Definition portable_storage_val_converters.h:145
#define DISABLE_GCC_AND_CLANG_WARNING(w)
Definition warnings.h:28
#define DISABLE_VS_WARNINGS(w)
Definition warnings.h:18
#define DISABLE_CLANG_WARNING(w)
Definition warnings.h:25
#define POP_WARNINGS
Definition warnings.h:17
#define PUSH_WARNINGS
Definition warnings.h:16