1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,380 @@ |
1 |
+// boost/endian/buffers.hpp ----------------------------------------------------------// |
|
2 |
+ |
|
3 |
+// (C) Copyright Darin Adler 2000 |
|
4 |
+// (C) Copyright Beman Dawes 2006, 2009, 2014 |
|
5 |
+// (C) Copyright Peter Dimov 2019 |
|
6 |
+ |
|
7 |
+// Distributed under the Boost Software License, Version 1.0. |
|
8 |
+// See http://www.boost.org/LICENSE_1_0.txt |
|
9 |
+ |
|
10 |
+// See library home page at http://www.boost.org/libs/endian |
|
11 |
+ |
|
12 |
+//--------------------------------------------------------------------------------------// |
|
13 |
+ |
|
14 |
+// Original design developed by Darin Adler based on classes developed by Mark |
|
15 |
+// Borgerding. Four original class templates were combined into a single endian |
|
16 |
+// class template by Beman Dawes, who also added the unrolled_byte_loops sign |
|
17 |
+// partial specialization to correctly extend the sign when cover integer size |
|
18 |
+// differs from endian representation size. |
|
19 |
+ |
|
20 |
+// TODO: When a compiler supporting constexpr becomes available, try possible uses. |
|
21 |
+ |
|
22 |
+#ifndef BOOST_ENDIAN_BUFFERS_HPP |
|
23 |
+#define BOOST_ENDIAN_BUFFERS_HPP |
|
24 |
+ |
|
25 |
+#if defined(_MSC_VER) |
|
26 |
+# pragma warning(push) |
|
27 |
+# pragma warning(disable: 4127) // conditional expression is constant |
|
28 |
+#endif |
|
29 |
+ |
|
30 |
+#include <boost/endian/detail/endian_store.hpp> |
|
31 |
+#include <boost/endian/detail/endian_load.hpp> |
|
32 |
+#include <boost/core/scoped_enum.hpp> |
|
33 |
+#include <boost/static_assert.hpp> |
|
34 |
+#include <boost/cstdint.hpp> |
|
35 |
+#include <boost/config.hpp> |
|
36 |
+#include <boost/config/workaround.hpp> |
|
37 |
+#include <iosfwd> |
|
38 |
+#include <climits> |
|
39 |
+#include <cstring> |
|
40 |
+ |
|
41 |
+#if defined(BOOST_BORLANDC) || defined(BOOST_CODEGEARC) |
|
42 |
+# pragma pack(push, 1) |
|
43 |
+#endif |
|
44 |
+ |
|
45 |
+# if CHAR_BIT != 8 |
|
46 |
+# error Platforms with CHAR_BIT != 8 are not supported |
|
47 |
+# endif |
|
48 |
+ |
|
49 |
+# ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS |
|
50 |
+# define BOOST_ENDIAN_DEFAULT_CONSTRUCT {} // C++03 |
|
51 |
+# else |
|
52 |
+# define BOOST_ENDIAN_DEFAULT_CONSTRUCT = default; // C++0x |
|
53 |
+# endif |
|
54 |
+ |
|
55 |
+// g++ pre-4.6 does not support unrestricted unions, but we have no Config macro for that |
|
56 |
+# if (defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || BOOST_WORKAROUND(BOOST_GCC, < 40600)) && defined(BOOST_ENDIAN_FORCE_PODNESS) |
|
57 |
+# define BOOST_ENDIAN_NO_CTORS |
|
58 |
+# endif |
|
59 |
+ |
|
60 |
+//---------------------------------- synopsis ----------------------------------------// |
|
61 |
+ |
|
62 |
+namespace boost |
|
63 |
+{ |
|
64 |
+namespace endian |
|
65 |
+{ |
|
66 |
+ |
|
67 |
+ BOOST_SCOPED_ENUM_START(align) |
|
68 |
+ {no, yes |
|
69 |
+# ifdef BOOST_ENDIAN_DEPRECATED_NAMES |
|
70 |
+ , unaligned = no, aligned = yes |
|
71 |
+# endif |
|
72 |
+ }; BOOST_SCOPED_ENUM_END |
|
73 |
+ |
|
74 |
+ template <BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits, |
|
75 |
+ BOOST_SCOPED_ENUM(align) A = align::no> |
|
76 |
+ class endian_buffer; |
|
77 |
+ |
|
78 |
+ // aligned big endian signed integer buffers |
|
79 |
+ typedef endian_buffer<order::big, int8_t, 8, align::yes> big_int8_buf_at; |
|
80 |
+ typedef endian_buffer<order::big, int16_t, 16, align::yes> big_int16_buf_at; |
|
81 |
+ typedef endian_buffer<order::big, int32_t, 32, align::yes> big_int32_buf_at; |
|
82 |
+ typedef endian_buffer<order::big, int64_t, 64, align::yes> big_int64_buf_at; |
|
83 |
+ |
|
84 |
+ // aligned big endian unsigned integer buffers |
|
85 |
+ typedef endian_buffer<order::big, uint8_t, 8, align::yes> big_uint8_buf_at; |
|
86 |
+ typedef endian_buffer<order::big, uint16_t, 16, align::yes> big_uint16_buf_at; |
|
87 |
+ typedef endian_buffer<order::big, uint32_t, 32, align::yes> big_uint32_buf_at; |
|
88 |
+ typedef endian_buffer<order::big, uint64_t, 64, align::yes> big_uint64_buf_at; |
|
89 |
+ |
|
90 |
+ // aligned little endian signed integer buffers |
|
91 |
+ typedef endian_buffer<order::little, int8_t, 8, align::yes> little_int8_buf_at; |
|
92 |
+ typedef endian_buffer<order::little, int16_t, 16, align::yes> little_int16_buf_at; |
|
93 |
+ typedef endian_buffer<order::little, int32_t, 32, align::yes> little_int32_buf_at; |
|
94 |
+ typedef endian_buffer<order::little, int64_t, 64, align::yes> little_int64_buf_at; |
|
95 |
+ |
|
96 |
+ // aligned little endian unsigned integer buffers |
|
97 |
+ typedef endian_buffer<order::little, uint8_t, 8, align::yes> little_uint8_buf_at; |
|
98 |
+ typedef endian_buffer<order::little, uint16_t, 16, align::yes> little_uint16_buf_at; |
|
99 |
+ typedef endian_buffer<order::little, uint32_t, 32, align::yes> little_uint32_buf_at; |
|
100 |
+ typedef endian_buffer<order::little, uint64_t, 64, align::yes> little_uint64_buf_at; |
|
101 |
+ |
|
102 |
+ // aligned floating point buffers |
|
103 |
+ typedef endian_buffer<order::big, float, 32, align::yes> big_float32_buf_at; |
|
104 |
+ typedef endian_buffer<order::big, double, 64, align::yes> big_float64_buf_at; |
|
105 |
+ typedef endian_buffer<order::little, float, 32, align::yes> little_float32_buf_at; |
|
106 |
+ typedef endian_buffer<order::little, double, 64, align::yes> little_float64_buf_at; |
|
107 |
+ |
|
108 |
+ // aligned native endian typedefs are not provided because |
|
109 |
+ // <cstdint> types are superior for this use case |
|
110 |
+ |
|
111 |
+ // unaligned big endian signed integer buffers |
|
112 |
+ typedef endian_buffer<order::big, int_least8_t, 8> big_int8_buf_t; |
|
113 |
+ typedef endian_buffer<order::big, int_least16_t, 16> big_int16_buf_t; |
|
114 |
+ typedef endian_buffer<order::big, int_least32_t, 24> big_int24_buf_t; |
|
115 |
+ typedef endian_buffer<order::big, int_least32_t, 32> big_int32_buf_t; |
|
116 |
+ typedef endian_buffer<order::big, int_least64_t, 40> big_int40_buf_t; |
|
117 |
+ typedef endian_buffer<order::big, int_least64_t, 48> big_int48_buf_t; |
|
118 |
+ typedef endian_buffer<order::big, int_least64_t, 56> big_int56_buf_t; |
|
119 |
+ typedef endian_buffer<order::big, int_least64_t, 64> big_int64_buf_t; |
|
120 |
+ |
|
121 |
+ // unaligned big endian unsigned integer buffers |
|
122 |
+ typedef endian_buffer<order::big, uint_least8_t, 8> big_uint8_buf_t; |
|
123 |
+ typedef endian_buffer<order::big, uint_least16_t, 16> big_uint16_buf_t; |
|
124 |
+ typedef endian_buffer<order::big, uint_least32_t, 24> big_uint24_buf_t; |
|
125 |
+ typedef endian_buffer<order::big, uint_least32_t, 32> big_uint32_buf_t; |
|
126 |
+ typedef endian_buffer<order::big, uint_least64_t, 40> big_uint40_buf_t; |
|
127 |
+ typedef endian_buffer<order::big, uint_least64_t, 48> big_uint48_buf_t; |
|
128 |
+ typedef endian_buffer<order::big, uint_least64_t, 56> big_uint56_buf_t; |
|
129 |
+ typedef endian_buffer<order::big, uint_least64_t, 64> big_uint64_buf_t; |
|
130 |
+ |
|
131 |
+ // unaligned little endian signed integer buffers |
|
132 |
+ typedef endian_buffer<order::little, int_least8_t, 8> little_int8_buf_t; |
|
133 |
+ typedef endian_buffer<order::little, int_least16_t, 16> little_int16_buf_t; |
|
134 |
+ typedef endian_buffer<order::little, int_least32_t, 24> little_int24_buf_t; |
|
135 |
+ typedef endian_buffer<order::little, int_least32_t, 32> little_int32_buf_t; |
|
136 |
+ typedef endian_buffer<order::little, int_least64_t, 40> little_int40_buf_t; |
|
137 |
+ typedef endian_buffer<order::little, int_least64_t, 48> little_int48_buf_t; |
|
138 |
+ typedef endian_buffer<order::little, int_least64_t, 56> little_int56_buf_t; |
|
139 |
+ typedef endian_buffer<order::little, int_least64_t, 64> little_int64_buf_t; |
|
140 |
+ |
|
141 |
+ // unaligned little endian unsigned integer buffers |
|
142 |
+ typedef endian_buffer<order::little, uint_least8_t, 8> little_uint8_buf_t; |
|
143 |
+ typedef endian_buffer<order::little, uint_least16_t, 16> little_uint16_buf_t; |
|
144 |
+ typedef endian_buffer<order::little, uint_least32_t, 24> little_uint24_buf_t; |
|
145 |
+ typedef endian_buffer<order::little, uint_least32_t, 32> little_uint32_buf_t; |
|
146 |
+ typedef endian_buffer<order::little, uint_least64_t, 40> little_uint40_buf_t; |
|
147 |
+ typedef endian_buffer<order::little, uint_least64_t, 48> little_uint48_buf_t; |
|
148 |
+ typedef endian_buffer<order::little, uint_least64_t, 56> little_uint56_buf_t; |
|
149 |
+ typedef endian_buffer<order::little, uint_least64_t, 64> little_uint64_buf_t; |
|
150 |
+ |
|
151 |
+ // unaligned native endian signed integer buffers |
|
152 |
+ typedef endian_buffer<order::native, int_least8_t, 8> native_int8_buf_t; |
|
153 |
+ typedef endian_buffer<order::native, int_least16_t, 16> native_int16_buf_t; |
|
154 |
+ typedef endian_buffer<order::native, int_least32_t, 24> native_int24_buf_t; |
|
155 |
+ typedef endian_buffer<order::native, int_least32_t, 32> native_int32_buf_t; |
|
156 |
+ typedef endian_buffer<order::native, int_least64_t, 40> native_int40_buf_t; |
|
157 |
+ typedef endian_buffer<order::native, int_least64_t, 48> native_int48_buf_t; |
|
158 |
+ typedef endian_buffer<order::native, int_least64_t, 56> native_int56_buf_t; |
|
159 |
+ typedef endian_buffer<order::native, int_least64_t, 64> native_int64_buf_t; |
|
160 |
+ |
|
161 |
+ // unaligned native endian unsigned integer buffers |
|
162 |
+ typedef endian_buffer<order::native, uint_least8_t, 8> native_uint8_buf_t; |
|
163 |
+ typedef endian_buffer<order::native, uint_least16_t, 16> native_uint16_buf_t; |
|
164 |
+ typedef endian_buffer<order::native, uint_least32_t, 24> native_uint24_buf_t; |
|
165 |
+ typedef endian_buffer<order::native, uint_least32_t, 32> native_uint32_buf_t; |
|
166 |
+ typedef endian_buffer<order::native, uint_least64_t, 40> native_uint40_buf_t; |
|
167 |
+ typedef endian_buffer<order::native, uint_least64_t, 48> native_uint48_buf_t; |
|
168 |
+ typedef endian_buffer<order::native, uint_least64_t, 56> native_uint56_buf_t; |
|
169 |
+ typedef endian_buffer<order::native, uint_least64_t, 64> native_uint64_buf_t; |
|
170 |
+ |
|
171 |
+ // unaligned floating point buffers |
|
172 |
+ typedef endian_buffer<order::big, float, 32, align::no> big_float32_buf_t; |
|
173 |
+ typedef endian_buffer<order::big, double, 64, align::no> big_float64_buf_t; |
|
174 |
+ typedef endian_buffer<order::little, float, 32, align::no> little_float32_buf_t; |
|
175 |
+ typedef endian_buffer<order::little, double, 64, align::no> little_float64_buf_t; |
|
176 |
+ typedef endian_buffer<order::native, float, 32, align::no> native_float32_buf_t; |
|
177 |
+ typedef endian_buffer<order::native, double, 64, align::no> native_float64_buf_t; |
|
178 |
+ |
|
179 |
+ // Stream inserter |
|
180 |
+ template <class charT, class traits, BOOST_SCOPED_ENUM(order) Order, class T, |
|
181 |
+ std::size_t n_bits, BOOST_SCOPED_ENUM(align) A> |
|
182 |
+ std::basic_ostream<charT, traits>& |
|
183 |
+ operator<<(std::basic_ostream<charT, traits>& os, |
|
184 |
+ const endian_buffer<Order, T, n_bits, A>& x) |
|
185 |
+ { |
|
186 |
+ return os << x.value(); |
|
187 |
+ } |
|
188 |
+ |
|
189 |
+ // Stream extractor |
|
190 |
+ template <class charT, class traits, BOOST_SCOPED_ENUM(order) Order, class T, |
|
191 |
+ std::size_t n_bits, BOOST_SCOPED_ENUM(align) A> |
|
192 |
+ std::basic_istream<charT, traits>& |
|
193 |
+ operator>>(std::basic_istream<charT, traits>& is, |
|
194 |
+ endian_buffer<Order, T, n_bits, A>& x) |
|
195 |
+ { |
|
196 |
+ T i; |
|
197 |
+ if (is >> i) |
|
198 |
+ x = i; |
|
199 |
+ return is; |
|
200 |
+ } |
|
201 |
+ |
|
202 |
+//---------------------------------- end synopsis ------------------------------------// |
|
203 |
+ |
|
204 |
+// endian_buffer class template specializations --------------------------------------// |
|
205 |
+ |
|
206 |
+// Specializations that represent unaligned bytes. |
|
207 |
+// Taking an integer type as a parameter provides a nice way to pass both |
|
208 |
+// the size and signedness of the desired integer and get the appropriate |
|
209 |
+// corresponding integer type for the interface. |
|
210 |
+ |
|
211 |
+// Q: Should endian_buffer supply "value_type operator value_type() const noexcept"? |
|
212 |
+// A: No. The rationale for endian_buffers is to prevent high-cost hidden |
|
213 |
+// conversions. If an implicit conversion operator is supplied, hidden conversions |
|
214 |
+// can occur. |
|
215 |
+ |
|
216 |
+// unaligned endian_buffer specialization |
|
217 |
+ |
|
218 |
+template< BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits > |
|
219 |
+class endian_buffer<Order, T, n_bits, align::no> |
|
220 |
+{ |
|
221 |
+#ifdef BOOST_ENDIAN_NO_CTORS |
|
222 |
+public: |
|
223 |
+#endif |
|
224 |
+ |
|
225 |
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
226 |
+ |
|
227 |
+ unsigned char value_[ n_bits / 8 ]; |
|
228 |
+ |
|
229 |
+public: |
|
230 |
+ |
|
231 |
+ typedef T value_type; |
|
232 |
+ |
|
233 |
+#ifndef BOOST_ENDIAN_NO_CTORS |
|
234 |
+ |
|
235 |
+ endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
236 |
+ |
|
237 |
+ explicit endian_buffer( T val ) BOOST_NOEXCEPT |
|
238 |
+ { |
|
239 |
+ boost::endian::endian_store<T, n_bits / 8, Order>( value_, val ); |
|
240 |
+ } |
|
241 |
+ |
|
242 |
+#endif |
|
243 |
+ |
|
244 |
+ endian_buffer& operator=( T val ) BOOST_NOEXCEPT |
|
245 |
+ { |
|
246 |
+ boost::endian::endian_store<T, n_bits / 8, Order>( value_, val ); |
|
247 |
+ return *this; |
|
248 |
+ } |
|
249 |
+ |
|
250 |
+ value_type value() const BOOST_NOEXCEPT |
|
251 |
+ { |
|
252 |
+ return boost::endian::endian_load<T, n_bits / 8, Order>( value_ ); |
|
253 |
+ } |
|
254 |
+ |
|
255 |
+ unsigned char const * data() const BOOST_NOEXCEPT |
|
256 |
+ { |
|
257 |
+ return value_; |
|
258 |
+ } |
|
259 |
+ |
|
260 |
+ unsigned char * data() BOOST_NOEXCEPT |
|
261 |
+ { |
|
262 |
+ return value_; |
|
263 |
+ } |
|
264 |
+}; |
|
265 |
+ |
|
266 |
+// aligned specializations; only n_bits == 16/32/64 supported |
|
267 |
+ |
|
268 |
+// aligned endian_buffer specialization |
|
269 |
+ |
|
270 |
+template< BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits > |
|
271 |
+class endian_buffer<Order, T, n_bits, align::yes> |
|
272 |
+{ |
|
273 |
+private: |
|
274 |
+ |
|
275 |
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
276 |
+ BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 ); |
|
277 |
+ |
|
278 |
+ union |
|
279 |
+ { |
|
280 |
+ unsigned char value_[ n_bits / 8 ]; |
|
281 |
+ T align_; |
|
282 |
+ }; |
|
283 |
+ |
|
284 |
+public: |
|
285 |
+ |
|
286 |
+ typedef T value_type; |
|
287 |
+ |
|
288 |
+#ifndef BOOST_ENDIAN_NO_CTORS |
|
289 |
+ |
|
290 |
+ endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
291 |
+ |
|
292 |
+ explicit endian_buffer( T val ) BOOST_NOEXCEPT |
|
293 |
+ { |
|
294 |
+ boost::endian::endian_store<T, n_bits / 8, Order>( value_, val ); |
|
295 |
+ } |
|
296 |
+ |
|
297 |
+#endif |
|
298 |
+ |
|
299 |
+ endian_buffer& operator=( T val ) BOOST_NOEXCEPT |
|
300 |
+ { |
|
301 |
+ boost::endian::endian_store<T, n_bits / 8, Order>( value_, val ); |
|
302 |
+ return *this; |
|
303 |
+ } |
|
304 |
+ |
|
305 |
+ value_type value() const BOOST_NOEXCEPT |
|
306 |
+ { |
|
307 |
+ return boost::endian::endian_load<T, n_bits / 8, Order>( value_ ); |
|
308 |
+ } |
|
309 |
+ |
|
310 |
+ unsigned char const * data() const BOOST_NOEXCEPT |
|
311 |
+ { |
|
312 |
+ return value_; |
|
313 |
+ } |
|
314 |
+ |
|
315 |
+ unsigned char * data() BOOST_NOEXCEPT |
|
316 |
+ { |
|
317 |
+ return value_; |
|
318 |
+ } |
|
319 |
+}; |
|
320 |
+ |
|
321 |
+// aligned native endian_buffer specialization |
|
322 |
+ |
|
323 |
+template< class T, std::size_t n_bits > |
|
324 |
+class endian_buffer<order::native, T, n_bits, align::yes> |
|
325 |
+{ |
|
326 |
+private: |
|
327 |
+ |
|
328 |
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
329 |
+ BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 ); |
|
330 |
+ |
|
331 |
+ T value_; |
|
332 |
+ |
|
333 |
+public: |
|
334 |
+ |
|
335 |
+ typedef T value_type; |
|
336 |
+ |
|
337 |
+#ifndef BOOST_ENDIAN_NO_CTORS |
|
338 |
+ |
|
339 |
+ endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
340 |
+ |
|
341 |
+ explicit endian_buffer( T val ) BOOST_NOEXCEPT: value_( val ) |
|
342 |
+ { |
|
343 |
+ } |
|
344 |
+ |
|
345 |
+#endif |
|
346 |
+ |
|
347 |
+ endian_buffer& operator=( T val ) BOOST_NOEXCEPT |
|
348 |
+ { |
|
349 |
+ value_ = val; |
|
350 |
+ return *this; |
|
351 |
+ } |
|
352 |
+ |
|
353 |
+ value_type value() const BOOST_NOEXCEPT |
|
354 |
+ { |
|
355 |
+ return value_; |
|
356 |
+ } |
|
357 |
+ |
|
358 |
+ unsigned char const * data() const BOOST_NOEXCEPT |
|
359 |
+ { |
|
360 |
+ return reinterpret_cast< unsigned char const* >( &value_ ); |
|
361 |
+ } |
|
362 |
+ |
|
363 |
+ unsigned char * data() BOOST_NOEXCEPT |
|
364 |
+ { |
|
365 |
+ return reinterpret_cast< unsigned char* >( &value_ ); |
|
366 |
+ } |
|
367 |
+}; |
|
368 |
+ |
|
369 |
+} // namespace endian |
|
370 |
+} // namespace boost |
|
371 |
+ |
|
372 |
+#if defined(BOOST_BORLANDC) || defined(BOOST_CODEGEARC) |
|
373 |
+# pragma pack(pop) |
|
374 |
+#endif |
|
375 |
+ |
|
376 |
+#if defined(_MSC_VER) |
|
377 |
+# pragma warning(pop) |
|
378 |
+#endif |
|
379 |
+ |
|
380 |
+#endif // BOOST_ENDIAN_BUFFERS_HPP |
From: Laurent <lg390@cam.ac.uk>
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/mzR@125180 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,515 +0,0 @@ |
1 |
-// boost/endian/buffers.hpp ----------------------------------------------------------// |
|
2 |
- |
|
3 |
-// (C) Copyright Darin Adler 2000 |
|
4 |
-// (C) Copyright Beman Dawes 2006, 2009, 2014 |
|
5 |
- |
|
6 |
-// Distributed under the Boost Software License, Version 1.0. |
|
7 |
-// See http://www.boost.org/LICENSE_1_0.txt |
|
8 |
- |
|
9 |
-// See library home page at http://www.boost.org/libs/endian |
|
10 |
- |
|
11 |
-//--------------------------------------------------------------------------------------// |
|
12 |
- |
|
13 |
-// Original design developed by Darin Adler based on classes developed by Mark |
|
14 |
-// Borgerding. Four original class templates were combined into a single endian |
|
15 |
-// class template by Beman Dawes, who also added the unrolled_byte_loops sign |
|
16 |
-// partial specialization to correctly extend the sign when cover integer size |
|
17 |
-// differs from endian representation size. |
|
18 |
- |
|
19 |
-// TODO: When a compiler supporting constexpr becomes available, try possible uses. |
|
20 |
- |
|
21 |
-#ifndef BOOST_ENDIAN_BUFFERS_HPP |
|
22 |
-#define BOOST_ENDIAN_BUFFERS_HPP |
|
23 |
- |
|
24 |
-#if defined(_MSC_VER) |
|
25 |
-# pragma warning(push) |
|
26 |
-# pragma warning(disable:4365) // conversion ... signed/unsigned mismatch |
|
27 |
-#endif |
|
28 |
- |
|
29 |
-#ifdef BOOST_ENDIAN_LOG |
|
30 |
-# include <iostream> |
|
31 |
-#endif |
|
32 |
- |
|
33 |
-#if defined(__BORLANDC__) || defined( __CODEGEARC__) |
|
34 |
-# pragma pack(push, 1) |
|
35 |
-#endif |
|
36 |
- |
|
37 |
-#include <boost/config.hpp> |
|
38 |
-#include <boost/predef/detail/endian_compat.h> |
|
39 |
-#include <boost/endian/conversion.hpp> |
|
40 |
-#include <boost/type_traits/is_signed.hpp> |
|
41 |
-#include <boost/cstdint.hpp> |
|
42 |
-#include <boost/static_assert.hpp> |
|
43 |
-#include <boost/core/scoped_enum.hpp> |
|
44 |
-#include <iosfwd> |
|
45 |
-#include <climits> |
|
46 |
- |
|
47 |
-# if CHAR_BIT != 8 |
|
48 |
-# error Platforms with CHAR_BIT != 8 are not supported |
|
49 |
-# endif |
|
50 |
- |
|
51 |
-# ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS |
|
52 |
-# define BOOST_ENDIAN_DEFAULT_CONSTRUCT {} // C++03 |
|
53 |
-# else |
|
54 |
-# define BOOST_ENDIAN_DEFAULT_CONSTRUCT = default; // C++0x |
|
55 |
-# endif |
|
56 |
- |
|
57 |
-# if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && defined(BOOST_ENDIAN_FORCE_PODNESS) |
|
58 |
-# define BOOST_ENDIAN_NO_CTORS |
|
59 |
-# endif |
|
60 |
- |
|
61 |
-//---------------------------------- synopsis ----------------------------------------// |
|
62 |
- |
|
63 |
-namespace boost |
|
64 |
-{ |
|
65 |
-namespace endian |
|
66 |
-{ |
|
67 |
- |
|
68 |
- BOOST_SCOPED_ENUM_START(align) |
|
69 |
- {no, yes |
|
70 |
-# ifdef BOOST_ENDIAN_DEPRECATED_NAMES |
|
71 |
- , unaligned = no, aligned = yes |
|
72 |
-# endif |
|
73 |
- }; BOOST_SCOPED_ENUM_END |
|
74 |
- |
|
75 |
- template <BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits, |
|
76 |
- BOOST_SCOPED_ENUM(align) A = align::no> |
|
77 |
- class endian_buffer; |
|
78 |
- |
|
79 |
- // aligned big endian signed integer buffers |
|
80 |
- typedef endian_buffer<order::big, int8_t, 8, align::yes> big_int8_buf_at; |
|
81 |
- typedef endian_buffer<order::big, int16_t, 16, align::yes> big_int16_buf_at; |
|
82 |
- typedef endian_buffer<order::big, int32_t, 32, align::yes> big_int32_buf_at; |
|
83 |
- typedef endian_buffer<order::big, int64_t, 64, align::yes> big_int64_buf_at; |
|
84 |
- |
|
85 |
- // aligned big endian unsigned integer buffers |
|
86 |
- typedef endian_buffer<order::big, uint8_t, 8, align::yes> big_uint8_buf_at; |
|
87 |
- typedef endian_buffer<order::big, uint16_t, 16, align::yes> big_uint16_buf_at; |
|
88 |
- typedef endian_buffer<order::big, uint32_t, 32, align::yes> big_uint32_buf_at; |
|
89 |
- typedef endian_buffer<order::big, uint64_t, 64, align::yes> big_uint64_buf_at; |
|
90 |
- |
|
91 |
- // aligned little endian signed integer buffers |
|
92 |
- typedef endian_buffer<order::little, int8_t, 8, align::yes> little_int8_buf_at; |
|
93 |
- typedef endian_buffer<order::little, int16_t, 16, align::yes> little_int16_buf_at; |
|
94 |
- typedef endian_buffer<order::little, int32_t, 32, align::yes> little_int32_buf_at; |
|
95 |
- typedef endian_buffer<order::little, int64_t, 64, align::yes> little_int64_buf_at; |
|
96 |
- |
|
97 |
- // aligned little endian unsigned integer buffers |
|
98 |
- typedef endian_buffer<order::little, uint8_t, 8, align::yes> little_uint8_buf_at; |
|
99 |
- typedef endian_buffer<order::little, uint16_t, 16, align::yes> little_uint16_buf_at; |
|
100 |
- typedef endian_buffer<order::little, uint32_t, 32, align::yes> little_uint32_buf_at; |
|
101 |
- typedef endian_buffer<order::little, uint64_t, 64, align::yes> little_uint64_buf_at; |
|
102 |
- |
|
103 |
- // aligned native endian typedefs are not provided because |
|
104 |
- // <cstdint> types are superior for this use case |
|
105 |
- |
|
106 |
- // unaligned big endian signed integer buffers |
|
107 |
- typedef endian_buffer<order::big, int_least8_t, 8> big_int8_buf_t; |
|
108 |
- typedef endian_buffer<order::big, int_least16_t, 16> big_int16_buf_t; |
|
109 |
- typedef endian_buffer<order::big, int_least32_t, 24> big_int24_buf_t; |
|
110 |
- typedef endian_buffer<order::big, int_least32_t, 32> big_int32_buf_t; |
|
111 |
- typedef endian_buffer<order::big, int_least64_t, 40> big_int40_buf_t; |
|
112 |
- typedef endian_buffer<order::big, int_least64_t, 48> big_int48_buf_t; |
|
113 |
- typedef endian_buffer<order::big, int_least64_t, 56> big_int56_buf_t; |
|
114 |
- typedef endian_buffer<order::big, int_least64_t, 64> big_int64_buf_t; |
|
115 |
- |
|
116 |
- // unaligned big endian unsigned integer buffers |
|
117 |
- typedef endian_buffer<order::big, uint_least8_t, 8> big_uint8_buf_t; |
|
118 |
- typedef endian_buffer<order::big, uint_least16_t, 16> big_uint16_buf_t; |
|
119 |
- typedef endian_buffer<order::big, uint_least32_t, 24> big_uint24_buf_t; |
|
120 |
- typedef endian_buffer<order::big, uint_least32_t, 32> big_uint32_buf_t; |
|
121 |
- typedef endian_buffer<order::big, uint_least64_t, 40> big_uint40_buf_t; |
|
122 |
- typedef endian_buffer<order::big, uint_least64_t, 48> big_uint48_buf_t; |
|
123 |
- typedef endian_buffer<order::big, uint_least64_t, 56> big_uint56_buf_t; |
|
124 |
- typedef endian_buffer<order::big, uint_least64_t, 64> big_uint64_buf_t; |
|
125 |
- |
|
126 |
- // unaligned little endian signed integer buffers |
|
127 |
- typedef endian_buffer<order::little, int_least8_t, 8> little_int8_buf_t; |
|
128 |
- typedef endian_buffer<order::little, int_least16_t, 16> little_int16_buf_t; |
|
129 |
- typedef endian_buffer<order::little, int_least32_t, 24> little_int24_buf_t; |
|
130 |
- typedef endian_buffer<order::little, int_least32_t, 32> little_int32_buf_t; |
|
131 |
- typedef endian_buffer<order::little, int_least64_t, 40> little_int40_buf_t; |
|
132 |
- typedef endian_buffer<order::little, int_least64_t, 48> little_int48_buf_t; |
|
133 |
- typedef endian_buffer<order::little, int_least64_t, 56> little_int56_buf_t; |
|
134 |
- typedef endian_buffer<order::little, int_least64_t, 64> little_int64_buf_t; |
|
135 |
- |
|
136 |
- // unaligned little endian unsigned integer buffers |
|
137 |
- typedef endian_buffer<order::little, uint_least8_t, 8> little_uint8_buf_t; |
|
138 |
- typedef endian_buffer<order::little, uint_least16_t, 16> little_uint16_buf_t; |
|
139 |
- typedef endian_buffer<order::little, uint_least32_t, 24> little_uint24_buf_t; |
|
140 |
- typedef endian_buffer<order::little, uint_least32_t, 32> little_uint32_buf_t; |
|
141 |
- typedef endian_buffer<order::little, uint_least64_t, 40> little_uint40_buf_t; |
|
142 |
- typedef endian_buffer<order::little, uint_least64_t, 48> little_uint48_buf_t; |
|
143 |
- typedef endian_buffer<order::little, uint_least64_t, 56> little_uint56_buf_t; |
|
144 |
- typedef endian_buffer<order::little, uint_least64_t, 64> little_uint64_buf_t; |
|
145 |
- |
|
146 |
-# ifdef BOOST_BIG_ENDIAN |
|
147 |
- // unaligned native endian signed integer buffers |
|
148 |
- typedef big_int8_buf_t native_int8_buf_t; |
|
149 |
- typedef big_int16_buf_t native_int16_buf_t; |
|
150 |
- typedef big_int24_buf_t native_int24_buf_t; |
|
151 |
- typedef big_int32_buf_t native_int32_buf_t; |
|
152 |
- typedef big_int40_buf_t native_int40_buf_t; |
|
153 |
- typedef big_int48_buf_t native_int48_buf_t; |
|
154 |
- typedef big_int56_buf_t native_int56_buf_t; |
|
155 |
- typedef big_int64_buf_t native_int64_buf_t; |
|
156 |
- |
|
157 |
- // unaligned native endian unsigned integer buffers |
|
158 |
- typedef big_uint8_buf_t native_uint8_buf_t; |
|
159 |
- typedef big_uint16_buf_t native_uint16_buf_t; |
|
160 |
- typedef big_uint24_buf_t native_uint24_buf_t; |
|
161 |
- typedef big_uint32_buf_t native_uint32_buf_t; |
|
162 |
- typedef big_uint40_buf_t native_uint40_buf_t; |
|
163 |
- typedef big_uint48_buf_t native_uint48_buf_t; |
|
164 |
- typedef big_uint56_buf_t native_uint56_buf_t; |
|
165 |
- typedef big_uint64_buf_t native_uint64_buf_t; |
|
166 |
-# else |
|
167 |
- // unaligned native endian signed integer buffers |
|
168 |
- typedef little_int8_buf_t native_int8_buf_t; |
|
169 |
- typedef little_int16_buf_t native_int16_buf_t; |
|
170 |
- typedef little_int24_buf_t native_int24_buf_t; |
|
171 |
- typedef little_int32_buf_t native_int32_buf_t; |
|
172 |
- typedef little_int40_buf_t native_int40_buf_t; |
|
173 |
- typedef little_int48_buf_t native_int48_buf_t; |
|
174 |
- typedef little_int56_buf_t native_int56_buf_t; |
|
175 |
- typedef little_int64_buf_t native_int64_buf_t; |
|
176 |
- |
|
177 |
- // unaligned native endian unsigned integer buffers |
|
178 |
- typedef little_uint8_buf_t native_uint8_buf_t; |
|
179 |
- typedef little_uint16_buf_t native_uint16_buf_t; |
|
180 |
- typedef little_uint24_buf_t native_uint24_buf_t; |
|
181 |
- typedef little_uint32_buf_t native_uint32_buf_t; |
|
182 |
- typedef little_uint40_buf_t native_uint40_buf_t; |
|
183 |
- typedef little_uint48_buf_t native_uint48_buf_t; |
|
184 |
- typedef little_uint56_buf_t native_uint56_buf_t; |
|
185 |
- typedef little_uint64_buf_t native_uint64_buf_t; |
|
186 |
-# endif |
|
187 |
- |
|
188 |
- // Stream inserter |
|
189 |
- template <class charT, class traits, BOOST_SCOPED_ENUM(order) Order, class T, |
|
190 |
- std::size_t n_bits, BOOST_SCOPED_ENUM(align) A> |
|
191 |
- std::basic_ostream<charT, traits>& |
|
192 |
- operator<<(std::basic_ostream<charT, traits>& os, |
|
193 |
- const endian_buffer<Order, T, n_bits, A>& x) |
|
194 |
- { |
|
195 |
- return os << x.value(); |
|
196 |
- } |
|
197 |
- |
|
198 |
- // Stream extractor |
|
199 |
- template <class charT, class traits, BOOST_SCOPED_ENUM(order) Order, class T, |
|
200 |
- std::size_t n_bits, BOOST_SCOPED_ENUM(align) A> |
|
201 |
- std::basic_istream<charT, traits>& |
|
202 |
- operator>>(std::basic_istream<charT, traits>& is, |
|
203 |
- endian_buffer<Order, T, n_bits, A>& x) |
|
204 |
- { |
|
205 |
- T i; |
|
206 |
- if (is >> i) |
|
207 |
- x = i; |
|
208 |
- return is; |
|
209 |
- } |
|
210 |
- |
|
211 |
-//---------------------------------- end synopsis ------------------------------------// |
|
212 |
- |
|
213 |
- namespace detail |
|
214 |
- { |
|
215 |
- |
|
216 |
- // Unrolled loops for loading and storing streams of bytes. |
|
217 |
- |
|
218 |
- template <typename T, std::size_t n_bytes, |
|
219 |
- bool sign=boost::is_signed<T>::value > |
|
220 |
- struct unrolled_byte_loops |
|
221 |
- { |
|
222 |
- typedef unrolled_byte_loops<T, n_bytes - 1, sign> next; |
|
223 |
- |
|
224 |
- static T load_big(const unsigned char* bytes) BOOST_NOEXCEPT |
|
225 |
- { return static_cast<T>(*(bytes - 1) | (next::load_big(bytes - 1) << 8)); } |
|
226 |
- static T load_little(const unsigned char* bytes) BOOST_NOEXCEPT |
|
227 |
- { return static_cast<T>(*bytes | (next::load_little(bytes + 1) << 8)); } |
|
228 |
- |
|
229 |
- static void store_big(char* bytes, T value) BOOST_NOEXCEPT |
|
230 |
- { |
|
231 |
- *(bytes - 1) = static_cast<char>(value); |
|
232 |
- next::store_big(bytes - 1, static_cast<T>(value >> 8)); |
|
233 |
- } |
|
234 |
- static void store_little(char* bytes, T value) BOOST_NOEXCEPT |
|
235 |
- { |
|
236 |
- *bytes = static_cast<char>(value); |
|
237 |
- next::store_little(bytes + 1, static_cast<T>(value >> 8)); |
|
238 |
- } |
|
239 |
- }; |
|
240 |
- |
|
241 |
- template <typename T> |
|
242 |
- struct unrolled_byte_loops<T, 1, false> |
|
243 |
- { |
|
244 |
- static T load_big(const unsigned char* bytes) BOOST_NOEXCEPT |
|
245 |
- { return *(bytes - 1); } |
|
246 |
- static T load_little(const unsigned char* bytes) BOOST_NOEXCEPT |
|
247 |
- { return *bytes; } |
|
248 |
- static void store_big(char* bytes, T value) BOOST_NOEXCEPT |
|
249 |
- { *(bytes - 1) = static_cast<char>(value); } |
|
250 |
- static void store_little(char* bytes, T value) BOOST_NOEXCEPT |
|
251 |
- { *bytes = static_cast<char>(value); } |
|
252 |
- |
|
253 |
- }; |
|
254 |
- |
|
255 |
- template <typename T> |
|
256 |
- struct unrolled_byte_loops<T, 1, true> |
|
257 |
- { |
|
258 |
- static T load_big(const unsigned char* bytes) BOOST_NOEXCEPT |
|
259 |
- { return *reinterpret_cast<const signed char*>(bytes - 1); } |
|
260 |
- static T load_little(const unsigned char* bytes) BOOST_NOEXCEPT |
|
261 |
- { return *reinterpret_cast<const signed char*>(bytes); } |
|
262 |
- static void store_big(char* bytes, T value) BOOST_NOEXCEPT |
|
263 |
- { *(bytes - 1) = static_cast<char>(value); } |
|
264 |
- static void store_little(char* bytes, T value) BOOST_NOEXCEPT |
|
265 |
- { *bytes = static_cast<char>(value); } |
|
266 |
- }; |
|
267 |
- |
|
268 |
- template <typename T, std::size_t n_bytes> |
|
269 |
- inline |
|
270 |
- T load_big_endian(const void* bytes) BOOST_NOEXCEPT |
|
271 |
- { |
|
272 |
- return unrolled_byte_loops<T, n_bytes>::load_big |
|
273 |
- (static_cast<const unsigned char*>(bytes) + n_bytes); |
|
274 |
- } |
|
275 |
- |
|
276 |
- template <typename T, std::size_t n_bytes> |
|
277 |
- inline |
|
278 |
- T load_little_endian(const void* bytes) BOOST_NOEXCEPT |
|
279 |
- { |
|
280 |
-# if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) |
|
281 |
- // On x86 (which is little endian), unaligned loads are permitted |
|
282 |
- if (sizeof(T) == n_bytes) // GCC 4.9, VC++ 14.0, and probably others, elide this |
|
283 |
- // test and generate code only for the applicable return |
|
284 |
- // case since sizeof(T) and n_bytes are known at compile |
|
285 |
- // time. |
|
286 |
- { |
|
287 |
- return *reinterpret_cast<T const *>(bytes); |
|
288 |
- } |
|
289 |
-# endif |
|
290 |
- return unrolled_byte_loops<T, n_bytes>::load_little |
|
291 |
- (static_cast<const unsigned char*>(bytes)); |
|
292 |
- } |
|
293 |
- |
|
294 |
- template <typename T, std::size_t n_bytes> |
|
295 |
- inline |
|
296 |
- void store_big_endian(void* bytes, T value) BOOST_NOEXCEPT |
|
297 |
- { |
|
298 |
- unrolled_byte_loops<T, n_bytes>::store_big |
|
299 |
- (static_cast<char*>(bytes) + n_bytes, value); |
|
300 |
- } |
|
301 |
- |
|
302 |
- template <typename T, std::size_t n_bytes> |
|
303 |
- inline |
|
304 |
- void store_little_endian(void* bytes, T value) BOOST_NOEXCEPT |
|
305 |
- { |
|
306 |
-# if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) |
|
307 |
- // On x86 (which is little endian), unaligned stores are permitted |
|
308 |
- if (sizeof(T) == n_bytes) // GCC 4.9, VC++ 14.0, and probably others, elide this |
|
309 |
- // test and generate code only for the applicable return |
|
310 |
- // case since sizeof(T) and n_bytes are known at compile |
|
311 |
- // time. |
|
312 |
- { |
|
313 |
- *reinterpret_cast<T *>(bytes) = value; |
|
314 |
- return; |
|
315 |
- } |
|
316 |
-# endif |
|
317 |
- unrolled_byte_loops<T, n_bytes>::store_little |
|
318 |
- (static_cast<char*>(bytes), value); |
|
319 |
- } |
|
320 |
- |
|
321 |
- } // namespace detail |
|
322 |
- |
|
323 |
-# ifdef BOOST_ENDIAN_LOG |
|
324 |
- bool endian_log(true); |
|
325 |
-# endif |
|
326 |
- |
|
327 |
-// endian_buffer class template specializations --------------------------------------// |
|
328 |
- |
|
329 |
- // Specializations that represent unaligned bytes. |
|
330 |
- // Taking an integer type as a parameter provides a nice way to pass both |
|
331 |
- // the size and signedness of the desired integer and get the appropriate |
|
332 |
- // corresponding integer type for the interface. |
|
333 |
- |
|
334 |
- // Q: Should endian_buffer supply "value_type operator value_type() const noexcept"? |
|
335 |
- // A: No. The rationale for endian_buffers is to prevent high-cost hidden |
|
336 |
- // conversions. If an implicit conversion operator is supplied, hidden conversions |
|
337 |
- // can occur. |
|
338 |
- |
|
339 |
- // unaligned big endian_buffer specialization |
|
340 |
- template <typename T, std::size_t n_bits> |
|
341 |
- class endian_buffer< order::big, T, n_bits, align::no > |
|
342 |
- { |
|
343 |
- BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
344 |
- public: |
|
345 |
- typedef T value_type; |
|
346 |
-# ifndef BOOST_ENDIAN_NO_CTORS |
|
347 |
- endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
348 |
- explicit endian_buffer(T val) BOOST_NOEXCEPT |
|
349 |
- { |
|
350 |
-# ifdef BOOST_ENDIAN_LOG |
|
351 |
- if ( endian_log ) |
|
352 |
- std::cout << "big, unaligned, " |
|
353 |
- << n_bits << "-bits, construct(" << val << ")\n"; |
|
354 |
-# endif |
|
355 |
- detail::store_big_endian<T, n_bits/8>(m_value, val); |
|
356 |
- } |
|
357 |
-# endif |
|
358 |
- endian_buffer & operator=(T val) BOOST_NOEXCEPT |
|
359 |
- { |
|
360 |
-# ifdef BOOST_ENDIAN_LOG |
|
361 |
- if (endian_log) |
|
362 |
- std::cout << "big, unaligned, " << n_bits << "-bits, assign(" << val << ")\n"; |
|
363 |
-# endif |
|
364 |
- detail::store_big_endian<T, n_bits/8>(m_value, val); |
|
365 |
- return *this; |
|
366 |
- } |
|
367 |
- value_type value() const BOOST_NOEXCEPT |
|
368 |
- { |
|
369 |
-# ifdef BOOST_ENDIAN_LOG |
|
370 |
- if ( endian_log ) |
|
371 |
- std::cout << "big, unaligned, " << n_bits << "-bits, convert(" |
|
372 |
- << detail::load_big_endian<T, n_bits/8>(m_value) << ")\n"; |
|
373 |
-# endif |
|
374 |
- return detail::load_big_endian<T, n_bits/8>(m_value); |
|
375 |
- } |
|
376 |
- const char* data() const BOOST_NOEXCEPT { return m_value; } |
|
377 |
- protected: |
|
378 |
- char m_value[n_bits/8]; |
|
379 |
- }; |
|
380 |
- |
|
381 |
- // unaligned little endian_buffer specialization |
|
382 |
- template <typename T, std::size_t n_bits> |
|
383 |
- class endian_buffer< order::little, T, n_bits, align::no > |
|
384 |
- { |
|
385 |
- BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
386 |
- public: |
|
387 |
- typedef T value_type; |
|
388 |
-# ifndef BOOST_ENDIAN_NO_CTORS |
|
389 |
- endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
390 |
- explicit endian_buffer(T val) BOOST_NOEXCEPT |
|
391 |
- { |
|
392 |
-# ifdef BOOST_ENDIAN_LOG |
|
393 |
- if ( endian_log ) |
|
394 |
- std::cout << "little, unaligned, " << n_bits << "-bits, construct(" |
|
395 |
- << val << ")\n"; |
|
396 |
-# endif |
|
397 |
- detail::store_little_endian<T, n_bits/8>(m_value, val); |
|
398 |
- } |
|
399 |
-# endif |
|
400 |
- endian_buffer & operator=(T val) BOOST_NOEXCEPT |
|
401 |
- { detail::store_little_endian<T, n_bits/8>(m_value, val); return *this; } |
|
402 |
- value_type value() const BOOST_NOEXCEPT |
|
403 |
- { |
|
404 |
-# ifdef BOOST_ENDIAN_LOG |
|
405 |
- if ( endian_log ) |
|
406 |
- std::cout << "little, unaligned, " << n_bits << "-bits, convert(" |
|
407 |
- << detail::load_little_endian<T, n_bits/8>(m_value) << ")\n"; |
|
408 |
-# endif |
|
409 |
- return detail::load_little_endian<T, n_bits/8>(m_value); |
|
410 |
- } |
|
411 |
- const char* data() const BOOST_NOEXCEPT { return m_value; } |
|
412 |
- protected: |
|
413 |
- char m_value[n_bits/8]; |
|
414 |
- }; |
|
415 |
- |
|
416 |
- // align::yes specializations; only n_bits == 16/32/64 supported |
|
417 |
- |
|
418 |
- // aligned big endian_buffer specialization |
|
419 |
- template <typename T, std::size_t n_bits> |
|
420 |
- class endian_buffer<order::big, T, n_bits, align::yes> |
|
421 |
- { |
|
422 |
- BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
423 |
- BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 ); |
|
424 |
- public: |
|
425 |
- typedef T value_type; |
|
426 |
-# ifndef BOOST_ENDIAN_NO_CTORS |
|
427 |
- endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
428 |
- explicit endian_buffer(T val) BOOST_NOEXCEPT |
|
429 |
- { |
|
430 |
-# ifdef BOOST_ENDIAN_LOG |
|
431 |
- if ( endian_log ) |
|
432 |
- std::cout << "big, aligned, " << n_bits |
|
433 |
- << "-bits, construct(" << val << ")\n"; |
|
434 |
-# endif |
|
435 |
- m_value = ::boost::endian::native_to_big(val); |
|
436 |
- } |
|
437 |
- |
|
438 |
-# endif |
|
439 |
- endian_buffer& operator=(T val) BOOST_NOEXCEPT |
|
440 |
- { |
|
441 |
- m_value = ::boost::endian::native_to_big(val); |
|
442 |
- return *this; |
|
443 |
- } |
|
444 |
- //operator value_type() const BOOST_NOEXCEPT |
|
445 |
- //{ |
|
446 |
- // return ::boost::endian::big_to_native(m_value); |
|
447 |
- //} |
|
448 |
- value_type value() const BOOST_NOEXCEPT |
|
449 |
- { |
|
450 |
-# ifdef BOOST_ENDIAN_LOG |
|
451 |
- if ( endian_log ) |
|
452 |
- std::cout << "big, aligned, " << n_bits << "-bits, convert(" |
|
453 |
- << ::boost::endian::big_to_native(m_value) << ")\n"; |
|
454 |
-# endif |
|
455 |
- return ::boost::endian::big_to_native(m_value); |
|
456 |
- } |
|
457 |
- const char* data() const BOOST_NOEXCEPT |
|
458 |
- {return reinterpret_cast<const char*>(&m_value);} |
|
459 |
- protected: |
|
460 |
- T m_value; |
|
461 |
- }; |
|
462 |
- |
|
463 |
- // aligned little endian_buffer specialization |
|
464 |
- template <typename T, std::size_t n_bits> |
|
465 |
- class endian_buffer<order::little, T, n_bits, align::yes> |
|
466 |
- { |
|
467 |
- BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
468 |
- BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 ); |
|
469 |
- public: |
|
470 |
- typedef T value_type; |
|
471 |
-# ifndef BOOST_ENDIAN_NO_CTORS |
|
472 |
- endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
473 |
- explicit endian_buffer(T val) BOOST_NOEXCEPT |
|
474 |
- { |
|
475 |
-# ifdef BOOST_ENDIAN_LOG |
|
476 |
- if ( endian_log ) |
|
477 |
- std::cout << "little, aligned, " << n_bits |
|
478 |
- << "-bits, construct(" << val << ")\n"; |
|
479 |
-# endif |
|
480 |
- m_value = ::boost::endian::native_to_little(val); |
|
481 |
- } |
|
482 |
- |
|
483 |
-# endif |
|
484 |
- endian_buffer& operator=(T val) BOOST_NOEXCEPT |
|
485 |
- { |
|
486 |
- m_value = ::boost::endian::native_to_little(val); |
|
487 |
- return *this; |
|
488 |
- } |
|
489 |
- value_type value() const BOOST_NOEXCEPT |
|
490 |
- { |
|
491 |
-# ifdef BOOST_ENDIAN_LOG |
|
492 |
- if ( endian_log ) |
|
493 |
- std::cout << "little, aligned, " << n_bits << "-bits, convert(" |
|
494 |
- << ::boost::endian::little_to_native(m_value) << ")\n"; |
|
495 |
-# endif |
|
496 |
- return ::boost::endian::little_to_native(m_value); |
|
497 |
- } |
|
498 |
- const char* data() const BOOST_NOEXCEPT |
|
499 |
- {return reinterpret_cast<const char*>(&m_value);} |
|
500 |
- protected: |
|
501 |
- T m_value; |
|
502 |
- }; |
|
503 |
- |
|
504 |
-} // namespace endian |
|
505 |
-} // namespace boost |
|
506 |
- |
|
507 |
-#if defined(__BORLANDC__) || defined( __CODEGEARC__) |
|
508 |
-# pragma pack(pop) |
|
509 |
-#endif |
|
510 |
- |
|
511 |
-#if defined(_MSC_VER) |
|
512 |
-# pragma warning(pop) |
|
513 |
-#endif |
|
514 |
- |
|
515 |
-#endif // BOOST_ENDIAN_BUFFERS_HPP |
Commit id: 0b3d4d9bb71e3ca5891b777610fc8dec103a6d61
Bumped version after KK's updates
Commit id: 9e04409b64757a177893d56c0300904f31945cb1
modified: src/pwiz/data/common/BinaryIndexStream.cpp modified: src/win/i386/libpwiz.a modified: src/win/x64/libpwiz.a
Commit id: f16b04258dc20bf3315beac99708e11728cfc12b
update precompiled lib for windows
Commit id: 5d56197f1148378d92e89b2d0a167e18c4b7ab2e
Bump version, tame .Rbuildignore
Commit id: 432da5bd294c9b87f7761e15bc814c3785c21abf
Merge remote-tracking branch 'origin/boost_159'
Commit id: 92be978bf72d90c2222a19ddf365f6d1acc9f20d
upadte Makevars
Commit id: ae75037a780cead56c4d20bedf822c94fb413677
upgrade to boost 1.5.9
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/mzR@110126 bc3139a8-67e5-0310-9ffc-ced21a209358
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,515 @@ |
1 |
+// boost/endian/buffers.hpp ----------------------------------------------------------// |
|
2 |
+ |
|
3 |
+// (C) Copyright Darin Adler 2000 |
|
4 |
+// (C) Copyright Beman Dawes 2006, 2009, 2014 |
|
5 |
+ |
|
6 |
+// Distributed under the Boost Software License, Version 1.0. |
|
7 |
+// See http://www.boost.org/LICENSE_1_0.txt |
|
8 |
+ |
|
9 |
+// See library home page at http://www.boost.org/libs/endian |
|
10 |
+ |
|
11 |
+//--------------------------------------------------------------------------------------// |
|
12 |
+ |
|
13 |
+// Original design developed by Darin Adler based on classes developed by Mark |
|
14 |
+// Borgerding. Four original class templates were combined into a single endian |
|
15 |
+// class template by Beman Dawes, who also added the unrolled_byte_loops sign |
|
16 |
+// partial specialization to correctly extend the sign when cover integer size |
|
17 |
+// differs from endian representation size. |
|
18 |
+ |
|
19 |
+// TODO: When a compiler supporting constexpr becomes available, try possible uses. |
|
20 |
+ |
|
21 |
+#ifndef BOOST_ENDIAN_BUFFERS_HPP |
|
22 |
+#define BOOST_ENDIAN_BUFFERS_HPP |
|
23 |
+ |
|
24 |
+#if defined(_MSC_VER) |
|
25 |
+# pragma warning(push) |
|
26 |
+# pragma warning(disable:4365) // conversion ... signed/unsigned mismatch |
|
27 |
+#endif |
|
28 |
+ |
|
29 |
+#ifdef BOOST_ENDIAN_LOG |
|
30 |
+# include <iostream> |
|
31 |
+#endif |
|
32 |
+ |
|
33 |
+#if defined(__BORLANDC__) || defined( __CODEGEARC__) |
|
34 |
+# pragma pack(push, 1) |
|
35 |
+#endif |
|
36 |
+ |
|
37 |
+#include <boost/config.hpp> |
|
38 |
+#include <boost/predef/detail/endian_compat.h> |
|
39 |
+#include <boost/endian/conversion.hpp> |
|
40 |
+#include <boost/type_traits/is_signed.hpp> |
|
41 |
+#include <boost/cstdint.hpp> |
|
42 |
+#include <boost/static_assert.hpp> |
|
43 |
+#include <boost/core/scoped_enum.hpp> |
|
44 |
+#include <iosfwd> |
|
45 |
+#include <climits> |
|
46 |
+ |
|
47 |
+# if CHAR_BIT != 8 |
|
48 |
+# error Platforms with CHAR_BIT != 8 are not supported |
|
49 |
+# endif |
|
50 |
+ |
|
51 |
+# ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS |
|
52 |
+# define BOOST_ENDIAN_DEFAULT_CONSTRUCT {} // C++03 |
|
53 |
+# else |
|
54 |
+# define BOOST_ENDIAN_DEFAULT_CONSTRUCT = default; // C++0x |
|
55 |
+# endif |
|
56 |
+ |
|
57 |
+# if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && defined(BOOST_ENDIAN_FORCE_PODNESS) |
|
58 |
+# define BOOST_ENDIAN_NO_CTORS |
|
59 |
+# endif |
|
60 |
+ |
|
61 |
+//---------------------------------- synopsis ----------------------------------------// |
|
62 |
+ |
|
63 |
+namespace boost |
|
64 |
+{ |
|
65 |
+namespace endian |
|
66 |
+{ |
|
67 |
+ |
|
68 |
+ BOOST_SCOPED_ENUM_START(align) |
|
69 |
+ {no, yes |
|
70 |
+# ifdef BOOST_ENDIAN_DEPRECATED_NAMES |
|
71 |
+ , unaligned = no, aligned = yes |
|
72 |
+# endif |
|
73 |
+ }; BOOST_SCOPED_ENUM_END |
|
74 |
+ |
|
75 |
+ template <BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits, |
|
76 |
+ BOOST_SCOPED_ENUM(align) A = align::no> |
|
77 |
+ class endian_buffer; |
|
78 |
+ |
|
79 |
+ // aligned big endian signed integer buffers |
|
80 |
+ typedef endian_buffer<order::big, int8_t, 8, align::yes> big_int8_buf_at; |
|
81 |
+ typedef endian_buffer<order::big, int16_t, 16, align::yes> big_int16_buf_at; |
|
82 |
+ typedef endian_buffer<order::big, int32_t, 32, align::yes> big_int32_buf_at; |
|
83 |
+ typedef endian_buffer<order::big, int64_t, 64, align::yes> big_int64_buf_at; |
|
84 |
+ |
|
85 |
+ // aligned big endian unsigned integer buffers |
|
86 |
+ typedef endian_buffer<order::big, uint8_t, 8, align::yes> big_uint8_buf_at; |
|
87 |
+ typedef endian_buffer<order::big, uint16_t, 16, align::yes> big_uint16_buf_at; |
|
88 |
+ typedef endian_buffer<order::big, uint32_t, 32, align::yes> big_uint32_buf_at; |
|
89 |
+ typedef endian_buffer<order::big, uint64_t, 64, align::yes> big_uint64_buf_at; |
|
90 |
+ |
|
91 |
+ // aligned little endian signed integer buffers |
|
92 |
+ typedef endian_buffer<order::little, int8_t, 8, align::yes> little_int8_buf_at; |
|
93 |
+ typedef endian_buffer<order::little, int16_t, 16, align::yes> little_int16_buf_at; |
|
94 |
+ typedef endian_buffer<order::little, int32_t, 32, align::yes> little_int32_buf_at; |
|
95 |
+ typedef endian_buffer<order::little, int64_t, 64, align::yes> little_int64_buf_at; |
|
96 |
+ |
|
97 |
+ // aligned little endian unsigned integer buffers |
|
98 |
+ typedef endian_buffer<order::little, uint8_t, 8, align::yes> little_uint8_buf_at; |
|
99 |
+ typedef endian_buffer<order::little, uint16_t, 16, align::yes> little_uint16_buf_at; |
|
100 |
+ typedef endian_buffer<order::little, uint32_t, 32, align::yes> little_uint32_buf_at; |
|
101 |
+ typedef endian_buffer<order::little, uint64_t, 64, align::yes> little_uint64_buf_at; |
|
102 |
+ |
|
103 |
+ // aligned native endian typedefs are not provided because |
|
104 |
+ // <cstdint> types are superior for this use case |
|
105 |
+ |
|
106 |
+ // unaligned big endian signed integer buffers |
|
107 |
+ typedef endian_buffer<order::big, int_least8_t, 8> big_int8_buf_t; |
|
108 |
+ typedef endian_buffer<order::big, int_least16_t, 16> big_int16_buf_t; |
|
109 |
+ typedef endian_buffer<order::big, int_least32_t, 24> big_int24_buf_t; |
|
110 |
+ typedef endian_buffer<order::big, int_least32_t, 32> big_int32_buf_t; |
|
111 |
+ typedef endian_buffer<order::big, int_least64_t, 40> big_int40_buf_t; |
|
112 |
+ typedef endian_buffer<order::big, int_least64_t, 48> big_int48_buf_t; |
|
113 |
+ typedef endian_buffer<order::big, int_least64_t, 56> big_int56_buf_t; |
|
114 |
+ typedef endian_buffer<order::big, int_least64_t, 64> big_int64_buf_t; |
|
115 |
+ |
|
116 |
+ // unaligned big endian unsigned integer buffers |
|
117 |
+ typedef endian_buffer<order::big, uint_least8_t, 8> big_uint8_buf_t; |
|
118 |
+ typedef endian_buffer<order::big, uint_least16_t, 16> big_uint16_buf_t; |
|
119 |
+ typedef endian_buffer<order::big, uint_least32_t, 24> big_uint24_buf_t; |
|
120 |
+ typedef endian_buffer<order::big, uint_least32_t, 32> big_uint32_buf_t; |
|
121 |
+ typedef endian_buffer<order::big, uint_least64_t, 40> big_uint40_buf_t; |
|
122 |
+ typedef endian_buffer<order::big, uint_least64_t, 48> big_uint48_buf_t; |
|
123 |
+ typedef endian_buffer<order::big, uint_least64_t, 56> big_uint56_buf_t; |
|
124 |
+ typedef endian_buffer<order::big, uint_least64_t, 64> big_uint64_buf_t; |
|
125 |
+ |
|
126 |
+ // unaligned little endian signed integer buffers |
|
127 |
+ typedef endian_buffer<order::little, int_least8_t, 8> little_int8_buf_t; |
|
128 |
+ typedef endian_buffer<order::little, int_least16_t, 16> little_int16_buf_t; |
|
129 |
+ typedef endian_buffer<order::little, int_least32_t, 24> little_int24_buf_t; |
|
130 |
+ typedef endian_buffer<order::little, int_least32_t, 32> little_int32_buf_t; |
|
131 |
+ typedef endian_buffer<order::little, int_least64_t, 40> little_int40_buf_t; |
|
132 |
+ typedef endian_buffer<order::little, int_least64_t, 48> little_int48_buf_t; |
|
133 |
+ typedef endian_buffer<order::little, int_least64_t, 56> little_int56_buf_t; |
|
134 |
+ typedef endian_buffer<order::little, int_least64_t, 64> little_int64_buf_t; |
|
135 |
+ |
|
136 |
+ // unaligned little endian unsigned integer buffers |
|
137 |
+ typedef endian_buffer<order::little, uint_least8_t, 8> little_uint8_buf_t; |
|
138 |
+ typedef endian_buffer<order::little, uint_least16_t, 16> little_uint16_buf_t; |
|
139 |
+ typedef endian_buffer<order::little, uint_least32_t, 24> little_uint24_buf_t; |
|
140 |
+ typedef endian_buffer<order::little, uint_least32_t, 32> little_uint32_buf_t; |
|
141 |
+ typedef endian_buffer<order::little, uint_least64_t, 40> little_uint40_buf_t; |
|
142 |
+ typedef endian_buffer<order::little, uint_least64_t, 48> little_uint48_buf_t; |
|
143 |
+ typedef endian_buffer<order::little, uint_least64_t, 56> little_uint56_buf_t; |
|
144 |
+ typedef endian_buffer<order::little, uint_least64_t, 64> little_uint64_buf_t; |
|
145 |
+ |
|
146 |
+# ifdef BOOST_BIG_ENDIAN |
|
147 |
+ // unaligned native endian signed integer buffers |
|
148 |
+ typedef big_int8_buf_t native_int8_buf_t; |
|
149 |
+ typedef big_int16_buf_t native_int16_buf_t; |
|
150 |
+ typedef big_int24_buf_t native_int24_buf_t; |
|
151 |
+ typedef big_int32_buf_t native_int32_buf_t; |
|
152 |
+ typedef big_int40_buf_t native_int40_buf_t; |
|
153 |
+ typedef big_int48_buf_t native_int48_buf_t; |
|
154 |
+ typedef big_int56_buf_t native_int56_buf_t; |
|
155 |
+ typedef big_int64_buf_t native_int64_buf_t; |
|
156 |
+ |
|
157 |
+ // unaligned native endian unsigned integer buffers |
|
158 |
+ typedef big_uint8_buf_t native_uint8_buf_t; |
|
159 |
+ typedef big_uint16_buf_t native_uint16_buf_t; |
|
160 |
+ typedef big_uint24_buf_t native_uint24_buf_t; |
|
161 |
+ typedef big_uint32_buf_t native_uint32_buf_t; |
|
162 |
+ typedef big_uint40_buf_t native_uint40_buf_t; |
|
163 |
+ typedef big_uint48_buf_t native_uint48_buf_t; |
|
164 |
+ typedef big_uint56_buf_t native_uint56_buf_t; |
|
165 |
+ typedef big_uint64_buf_t native_uint64_buf_t; |
|
166 |
+# else |
|
167 |
+ // unaligned native endian signed integer buffers |
|
168 |
+ typedef little_int8_buf_t native_int8_buf_t; |
|
169 |
+ typedef little_int16_buf_t native_int16_buf_t; |
|
170 |
+ typedef little_int24_buf_t native_int24_buf_t; |
|
171 |
+ typedef little_int32_buf_t native_int32_buf_t; |
|
172 |
+ typedef little_int40_buf_t native_int40_buf_t; |
|
173 |
+ typedef little_int48_buf_t native_int48_buf_t; |
|
174 |
+ typedef little_int56_buf_t native_int56_buf_t; |
|
175 |
+ typedef little_int64_buf_t native_int64_buf_t; |
|
176 |
+ |
|
177 |
+ // unaligned native endian unsigned integer buffers |
|
178 |
+ typedef little_uint8_buf_t native_uint8_buf_t; |
|
179 |
+ typedef little_uint16_buf_t native_uint16_buf_t; |
|
180 |
+ typedef little_uint24_buf_t native_uint24_buf_t; |
|
181 |
+ typedef little_uint32_buf_t native_uint32_buf_t; |
|
182 |
+ typedef little_uint40_buf_t native_uint40_buf_t; |
|
183 |
+ typedef little_uint48_buf_t native_uint48_buf_t; |
|
184 |
+ typedef little_uint56_buf_t native_uint56_buf_t; |
|
185 |
+ typedef little_uint64_buf_t native_uint64_buf_t; |
|
186 |
+# endif |
|
187 |
+ |
|
188 |
+ // Stream inserter |
|
189 |
+ template <class charT, class traits, BOOST_SCOPED_ENUM(order) Order, class T, |
|
190 |
+ std::size_t n_bits, BOOST_SCOPED_ENUM(align) A> |
|
191 |
+ std::basic_ostream<charT, traits>& |
|
192 |
+ operator<<(std::basic_ostream<charT, traits>& os, |
|
193 |
+ const endian_buffer<Order, T, n_bits, A>& x) |
|
194 |
+ { |
|
195 |
+ return os << x.value(); |
|
196 |
+ } |
|
197 |
+ |
|
198 |
+ // Stream extractor |
|
199 |
+ template <class charT, class traits, BOOST_SCOPED_ENUM(order) Order, class T, |
|
200 |
+ std::size_t n_bits, BOOST_SCOPED_ENUM(align) A> |
|
201 |
+ std::basic_istream<charT, traits>& |
|
202 |
+ operator>>(std::basic_istream<charT, traits>& is, |
|
203 |
+ endian_buffer<Order, T, n_bits, A>& x) |
|
204 |
+ { |
|
205 |
+ T i; |
|
206 |
+ if (is >> i) |
|
207 |
+ x = i; |
|
208 |
+ return is; |
|
209 |
+ } |
|
210 |
+ |
|
211 |
+//---------------------------------- end synopsis ------------------------------------// |
|
212 |
+ |
|
213 |
+ namespace detail |
|
214 |
+ { |
|
215 |
+ |
|
216 |
+ // Unrolled loops for loading and storing streams of bytes. |
|
217 |
+ |
|
218 |
+ template <typename T, std::size_t n_bytes, |
|
219 |
+ bool sign=boost::is_signed<T>::value > |
|
220 |
+ struct unrolled_byte_loops |
|
221 |
+ { |
|
222 |
+ typedef unrolled_byte_loops<T, n_bytes - 1, sign> next; |
|
223 |
+ |
|
224 |
+ static T load_big(const unsigned char* bytes) BOOST_NOEXCEPT |
|
225 |
+ { return static_cast<T>(*(bytes - 1) | (next::load_big(bytes - 1) << 8)); } |
|
226 |
+ static T load_little(const unsigned char* bytes) BOOST_NOEXCEPT |
|
227 |
+ { return static_cast<T>(*bytes | (next::load_little(bytes + 1) << 8)); } |
|
228 |
+ |
|
229 |
+ static void store_big(char* bytes, T value) BOOST_NOEXCEPT |
|
230 |
+ { |
|
231 |
+ *(bytes - 1) = static_cast<char>(value); |
|
232 |
+ next::store_big(bytes - 1, static_cast<T>(value >> 8)); |
|
233 |
+ } |
|
234 |
+ static void store_little(char* bytes, T value) BOOST_NOEXCEPT |
|
235 |
+ { |
|
236 |
+ *bytes = static_cast<char>(value); |
|
237 |
+ next::store_little(bytes + 1, static_cast<T>(value >> 8)); |
|
238 |
+ } |
|
239 |
+ }; |
|
240 |
+ |
|
241 |
+ template <typename T> |
|
242 |
+ struct unrolled_byte_loops<T, 1, false> |
|
243 |
+ { |
|
244 |
+ static T load_big(const unsigned char* bytes) BOOST_NOEXCEPT |
|
245 |
+ { return *(bytes - 1); } |
|
246 |
+ static T load_little(const unsigned char* bytes) BOOST_NOEXCEPT |
|
247 |
+ { return *bytes; } |
|
248 |
+ static void store_big(char* bytes, T value) BOOST_NOEXCEPT |
|
249 |
+ { *(bytes - 1) = static_cast<char>(value); } |
|
250 |
+ static void store_little(char* bytes, T value) BOOST_NOEXCEPT |
|
251 |
+ { *bytes = static_cast<char>(value); } |
|
252 |
+ |
|
253 |
+ }; |
|
254 |
+ |
|
255 |
+ template <typename T> |
|
256 |
+ struct unrolled_byte_loops<T, 1, true> |
|
257 |
+ { |
|
258 |
+ static T load_big(const unsigned char* bytes) BOOST_NOEXCEPT |
|
259 |
+ { return *reinterpret_cast<const signed char*>(bytes - 1); } |
|
260 |
+ static T load_little(const unsigned char* bytes) BOOST_NOEXCEPT |
|
261 |
+ { return *reinterpret_cast<const signed char*>(bytes); } |
|
262 |
+ static void store_big(char* bytes, T value) BOOST_NOEXCEPT |
|
263 |
+ { *(bytes - 1) = static_cast<char>(value); } |
|
264 |
+ static void store_little(char* bytes, T value) BOOST_NOEXCEPT |
|
265 |
+ { *bytes = static_cast<char>(value); } |
|
266 |
+ }; |
|
267 |
+ |
|
268 |
+ template <typename T, std::size_t n_bytes> |
|
269 |
+ inline |
|
270 |
+ T load_big_endian(const void* bytes) BOOST_NOEXCEPT |
|
271 |
+ { |
|
272 |
+ return unrolled_byte_loops<T, n_bytes>::load_big |
|
273 |
+ (static_cast<const unsigned char*>(bytes) + n_bytes); |
|
274 |
+ } |
|
275 |
+ |
|
276 |
+ template <typename T, std::size_t n_bytes> |
|
277 |
+ inline |
|
278 |
+ T load_little_endian(const void* bytes) BOOST_NOEXCEPT |
|
279 |
+ { |
|
280 |
+# if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) |
|
281 |
+ // On x86 (which is little endian), unaligned loads are permitted |
|
282 |
+ if (sizeof(T) == n_bytes) // GCC 4.9, VC++ 14.0, and probably others, elide this |
|
283 |
+ // test and generate code only for the applicable return |
|
284 |
+ // case since sizeof(T) and n_bytes are known at compile |
|
285 |
+ // time. |
|
286 |
+ { |
|
287 |
+ return *reinterpret_cast<T const *>(bytes); |
|
288 |
+ } |
|
289 |
+# endif |
|
290 |
+ return unrolled_byte_loops<T, n_bytes>::load_little |
|
291 |
+ (static_cast<const unsigned char*>(bytes)); |
|
292 |
+ } |
|
293 |
+ |
|
294 |
+ template <typename T, std::size_t n_bytes> |
|
295 |
+ inline |
|
296 |
+ void store_big_endian(void* bytes, T value) BOOST_NOEXCEPT |
|
297 |
+ { |
|
298 |
+ unrolled_byte_loops<T, n_bytes>::store_big |
|
299 |
+ (static_cast<char*>(bytes) + n_bytes, value); |
|
300 |
+ } |
|
301 |
+ |
|
302 |
+ template <typename T, std::size_t n_bytes> |
|
303 |
+ inline |
|
304 |
+ void store_little_endian(void* bytes, T value) BOOST_NOEXCEPT |
|
305 |
+ { |
|
306 |
+# if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86) |
|
307 |
+ // On x86 (which is little endian), unaligned stores are permitted |
|
308 |
+ if (sizeof(T) == n_bytes) // GCC 4.9, VC++ 14.0, and probably others, elide this |
|
309 |
+ // test and generate code only for the applicable return |
|
310 |
+ // case since sizeof(T) and n_bytes are known at compile |
|
311 |
+ // time. |
|
312 |
+ { |
|
313 |
+ *reinterpret_cast<T *>(bytes) = value; |
|
314 |
+ return; |
|
315 |
+ } |
|
316 |
+# endif |
|
317 |
+ unrolled_byte_loops<T, n_bytes>::store_little |
|
318 |
+ (static_cast<char*>(bytes), value); |
|
319 |
+ } |
|
320 |
+ |
|
321 |
+ } // namespace detail |
|
322 |
+ |
|
323 |
+# ifdef BOOST_ENDIAN_LOG |
|
324 |
+ bool endian_log(true); |
|
325 |
+# endif |
|
326 |
+ |
|
327 |
+// endian_buffer class template specializations --------------------------------------// |
|
328 |
+ |
|
329 |
+ // Specializations that represent unaligned bytes. |
|
330 |
+ // Taking an integer type as a parameter provides a nice way to pass both |
|
331 |
+ // the size and signedness of the desired integer and get the appropriate |
|
332 |
+ // corresponding integer type for the interface. |
|
333 |
+ |
|
334 |
+ // Q: Should endian_buffer supply "value_type operator value_type() const noexcept"? |
|
335 |
+ // A: No. The rationale for endian_buffers is to prevent high-cost hidden |
|
336 |
+ // conversions. If an implicit conversion operator is supplied, hidden conversions |
|
337 |
+ // can occur. |
|
338 |
+ |
|
339 |
+ // unaligned big endian_buffer specialization |
|
340 |
+ template <typename T, std::size_t n_bits> |
|
341 |
+ class endian_buffer< order::big, T, n_bits, align::no > |
|
342 |
+ { |
|
343 |
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
344 |
+ public: |
|
345 |
+ typedef T value_type; |
|
346 |
+# ifndef BOOST_ENDIAN_NO_CTORS |
|
347 |
+ endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
348 |
+ explicit endian_buffer(T val) BOOST_NOEXCEPT |
|
349 |
+ { |
|
350 |
+# ifdef BOOST_ENDIAN_LOG |
|
351 |
+ if ( endian_log ) |
|
352 |
+ std::cout << "big, unaligned, " |
|
353 |
+ << n_bits << "-bits, construct(" << val << ")\n"; |
|
354 |
+# endif |
|
355 |
+ detail::store_big_endian<T, n_bits/8>(m_value, val); |
|
356 |
+ } |
|
357 |
+# endif |
|
358 |
+ endian_buffer & operator=(T val) BOOST_NOEXCEPT |
|
359 |
+ { |
|
360 |
+# ifdef BOOST_ENDIAN_LOG |
|
361 |
+ if (endian_log) |
|
362 |
+ std::cout << "big, unaligned, " << n_bits << "-bits, assign(" << val << ")\n"; |
|
363 |
+# endif |
|
364 |
+ detail::store_big_endian<T, n_bits/8>(m_value, val); |
|
365 |
+ return *this; |
|
366 |
+ } |
|
367 |
+ value_type value() const BOOST_NOEXCEPT |
|
368 |
+ { |
|
369 |
+# ifdef BOOST_ENDIAN_LOG |
|
370 |
+ if ( endian_log ) |
|
371 |
+ std::cout << "big, unaligned, " << n_bits << "-bits, convert(" |
|
372 |
+ << detail::load_big_endian<T, n_bits/8>(m_value) << ")\n"; |
|
373 |
+# endif |
|
374 |
+ return detail::load_big_endian<T, n_bits/8>(m_value); |
|
375 |
+ } |
|
376 |
+ const char* data() const BOOST_NOEXCEPT { return m_value; } |
|
377 |
+ protected: |
|
378 |
+ char m_value[n_bits/8]; |
|
379 |
+ }; |
|
380 |
+ |
|
381 |
+ // unaligned little endian_buffer specialization |
|
382 |
+ template <typename T, std::size_t n_bits> |
|
383 |
+ class endian_buffer< order::little, T, n_bits, align::no > |
|
384 |
+ { |
|
385 |
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
386 |
+ public: |
|
387 |
+ typedef T value_type; |
|
388 |
+# ifndef BOOST_ENDIAN_NO_CTORS |
|
389 |
+ endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
390 |
+ explicit endian_buffer(T val) BOOST_NOEXCEPT |
|
391 |
+ { |
|
392 |
+# ifdef BOOST_ENDIAN_LOG |
|
393 |
+ if ( endian_log ) |
|
394 |
+ std::cout << "little, unaligned, " << n_bits << "-bits, construct(" |
|
395 |
+ << val << ")\n"; |
|
396 |
+# endif |
|
397 |
+ detail::store_little_endian<T, n_bits/8>(m_value, val); |
|
398 |
+ } |
|
399 |
+# endif |
|
400 |
+ endian_buffer & operator=(T val) BOOST_NOEXCEPT |
|
401 |
+ { detail::store_little_endian<T, n_bits/8>(m_value, val); return *this; } |
|
402 |
+ value_type value() const BOOST_NOEXCEPT |
|
403 |
+ { |
|
404 |
+# ifdef BOOST_ENDIAN_LOG |
|
405 |
+ if ( endian_log ) |
|
406 |
+ std::cout << "little, unaligned, " << n_bits << "-bits, convert(" |
|
407 |
+ << detail::load_little_endian<T, n_bits/8>(m_value) << ")\n"; |
|
408 |
+# endif |
|
409 |
+ return detail::load_little_endian<T, n_bits/8>(m_value); |
|
410 |
+ } |
|
411 |
+ const char* data() const BOOST_NOEXCEPT { return m_value; } |
|
412 |
+ protected: |
|
413 |
+ char m_value[n_bits/8]; |
|
414 |
+ }; |
|
415 |
+ |
|
416 |
+ // align::yes specializations; only n_bits == 16/32/64 supported |
|
417 |
+ |
|
418 |
+ // aligned big endian_buffer specialization |
|
419 |
+ template <typename T, std::size_t n_bits> |
|
420 |
+ class endian_buffer<order::big, T, n_bits, align::yes> |
|
421 |
+ { |
|
422 |
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
423 |
+ BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 ); |
|
424 |
+ public: |
|
425 |
+ typedef T value_type; |
|
426 |
+# ifndef BOOST_ENDIAN_NO_CTORS |
|
427 |
+ endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
428 |
+ explicit endian_buffer(T val) BOOST_NOEXCEPT |
|
429 |
+ { |
|
430 |
+# ifdef BOOST_ENDIAN_LOG |
|
431 |
+ if ( endian_log ) |
|
432 |
+ std::cout << "big, aligned, " << n_bits |
|
433 |
+ << "-bits, construct(" << val << ")\n"; |
|
434 |
+# endif |
|
435 |
+ m_value = ::boost::endian::native_to_big(val); |
|
436 |
+ } |
|
437 |
+ |
|
438 |
+# endif |
|
439 |
+ endian_buffer& operator=(T val) BOOST_NOEXCEPT |
|
440 |
+ { |
|
441 |
+ m_value = ::boost::endian::native_to_big(val); |
|
442 |
+ return *this; |
|
443 |
+ } |
|
444 |
+ //operator value_type() const BOOST_NOEXCEPT |
|
445 |
+ //{ |
|
446 |
+ // return ::boost::endian::big_to_native(m_value); |
|
447 |
+ //} |
|
448 |
+ value_type value() const BOOST_NOEXCEPT |
|
449 |
+ { |
|
450 |
+# ifdef BOOST_ENDIAN_LOG |
|
451 |
+ if ( endian_log ) |
|
452 |
+ std::cout << "big, aligned, " << n_bits << "-bits, convert(" |
|
453 |
+ << ::boost::endian::big_to_native(m_value) << ")\n"; |
|
454 |
+# endif |
|
455 |
+ return ::boost::endian::big_to_native(m_value); |
|
456 |
+ } |
|
457 |
+ const char* data() const BOOST_NOEXCEPT |
|
458 |
+ {return reinterpret_cast<const char*>(&m_value);} |
|
459 |
+ protected: |
|
460 |
+ T m_value; |
|
461 |
+ }; |
|
462 |
+ |
|
463 |
+ // aligned little endian_buffer specialization |
|
464 |
+ template <typename T, std::size_t n_bits> |
|
465 |
+ class endian_buffer<order::little, T, n_bits, align::yes> |
|
466 |
+ { |
|
467 |
+ BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits ); |
|
468 |
+ BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 ); |
|
469 |
+ public: |
|
470 |
+ typedef T value_type; |
|
471 |
+# ifndef BOOST_ENDIAN_NO_CTORS |
|
472 |
+ endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT |
|
473 |
+ explicit endian_buffer(T val) BOOST_NOEXCEPT |
|
474 |
+ { |
|
475 |
+# ifdef BOOST_ENDIAN_LOG |
|
476 |
+ if ( endian_log ) |
|
477 |
+ std::cout << "little, aligned, " << n_bits |
|
478 |
+ << "-bits, construct(" << val << ")\n"; |
|
479 |
+# endif |
|
480 |
+ m_value = ::boost::endian::native_to_little(val); |
|
481 |
+ } |
|
482 |
+ |
|
483 |
+# endif |
|
484 |
+ endian_buffer& operator=(T val) BOOST_NOEXCEPT |
|
485 |
+ { |
|
486 |
+ m_value = ::boost::endian::native_to_little(val); |
|
487 |
+ return *this; |
|