36#include <boost/numeric/conversion/bounds.hpp>
47#define ASSERT_AND_THROW_WRONG_CONVERSION() ASSERT_MES_AND_THROW("WRONG DATA CONVERSION: from type=" << typeid(from).name() << " to type " << typeid(to).name())
49 template<
typename from_type,
typename to_type>
54 CHECK_AND_ASSERT_THROW_MES(from >=0,
"unexpected int value with signed storage value less than 0, and unsigned receiver value");
56 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());
57 to =
static_cast<to_type
>(from);
60 template<
typename from_type,
typename to_type>
63 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());
66 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());
68 to =
static_cast<to_type
>(from);
70 template<
typename from_type,
typename to_type>
76 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());
77 to =
static_cast<to_type
>(from);
81 template<
typename from_type,
typename to_type,
bool,
bool>
84 template<
typename from_type,
typename to_type>
87 static void convert(
const from_type& from, to_type& to)
93 template<
typename from_type,
typename to_type>
96 static void convert(
const from_type& from, to_type& to)
102 template<
typename from_type,
typename to_type>
105 static void convert(
const from_type& from, to_type& to)
111 template<
typename from_type,
typename to_type>
114 static void convert(
const from_type& from, to_type& to)
121 template<
typename from_type,
typename to_type,
bool>
124 template<
typename from_type,
typename to_type>
127 static void convert(
const from_type& from, to_type& to)
133 template<
typename from_type,
typename to_type>
136 static void convert(
const from_type& from, to_type& to)
151 for (
const char c : from)
153 if (c <
'0' || c >
'9')
156 if (
value > (std::numeric_limits<uint64_t>::max() - digit) / 10)
164 template<
class from_type,
class to_type>
166 std::is_integral<to_type>::value &&
167 std::is_integral<from_type>::value &&
168 !std::is_same<from_type, bool>::value &&
169 !std::is_same<to_type, bool>::value > {};
171 template<
typename from_type,
typename to_type,
bool>
174 template<
typename from_type,
typename to_type>
177 static void convert(
const from_type& from, to_type& to)
183 template<
typename from_type,
typename to_type>
186 static void convert(
const from_type& from, to_type& to)
193 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:194
void convert_int_to_int(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:61
void convert_uint_to_any_int(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:71
void convert_int_to_uint(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:50
TODO: (mj-xmr) This will be reduced in an another PR.
Definition byte_slice.h:40
const GenericPointer< typename T::ValueType > T2 value
Definition pointer.h:1225
#define ASSERT_AND_THROW_WRONG_CONVERSION()
Definition portable_storage_val_converters.h:47
unsigned __int64 uint64_t
Definition stdint.h:136
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:136
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:127
static void convert(const std::string &from, uint64_t &to)
Definition portable_storage_val_converters.h:145
Definition portable_storage_val_converters.h:122
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:186
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:177
Definition portable_storage_val_converters.h:172
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:114
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:105
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:96
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:87
Definition portable_storage_val_converters.h:82
Definition portable_storage_val_converters.h:169
#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