31#include <boost/regex.hpp>
39#include <boost/lexical_cast.hpp>
40#include <boost/numeric/conversion/bounds.hpp>
48#define ASSERT_AND_THROW_WRONG_CONVERSION() ASSERT_MES_AND_THROW("WRONG DATA CONVERSION: from type=" << typeid(from).name() << " to type " << typeid(to).name())
50 template<
typename from_type,
typename to_type>
55 CHECK_AND_ASSERT_THROW_MES(from >=0,
"unexpected int value with signed storage value less than 0, and unsigned receiver value");
57 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());
58 to =
static_cast<to_type
>(from);
61 template<
typename from_type,
typename to_type>
64 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());
67 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());
69 to =
static_cast<to_type
>(from);
71 template<
typename from_type,
typename to_type>
77 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());
78 to =
static_cast<to_type
>(from);
82 template<
typename from_type,
typename to_type,
bool,
bool>
85 template<
typename from_type,
typename to_type>
88 static void convert(
const from_type& from, to_type& to)
94 template<
typename from_type,
typename to_type>
97 static void convert(
const from_type& from, to_type& to)
103 template<
typename from_type,
typename to_type>
106 static void convert(
const from_type& from, to_type& to)
112 template<
typename from_type,
typename to_type>
115 static void convert(
const from_type& from, to_type& to)
122 template<
typename from_type,
typename to_type,
bool>
125 template<
typename from_type,
typename to_type>
128 static void convert(
const from_type& from, to_type& to)
134 template<
typename from_type,
typename to_type>
137 static void convert(
const from_type& from, to_type& to)
151 MTRACE(
"Converting std::string to uint64_t. Source: " << from);
154 to = boost::lexical_cast<uint64_t>(from);
156 else if (boost::regex_match (from, boost::regex(
"\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\dZ")))
161 if (strptime(from.c_str(),
"%Y-%m-%dT%H:%M:%S", &tm))
164 std::istringstream ss(from);
165 if (ss >> std::get_time(&tm,
"%Y-%m-%dT%H:%M:%S"))
167 to = std::mktime(&tm);
173 template<
class from_type,
class to_type>
175 std::is_integral<to_type>::value &&
176 std::is_integral<from_type>::value &&
177 !std::is_same<from_type, bool>::value &&
178 !std::is_same<to_type, bool>::value > {};
180 template<
typename from_type,
typename to_type,
bool>
183 template<
typename from_type,
typename to_type>
186 static void convert(
const from_type& from, to_type& to)
192 template<
typename from_type,
typename to_type>
195 static void convert(
const from_type& from, to_type& to)
202 template<
class from_type,
class to_type>
bool isdigit(char c)
Definition parserse_base_utils.h:91
Definition keyvalue_serialization_overloads.h:49
void convert_t(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:203
void convert_int_to_int(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:62
void convert_uint_to_any_int(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:72
void convert_int_to_uint(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:51
TODO: (mj-xmr) This will be reduced in an another PR.
Definition byte_slice.h:40
const char * name
Definition options.c:30
#define ASSERT_AND_THROW_WRONG_CONVERSION()
Definition portable_storage_val_converters.h:48
unsigned __int64 uint64_t
Definition stdint.h:136
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:137
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:128
static void convert(const std::string &from, uint64_t &to)
Definition portable_storage_val_converters.h:149
Definition portable_storage_val_converters.h:123
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:195
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:186
Definition portable_storage_val_converters.h:181
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:115
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:106
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:97
static void convert(const from_type &from, to_type &to)
Definition portable_storage_val_converters.h:88
Definition portable_storage_val_converters.h:83
Definition portable_storage_val_converters.h:178
#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