32 #include <boost/regex.hpp> 42 #define ASSERT_AND_THROW_WRONG_CONVERSION() ASSERT_MES_AND_THROW("WRONG DATA CONVERSION: from type=" << typeid(from).name() << " to type " << typeid(to).name()) 44 template<
typename from_type,
typename to_type>
49 CHECK_AND_ASSERT_THROW_MES(from >=0,
"unexpected int value with signed storage value less than 0, and unsigned receiver value");
51 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());
52 to =
static_cast<to_type
>(from);
55 template<
typename from_type,
typename to_type>
58 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());
61 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());
63 to =
static_cast<to_type
>(from);
65 template<
typename from_type,
typename to_type>
71 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());
72 to =
static_cast<to_type
>(from);
76 template<
typename from_type,
typename to_type,
bool,
bool>
79 template<
typename from_type,
typename to_type>
82 static void convert(
const from_type& from, to_type& to)
88 template<
typename from_type,
typename to_type>
91 static void convert(
const from_type& from, to_type& to)
97 template<
typename from_type,
typename to_type>
100 static void convert(
const from_type& from, to_type& to)
106 template<
typename from_type,
typename to_type>
109 static void convert(
const from_type& from, to_type& to)
116 template<
typename from_type,
typename to_type,
bool>
119 template<
typename from_type,
typename to_type>
122 static void convert(
const from_type& from, to_type& to)
128 template<
typename from_type,
typename to_type>
131 static void convert(
const from_type& from, to_type& to)
145 MTRACE(
"Converting std::string to uint64_t. Source: " << from);
148 to = boost::lexical_cast<
uint64_t>(from);
150 else if (boost::regex_match (from, boost::regex(
"\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\dZ")))
155 if (strptime(from.c_str(),
"%Y-%m-%dT%H:%M:%S", &tm))
158 std::istringstream ss(from);
159 if (ss >> std::get_time(&tm,
"%Y-%m-%dT%H:%M:%S"))
161 to = std::mktime(&tm);
167 template<
class from_type,
class to_type>
169 std::is_integral<to_type>::value &&
170 std::is_integral<from_type>::value &&
171 !std::is_same<from_type, bool>::value &&
172 !std::is_same<to_type, bool>::value > {};
174 template<
typename from_type,
typename to_type,
bool>
177 template<
typename from_type,
typename to_type>
180 static void convert(
const from_type& from, to_type& to)
186 template<
typename from_type,
typename to_type>
189 static void convert(
const from_type& from, to_type& to)
196 template<
class from_type,
class to_type>
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
#define ASSERT_AND_THROW_WRONG_CONVERSION()
#define DISABLE_GCC_AND_CLANG_WARNING(w)
static void convert(const from_type &from, to_type &to)
#define DISABLE_CLANG_WARNING(w)
void convert_t(const from_type &from, to_type &to)
int compare(MDB_val const *left, MDB_val const *right) noexcept
static void convert(const from_type &from, to_type &to)
void convert_int_to_int(const from_type &from, to_type &to)
static void convert(const std::string &from, uint64_t &to)
void convert_uint_to_any_int(const from_type &from, to_type &to)
unsigned __int64 uint64_t
static void convert(const from_type &from, to_type &to)
static void convert(const from_type &from, to_type &to)
static void convert(const from_type &from, to_type &to)
static void convert(const from_type &from, to_type &to)
void convert_int_to_uint(const from_type &from, to_type &to)
const GenericPointer< typename T::ValueType > T2 value
static void convert(const from_type &from, to_type &to)
DISABLE_VS_WARNINGS(4244 4345 4503) using namespace crypto
static void convert(const from_type &from, to_type &to)