7 #include <boost/numeric/conversion/cast.hpp>
14 template<
typename SourceType,
typename DestType>
21 using round_style = boost::mpl::integral_c<std::float_round_style, std::round_to_nearest>;
25 boost::numeric::converter<DestType, SourceType, boost::numeric::conversion_traits<DestType, SourceType>,
29 template<
typename SourceType>
32 static Void convert(__attribute__((unused)) SourceType s) {
return {}; }
36 template<
typename DestType>
39 static DestType
convert(__attribute__((unused))
Void s) {
return 0.0; }
47 template<
typename CookedType,
typename RAW_ITERATOR,
typename COOKED_ITERATOR>
49 const RAW_ITERATOR& raw_begin,
const RAW_ITERATOR& raw_end,
const COOKED_ITERATOR& cooked_begin)
const {
51 assert((std::is_same<
typename std::iterator_traits<RAW_ITERATOR>::value_type, int32_t>::value));
52 static_assert(std::is_same<
typename std::iterator_traits<RAW_ITERATOR>::value_type, int8_t>::value ||
53 std::is_same<
typename std::iterator_traits<RAW_ITERATOR>::value_type, int16_t>::value ||
54 std::is_same<
typename std::iterator_traits<RAW_ITERATOR>::value_type, int32_t>::value,
55 "RAW_ITERATOR template argument must be an iterator with value type equal to int8_t, int16_t or int32_t.");
56 static_assert(std::is_same<
typename std::iterator_traits<COOKED_ITERATOR>::value_type, CookedType>::value,
57 "COOKED_ITERATOR template argument must be an iterator with value type equal to the CookedType template "
62 template<
typename CookedType,
typename RAW_ITERATOR,
typename COOKED_ITERATOR>
64 static void impl(
const RAW_ITERATOR& raw_begin,
const RAW_ITERATOR& raw_end, COOKED_ITERATOR cooked_begin);
68 template<
typename CookedType>
71 vectorToCooked<CookedType>(&
raw, (&
raw) + 1, &cooked);
75 template<
typename CookedType>
76 uint32_t
toRaw(CookedType cookedValue)
const;
85 template<
typename CookedType,
typename RAW_ITERATOR,
typename COOKED_ITERATOR>
87 const RAW_ITERATOR& raw_begin,
const RAW_ITERATOR& raw_end, COOKED_ITERATOR cooked_begin) {
88 for(
auto it = raw_begin; it != raw_end; ++it) {
90 float genericRepresentation;
91 memcpy(&genericRepresentation, &(*it),
sizeof(
float));
99 template<
typename CookedType>
103 float genericRepresentation;
107 catch(boost::numeric::positive_overflow&) {
108 genericRepresentation = FLT_MAX;
110 catch(boost::numeric::negative_overflow&) {
111 genericRepresentation = -FLT_MAX;
115 void* warningAvoider = &genericRepresentation;
117 int32_t rawValue = *(
reinterpret_cast<int32_t*
>(warningAvoider));
122 template<
typename RAW_ITERATOR,
typename COOKED_ITERATOR>
124 static void impl(
const RAW_ITERATOR& raw_begin,
const RAW_ITERATOR& raw_end, COOKED_ITERATOR cooked_begin) {
125 for(
auto it = raw_begin; it != raw_end; ++it) {
128 float genericRepresentation = *(
reinterpret_cast<const float*
>(&(*it)));