31 #include <boost/regex.hpp> 39 #include <boost/lexical_cast.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)
150 MTRACE(
"Converting std::string to uint64_t. Source: " << from);
153 to = boost::lexical_cast<
uint64_t>(from);
155 else if (boost::regex_match (from, boost::regex(
"\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\dZ")))
160 if (strptime(from.c_str(),
"%Y-%m-%dT%H:%M:%S", &tm))
163 std::istringstream ss(from);
164 if (ss >> std::get_time(&tm,
"%Y-%m-%dT%H:%M:%S"))
166 to = std::mktime(&tm);
172 template<
class from_type,
class to_type>
174 std::is_integral<to_type>::value &&
175 std::is_integral<from_type>::value &&
176 !std::is_same<from_type, bool>::value &&
177 !std::is_same<to_type, bool>::value > {};
179 template<
typename from_type,
typename to_type,
bool>
182 template<
typename from_type,
typename to_type>
185 static void convert(
const from_type& from, to_type& to)
191 template<
typename from_type,
typename to_type>
194 static void convert(
const from_type& from, to_type& to)
201 template<
class from_type,
class to_type>
Definition: binary_utils.h:36
#define ASSERT_AND_THROW_WRONG_CONVERSION()
Definition: portable_storage_val_converters.h:47
#define DISABLE_GCC_AND_CLANG_WARNING(w)
Definition: warnings.h:28
PUSH_WARNINGS
Definition: hash-ops.h:53
static void convert(const from_type &from, to_type &to)
Definition: portable_storage_val_converters.h:185
bool isdigit(char c)
Definition: parserse_base_utils.h:91
Definition: portable_storage_val_converters.h:82
::std::string string
Definition: gtest-port.h:1097
std::string convert(char val)
Definition: abstract_http_client.cpp:74
#define DISABLE_CLANG_WARNING(w)
Definition: warnings.h:25
void convert_t(const from_type &from, to_type &to)
Definition: portable_storage_val_converters.h:202
Definition: portable_storage_val_converters.h:122
Definition: portable_storage_val_converters.h:180
static void convert(const from_type &from, to_type &to)
Definition: portable_storage_val_converters.h:114
Definition: portable_storage_val_converters.h:173
void convert_int_to_int(const from_type &from, to_type &to)
Definition: portable_storage_val_converters.h:61
#define POP_WARNINGS
Definition: warnings.h:17
static void convert(const std::string &from, uint64_t &to)
Definition: portable_storage_val_converters.h:148
void convert_uint_to_any_int(const from_type &from, to_type &to)
Definition: portable_storage_val_converters.h:71
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:105
static void convert(const from_type &from, to_type &to)
Definition: portable_storage_val_converters.h:194
#define false
Definition: stdbool.h:37
DISABLE_VS_WARNINGS(4244 4345 4503) using namespace crypto
static void convert(const from_type &from, to_type &to)
Definition: portable_storage_val_converters.h:96
TODO: (mj-xmr) This will be reduced in an another PR.
Definition: byte_slice.h:39
void convert_int_to_uint(const from_type &from, to_type &to)
Definition: portable_storage_val_converters.h:50
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
static void convert(const from_type &from, to_type &to)
Definition: portable_storage_val_converters.h:87
const char * name
Definition: options.c:30
static void convert(const from_type &from, to_type &to)
Definition: portable_storage_val_converters.h:127
#define true
Definition: stdbool.h:36