Skip to content

Commit f07c2e2

Browse files
committed
Preparations for boost fpclassify replacement
1 parent db6688d commit f07c2e2

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

src/portable_archive/portable_archive_includes.hpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,45 @@
9696
#include <boost/endian/conversion.hpp>
9797
#include <boost/math/special_functions/fpclassify.hpp>
9898

99-
// namespace alias fp_classify
100-
namespace fp = lslboost::math;
101-
102-
// namespace alias endian
103-
namespace endian = lslboost::endian;
104-
10599
// generic type traits for numeric types
100+
#include "portable_archive_exception.hpp"
101+
#include <cstdint>
106102
#include <type_traits>
107103

108-
#include <boost/cstdint.hpp>
104+
namespace lsl {
105+
/*template<typename T>
106+
int fpclassify(T val) { return std::fpclassify(val); }*/
107+
namespace detail {
109108

110-
#include "portable_archive_exception.hpp"
109+
template <typename T> struct fp_traits_consts {};
110+
template <> struct fp_traits_consts<double> {
111+
using bits = uint64_t;
112+
static constexpr bits sign = (0x80000000ull) << 32, exponent = (0x7ff00000ll) << 32,
113+
significand = ((0x000fffffll) << 32) + (0xfffffffful);
114+
};
115+
template <> struct fp_traits_consts<float> {
116+
using bits = uint32_t;
117+
static constexpr bits sign = 0x80000000u, exponent = 0x7f800000, significand = 0x007fffff;
118+
static void get_bits(float src, bits &dst) { std::memcpy(&dst, &src, sizeof(src)); }
119+
static void set_bits(float &dst, bits src) { std::memcpy(&dst, &src, sizeof(src)); }
120+
};
121+
122+
template <typename T> struct fp_traits {
123+
using type = fp_traits_consts<T>;
124+
static void get_bits(double src, typename type::bits &dst) {
125+
std::memcpy(&dst, &src, sizeof(src));
126+
}
127+
static void set_bits(double &dst, typename type::bits src) {
128+
std::memcpy(&dst, &src, sizeof(src));
129+
}
130+
};
131+
132+
} // namespace detail
133+
} // namespace lsl
134+
135+
namespace fp = lslboost::math;
136+
// namespace alias endian
137+
namespace endian = lslboost::endian;
111138

112139
// hint from Johan Rade: on VMS there is still support for
113140
// the VAX floating point format and this macro detects it

src/portable_archive/portable_oarchive.hpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#pragma once
22

3-
#include <ostream>
43
#include "portable_archive_includes.hpp"
4+
#include <cstring>
5+
#include <ostream>
56

67
#ifdef SLIMARCHIVE
78
#include "slimarchive.hpp"
@@ -10,29 +11,6 @@
1011
#include <boost/archive/basic_binary_oarchive.hpp>
1112
#endif
1213

13-
#include <cstring>
14-
15-
template <typename T> struct FPTraits {};
16-
template <> struct FPTraits<double> {
17-
using bits = uint64_t;
18-
static constexpr bits sign = (0x80000000ull) << 32, exponent = (0x7ff00000ll) << 32,
19-
significand = ((0x000fffffll) << 32) + (0xfffffffful);
20-
static bits get_bits(double f) {
21-
bits b;
22-
std::memcpy(&b, &f, sizeof(bits));
23-
return b;
24-
}
25-
};
26-
template <> struct FPTraits<float> {
27-
using bits = uint32_t;
28-
static constexpr bits sign = 0x80000000u, exponent = 0x7f800000, significand = 0x007fffff;
29-
static bits get_bits(float f) {
30-
bits b;
31-
std::memcpy(&b, &f, sizeof(bits));
32-
return b;
33-
}
34-
};
35-
3614
namespace eos {
3715

3816
// IMPORTANT: We are fixing the lslboost serialization archive version
@@ -214,7 +192,7 @@ namespace eos {
214192
save(const T & t, dummy<3> = 0)
215193
{
216194
using traits = typename fp::detail::fp_traits<T>::type;
217-
using newtraits = FPTraits<T>;
195+
using newtraits = typename lsl::detail::fp_traits<T>::type;
218196
static_assert(std::is_same<typename traits::bits, typename newtraits::bits>::value,
219197
"Wrong corresponding int type");
220198

0 commit comments

Comments
 (0)