Chris@102
|
1 // boost/endian/arithmetic.hpp -------------------------------------------------------//
|
Chris@102
|
2
|
Chris@102
|
3 // (C) Copyright Darin Adler 2000
|
Chris@102
|
4 // (C) Copyright Beman Dawes 2006, 2009, 2014
|
Chris@102
|
5
|
Chris@102
|
6 // Distributed under the Boost Software License, Version 1.0.
|
Chris@102
|
7 // See http://www.boost.org/LICENSE_1_0.txt
|
Chris@102
|
8
|
Chris@102
|
9 // See library home page at http://www.boost.org/libs/endian
|
Chris@102
|
10
|
Chris@102
|
11 //--------------------------------------------------------------------------------------//
|
Chris@102
|
12
|
Chris@102
|
13 // Original design developed by Darin Adler based on classes developed by Mark
|
Chris@102
|
14 // Borgerding. Four original class templates were combined into a single endian
|
Chris@102
|
15 // class template by Beman Dawes, who also added the unrolled_byte_loops sign
|
Chris@102
|
16 // partial specialization to correctly extend the sign when cover integer size
|
Chris@102
|
17 // differs from endian representation size.
|
Chris@102
|
18
|
Chris@102
|
19 // TODO: When a compiler supporting constexpr becomes available, try possible uses.
|
Chris@102
|
20
|
Chris@102
|
21 #ifndef BOOST_ENDIAN_ARITHMETIC_HPP
|
Chris@102
|
22 #define BOOST_ENDIAN_ARITHMETIC_HPP
|
Chris@102
|
23
|
Chris@102
|
24 #if defined(_MSC_VER)
|
Chris@102
|
25 # pragma warning(push)
|
Chris@102
|
26 # pragma warning(disable:4365) // conversion ... signed/unsigned mismatch
|
Chris@102
|
27 #endif
|
Chris@102
|
28
|
Chris@102
|
29 #ifdef BOOST_ENDIAN_LOG
|
Chris@102
|
30 # include <iostream>
|
Chris@102
|
31 #endif
|
Chris@102
|
32
|
Chris@102
|
33 #if defined(__BORLANDC__) || defined( __CODEGEARC__)
|
Chris@102
|
34 # pragma pack(push, 1)
|
Chris@102
|
35 #endif
|
Chris@102
|
36
|
Chris@102
|
37 #include <boost/config.hpp>
|
Chris@102
|
38 #include <boost/predef/detail/endian_compat.h>
|
Chris@102
|
39 #include <boost/endian/conversion.hpp>
|
Chris@102
|
40 #include <boost/endian/buffers.hpp>
|
Chris@102
|
41 #define BOOST_ENDIAN_MINIMAL_COVER_OPERATORS
|
Chris@102
|
42 #include <boost/endian/detail/cover_operators.hpp>
|
Chris@102
|
43 #undef BOOST_ENDIAN_MINIMAL_COVER_OPERATORS
|
Chris@102
|
44 #include <boost/type_traits/is_signed.hpp>
|
Chris@102
|
45 #include <boost/cstdint.hpp>
|
Chris@102
|
46 #include <boost/static_assert.hpp>
|
Chris@102
|
47 #include <boost/core/scoped_enum.hpp>
|
Chris@102
|
48 #include <iosfwd>
|
Chris@102
|
49 #include <climits>
|
Chris@102
|
50
|
Chris@102
|
51 # if CHAR_BIT != 8
|
Chris@102
|
52 # error Platforms with CHAR_BIT != 8 are not supported
|
Chris@102
|
53 # endif
|
Chris@102
|
54
|
Chris@102
|
55 # ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
|
Chris@102
|
56 # define BOOST_ENDIAN_DEFAULT_CONSTRUCT {} // C++03
|
Chris@102
|
57 # else
|
Chris@102
|
58 # define BOOST_ENDIAN_DEFAULT_CONSTRUCT = default; // C++0x
|
Chris@102
|
59 # endif
|
Chris@102
|
60
|
Chris@102
|
61 # if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && defined(BOOST_ENDIAN_FORCE_PODNESS)
|
Chris@102
|
62 # define BOOST_ENDIAN_NO_CTORS
|
Chris@102
|
63 # endif
|
Chris@102
|
64
|
Chris@102
|
65 # ifndef BOOST_ENDIAN_EXPLICIT_CTORS
|
Chris@102
|
66 # define BOOST_ENDIAN_EXPLICIT_OPT
|
Chris@102
|
67 # else
|
Chris@102
|
68 # define BOOST_ENDIAN_EXPLICIT_OPT explicit
|
Chris@102
|
69 # endif
|
Chris@102
|
70
|
Chris@102
|
71 //---------------------------------- synopsis ----------------------------------------//
|
Chris@102
|
72
|
Chris@102
|
73 namespace boost
|
Chris@102
|
74 {
|
Chris@102
|
75 namespace endian
|
Chris@102
|
76 {
|
Chris@102
|
77
|
Chris@102
|
78 template <BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits,
|
Chris@102
|
79 BOOST_SCOPED_ENUM(align) A = align::no>
|
Chris@102
|
80 class endian_arithmetic;
|
Chris@102
|
81
|
Chris@102
|
82 // big endian signed integer aligned types
|
Chris@102
|
83 typedef endian_arithmetic<order::big, int8_t, 8, align::yes> big_int8_at;
|
Chris@102
|
84 typedef endian_arithmetic<order::big, int16_t, 16, align::yes> big_int16_at;
|
Chris@102
|
85 typedef endian_arithmetic<order::big, int32_t, 32, align::yes> big_int32_at;
|
Chris@102
|
86 typedef endian_arithmetic<order::big, int64_t, 64, align::yes> big_int64_at;
|
Chris@102
|
87
|
Chris@102
|
88 // big endian unsigned integer aligned types
|
Chris@102
|
89 typedef endian_arithmetic<order::big, uint8_t, 8, align::yes> big_uint8_at;
|
Chris@102
|
90 typedef endian_arithmetic<order::big, uint16_t, 16, align::yes> big_uint16_at;
|
Chris@102
|
91 typedef endian_arithmetic<order::big, uint32_t, 32, align::yes> big_uint32_at;
|
Chris@102
|
92 typedef endian_arithmetic<order::big, uint64_t, 64, align::yes> big_uint64_at;
|
Chris@102
|
93
|
Chris@102
|
94 // little endian signed integer aligned types
|
Chris@102
|
95 typedef endian_arithmetic<order::little, int8_t, 8, align::yes> little_int8_at;
|
Chris@102
|
96 typedef endian_arithmetic<order::little, int16_t, 16, align::yes> little_int16_at;
|
Chris@102
|
97 typedef endian_arithmetic<order::little, int32_t, 32, align::yes> little_int32_at;
|
Chris@102
|
98 typedef endian_arithmetic<order::little, int64_t, 64, align::yes> little_int64_at;
|
Chris@102
|
99
|
Chris@102
|
100 // little endian unsigned integer aligned types
|
Chris@102
|
101 typedef endian_arithmetic<order::little, uint8_t, 8, align::yes> little_uint8_at;
|
Chris@102
|
102 typedef endian_arithmetic<order::little, uint16_t, 16, align::yes> little_uint16_at;
|
Chris@102
|
103 typedef endian_arithmetic<order::little, uint32_t, 32, align::yes> little_uint32_at;
|
Chris@102
|
104 typedef endian_arithmetic<order::little, uint64_t, 64, align::yes> little_uint64_at;
|
Chris@102
|
105
|
Chris@102
|
106 // aligned native endian typedefs are not provided because
|
Chris@102
|
107 // <cstdint> types are superior for this use case
|
Chris@102
|
108
|
Chris@102
|
109 // big endian signed integer unaligned types
|
Chris@102
|
110 typedef endian_arithmetic<order::big, int_least8_t, 8> big_int8_t;
|
Chris@102
|
111 typedef endian_arithmetic<order::big, int_least16_t, 16> big_int16_t;
|
Chris@102
|
112 typedef endian_arithmetic<order::big, int_least32_t, 24> big_int24_t;
|
Chris@102
|
113 typedef endian_arithmetic<order::big, int_least32_t, 32> big_int32_t;
|
Chris@102
|
114 typedef endian_arithmetic<order::big, int_least64_t, 40> big_int40_t;
|
Chris@102
|
115 typedef endian_arithmetic<order::big, int_least64_t, 48> big_int48_t;
|
Chris@102
|
116 typedef endian_arithmetic<order::big, int_least64_t, 56> big_int56_t;
|
Chris@102
|
117 typedef endian_arithmetic<order::big, int_least64_t, 64> big_int64_t;
|
Chris@102
|
118
|
Chris@102
|
119 // big endian unsigned integer unaligned types
|
Chris@102
|
120 typedef endian_arithmetic<order::big, uint_least8_t, 8> big_uint8_t;
|
Chris@102
|
121 typedef endian_arithmetic<order::big, uint_least16_t, 16> big_uint16_t;
|
Chris@102
|
122 typedef endian_arithmetic<order::big, uint_least32_t, 24> big_uint24_t;
|
Chris@102
|
123 typedef endian_arithmetic<order::big, uint_least32_t, 32> big_uint32_t;
|
Chris@102
|
124 typedef endian_arithmetic<order::big, uint_least64_t, 40> big_uint40_t;
|
Chris@102
|
125 typedef endian_arithmetic<order::big, uint_least64_t, 48> big_uint48_t;
|
Chris@102
|
126 typedef endian_arithmetic<order::big, uint_least64_t, 56> big_uint56_t;
|
Chris@102
|
127 typedef endian_arithmetic<order::big, uint_least64_t, 64> big_uint64_t;
|
Chris@102
|
128
|
Chris@102
|
129 // little endian signed integer unaligned types
|
Chris@102
|
130 typedef endian_arithmetic<order::little, int_least8_t, 8> little_int8_t;
|
Chris@102
|
131 typedef endian_arithmetic<order::little, int_least16_t, 16> little_int16_t;
|
Chris@102
|
132 typedef endian_arithmetic<order::little, int_least32_t, 24> little_int24_t;
|
Chris@102
|
133 typedef endian_arithmetic<order::little, int_least32_t, 32> little_int32_t;
|
Chris@102
|
134 typedef endian_arithmetic<order::little, int_least64_t, 40> little_int40_t;
|
Chris@102
|
135 typedef endian_arithmetic<order::little, int_least64_t, 48> little_int48_t;
|
Chris@102
|
136 typedef endian_arithmetic<order::little, int_least64_t, 56> little_int56_t;
|
Chris@102
|
137 typedef endian_arithmetic<order::little, int_least64_t, 64> little_int64_t;
|
Chris@102
|
138
|
Chris@102
|
139 // little endian unsigned integer unaligned types
|
Chris@102
|
140 typedef endian_arithmetic<order::little, uint_least8_t, 8> little_uint8_t;
|
Chris@102
|
141 typedef endian_arithmetic<order::little, uint_least16_t, 16> little_uint16_t;
|
Chris@102
|
142 typedef endian_arithmetic<order::little, uint_least32_t, 24> little_uint24_t;
|
Chris@102
|
143 typedef endian_arithmetic<order::little, uint_least32_t, 32> little_uint32_t;
|
Chris@102
|
144 typedef endian_arithmetic<order::little, uint_least64_t, 40> little_uint40_t;
|
Chris@102
|
145 typedef endian_arithmetic<order::little, uint_least64_t, 48> little_uint48_t;
|
Chris@102
|
146 typedef endian_arithmetic<order::little, uint_least64_t, 56> little_uint56_t;
|
Chris@102
|
147 typedef endian_arithmetic<order::little, uint_least64_t, 64> little_uint64_t;
|
Chris@102
|
148
|
Chris@102
|
149 # ifdef BOOST_BIG_ENDIAN
|
Chris@102
|
150 // native endian signed integer unaligned types
|
Chris@102
|
151 typedef big_int8_t native_int8_t;
|
Chris@102
|
152 typedef big_int16_t native_int16_t;
|
Chris@102
|
153 typedef big_int24_t native_int24_t;
|
Chris@102
|
154 typedef big_int32_t native_int32_t;
|
Chris@102
|
155 typedef big_int40_t native_int40_t;
|
Chris@102
|
156 typedef big_int48_t native_int48_t;
|
Chris@102
|
157 typedef big_int56_t native_int56_t;
|
Chris@102
|
158 typedef big_int64_t native_int64_t;
|
Chris@102
|
159
|
Chris@102
|
160 // native endian unsigned integer unaligned types
|
Chris@102
|
161 typedef big_uint8_t native_uint8_t;
|
Chris@102
|
162 typedef big_uint16_t native_uint16_t;
|
Chris@102
|
163 typedef big_uint24_t native_uint24_t;
|
Chris@102
|
164 typedef big_uint32_t native_uint32_t;
|
Chris@102
|
165 typedef big_uint40_t native_uint40_t;
|
Chris@102
|
166 typedef big_uint48_t native_uint48_t;
|
Chris@102
|
167 typedef big_uint56_t native_uint56_t;
|
Chris@102
|
168 typedef big_uint64_t native_uint64_t;
|
Chris@102
|
169 # else
|
Chris@102
|
170 // native endian signed integer unaligned types
|
Chris@102
|
171 typedef little_int8_t native_int8_t;
|
Chris@102
|
172 typedef little_int16_t native_int16_t;
|
Chris@102
|
173 typedef little_int24_t native_int24_t;
|
Chris@102
|
174 typedef little_int32_t native_int32_t;
|
Chris@102
|
175 typedef little_int40_t native_int40_t;
|
Chris@102
|
176 typedef little_int48_t native_int48_t;
|
Chris@102
|
177 typedef little_int56_t native_int56_t;
|
Chris@102
|
178 typedef little_int64_t native_int64_t;
|
Chris@102
|
179
|
Chris@102
|
180 // native endian unsigned integer unaligned types
|
Chris@102
|
181 typedef little_uint8_t native_uint8_t;
|
Chris@102
|
182 typedef little_uint16_t native_uint16_t;
|
Chris@102
|
183 typedef little_uint24_t native_uint24_t;
|
Chris@102
|
184 typedef little_uint32_t native_uint32_t;
|
Chris@102
|
185 typedef little_uint40_t native_uint40_t;
|
Chris@102
|
186 typedef little_uint48_t native_uint48_t;
|
Chris@102
|
187 typedef little_uint56_t native_uint56_t;
|
Chris@102
|
188 typedef little_uint64_t native_uint64_t;
|
Chris@102
|
189 # endif
|
Chris@102
|
190
|
Chris@102
|
191 # ifdef BOOST_ENDIAN_DEPRECATED_NAMES
|
Chris@102
|
192
|
Chris@102
|
193 typedef order endianness;
|
Chris@102
|
194 typedef align alignment;
|
Chris@102
|
195
|
Chris@102
|
196 # ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES
|
Chris@102
|
197 template <BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits,
|
Chris@102
|
198 BOOST_SCOPED_ENUM(align) Align = align::no>
|
Chris@102
|
199 using endian = endian_arithmetic<Order, T, n_bits, Align>;
|
Chris@102
|
200 # endif
|
Chris@102
|
201
|
Chris@102
|
202 // unaligned big endian signed integer types
|
Chris@102
|
203 typedef endian_arithmetic< order::big, int_least8_t, 8 > big8_t;
|
Chris@102
|
204 typedef endian_arithmetic< order::big, int_least16_t, 16 > big16_t;
|
Chris@102
|
205 typedef endian_arithmetic< order::big, int_least32_t, 24 > big24_t;
|
Chris@102
|
206 typedef endian_arithmetic< order::big, int_least32_t, 32 > big32_t;
|
Chris@102
|
207 typedef endian_arithmetic< order::big, int_least64_t, 40 > big40_t;
|
Chris@102
|
208 typedef endian_arithmetic< order::big, int_least64_t, 48 > big48_t;
|
Chris@102
|
209 typedef endian_arithmetic< order::big, int_least64_t, 56 > big56_t;
|
Chris@102
|
210 typedef endian_arithmetic< order::big, int_least64_t, 64 > big64_t;
|
Chris@102
|
211
|
Chris@102
|
212 // unaligned big endian_arithmetic unsigned integer types
|
Chris@102
|
213 typedef endian_arithmetic< order::big, uint_least8_t, 8 > ubig8_t;
|
Chris@102
|
214 typedef endian_arithmetic< order::big, uint_least16_t, 16 > ubig16_t;
|
Chris@102
|
215 typedef endian_arithmetic< order::big, uint_least32_t, 24 > ubig24_t;
|
Chris@102
|
216 typedef endian_arithmetic< order::big, uint_least32_t, 32 > ubig32_t;
|
Chris@102
|
217 typedef endian_arithmetic< order::big, uint_least64_t, 40 > ubig40_t;
|
Chris@102
|
218 typedef endian_arithmetic< order::big, uint_least64_t, 48 > ubig48_t;
|
Chris@102
|
219 typedef endian_arithmetic< order::big, uint_least64_t, 56 > ubig56_t;
|
Chris@102
|
220 typedef endian_arithmetic< order::big, uint_least64_t, 64 > ubig64_t;
|
Chris@102
|
221
|
Chris@102
|
222 // unaligned little endian_arithmetic signed integer types
|
Chris@102
|
223 typedef endian_arithmetic< order::little, int_least8_t, 8 > little8_t;
|
Chris@102
|
224 typedef endian_arithmetic< order::little, int_least16_t, 16 > little16_t;
|
Chris@102
|
225 typedef endian_arithmetic< order::little, int_least32_t, 24 > little24_t;
|
Chris@102
|
226 typedef endian_arithmetic< order::little, int_least32_t, 32 > little32_t;
|
Chris@102
|
227 typedef endian_arithmetic< order::little, int_least64_t, 40 > little40_t;
|
Chris@102
|
228 typedef endian_arithmetic< order::little, int_least64_t, 48 > little48_t;
|
Chris@102
|
229 typedef endian_arithmetic< order::little, int_least64_t, 56 > little56_t;
|
Chris@102
|
230 typedef endian_arithmetic< order::little, int_least64_t, 64 > little64_t;
|
Chris@102
|
231
|
Chris@102
|
232 // unaligned little endian_arithmetic unsigned integer types
|
Chris@102
|
233 typedef endian_arithmetic< order::little, uint_least8_t, 8 > ulittle8_t;
|
Chris@102
|
234 typedef endian_arithmetic< order::little, uint_least16_t, 16 > ulittle16_t;
|
Chris@102
|
235 typedef endian_arithmetic< order::little, uint_least32_t, 24 > ulittle24_t;
|
Chris@102
|
236 typedef endian_arithmetic< order::little, uint_least32_t, 32 > ulittle32_t;
|
Chris@102
|
237 typedef endian_arithmetic< order::little, uint_least64_t, 40 > ulittle40_t;
|
Chris@102
|
238 typedef endian_arithmetic< order::little, uint_least64_t, 48 > ulittle48_t;
|
Chris@102
|
239 typedef endian_arithmetic< order::little, uint_least64_t, 56 > ulittle56_t;
|
Chris@102
|
240 typedef endian_arithmetic< order::little, uint_least64_t, 64 > ulittle64_t;
|
Chris@102
|
241
|
Chris@102
|
242 // unaligned native endian_arithmetic signed integer types
|
Chris@102
|
243 typedef endian_arithmetic< order::native, int_least8_t, 8 > native8_t;
|
Chris@102
|
244 typedef endian_arithmetic< order::native, int_least16_t, 16 > native16_t;
|
Chris@102
|
245 typedef endian_arithmetic< order::native, int_least32_t, 24 > native24_t;
|
Chris@102
|
246 typedef endian_arithmetic< order::native, int_least32_t, 32 > native32_t;
|
Chris@102
|
247 typedef endian_arithmetic< order::native, int_least64_t, 40 > native40_t;
|
Chris@102
|
248 typedef endian_arithmetic< order::native, int_least64_t, 48 > native48_t;
|
Chris@102
|
249 typedef endian_arithmetic< order::native, int_least64_t, 56 > native56_t;
|
Chris@102
|
250 typedef endian_arithmetic< order::native, int_least64_t, 64 > native64_t;
|
Chris@102
|
251
|
Chris@102
|
252 // unaligned native endian_arithmetic unsigned integer types
|
Chris@102
|
253 typedef endian_arithmetic< order::native, uint_least8_t, 8 > unative8_t;
|
Chris@102
|
254 typedef endian_arithmetic< order::native, uint_least16_t, 16 > unative16_t;
|
Chris@102
|
255 typedef endian_arithmetic< order::native, uint_least32_t, 24 > unative24_t;
|
Chris@102
|
256 typedef endian_arithmetic< order::native, uint_least32_t, 32 > unative32_t;
|
Chris@102
|
257 typedef endian_arithmetic< order::native, uint_least64_t, 40 > unative40_t;
|
Chris@102
|
258 typedef endian_arithmetic< order::native, uint_least64_t, 48 > unative48_t;
|
Chris@102
|
259 typedef endian_arithmetic< order::native, uint_least64_t, 56 > unative56_t;
|
Chris@102
|
260 typedef endian_arithmetic< order::native, uint_least64_t, 64 > unative64_t;
|
Chris@102
|
261
|
Chris@102
|
262 // aligned native endian_arithmetic typedefs are not provided because
|
Chris@102
|
263 // <cstdint> types are superior for this use case
|
Chris@102
|
264
|
Chris@102
|
265 typedef endian_arithmetic< order::big, int16_t, 16, align::yes > aligned_big16_t;
|
Chris@102
|
266 typedef endian_arithmetic< order::big, uint16_t, 16, align::yes > aligned_ubig16_t;
|
Chris@102
|
267 typedef endian_arithmetic< order::little, int16_t, 16, align::yes > aligned_little16_t;
|
Chris@102
|
268 typedef endian_arithmetic< order::little, uint16_t, 16, align::yes > aligned_ulittle16_t;
|
Chris@102
|
269
|
Chris@102
|
270 typedef endian_arithmetic< order::big, int32_t, 32, align::yes > aligned_big32_t;
|
Chris@102
|
271 typedef endian_arithmetic< order::big, uint32_t, 32, align::yes > aligned_ubig32_t;
|
Chris@102
|
272 typedef endian_arithmetic< order::little, int32_t, 32, align::yes > aligned_little32_t;
|
Chris@102
|
273 typedef endian_arithmetic< order::little, uint32_t, 32, align::yes > aligned_ulittle32_t;
|
Chris@102
|
274
|
Chris@102
|
275 typedef endian_arithmetic< order::big, int64_t, 64, align::yes > aligned_big64_t;
|
Chris@102
|
276 typedef endian_arithmetic< order::big, uint64_t, 64, align::yes > aligned_ubig64_t;
|
Chris@102
|
277 typedef endian_arithmetic< order::little, int64_t, 64, align::yes > aligned_little64_t;
|
Chris@102
|
278 typedef endian_arithmetic< order::little, uint64_t, 64, align::yes > aligned_ulittle64_t;
|
Chris@102
|
279
|
Chris@102
|
280 # endif
|
Chris@102
|
281
|
Chris@102
|
282 //---------------------------------- end synopsis ------------------------------------//
|
Chris@102
|
283
|
Chris@102
|
284 // endian class template specializations ---------------------------------------------//
|
Chris@102
|
285
|
Chris@102
|
286 // Specializations that represent unaligned bytes.
|
Chris@102
|
287 // Taking an integer type as a parameter provides a nice way to pass both
|
Chris@102
|
288 // the size and signness of the desired integer and get the appropriate
|
Chris@102
|
289 // corresponding integer type for the interface.
|
Chris@102
|
290
|
Chris@102
|
291 // unaligned integer big endian specialization
|
Chris@102
|
292 template <typename T, std::size_t n_bits>
|
Chris@102
|
293 class endian_arithmetic< order::big, T, n_bits, align::no >
|
Chris@102
|
294 : public endian_buffer< order::big, T, n_bits, align::no >,
|
Chris@102
|
295 cover_operators<endian_arithmetic<order::big, T, n_bits>, T>
|
Chris@102
|
296 {
|
Chris@102
|
297 BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
|
Chris@102
|
298 public:
|
Chris@102
|
299 typedef T value_type;
|
Chris@102
|
300 # ifndef BOOST_ENDIAN_NO_CTORS
|
Chris@102
|
301 endian_arithmetic() BOOST_ENDIAN_DEFAULT_CONSTRUCT
|
Chris@102
|
302 BOOST_ENDIAN_EXPLICIT_OPT endian_arithmetic(T val) BOOST_NOEXCEPT
|
Chris@102
|
303 {
|
Chris@102
|
304 # ifdef BOOST_ENDIAN_LOG
|
Chris@102
|
305 if ( endian_log )
|
Chris@102
|
306 std::cout << "big, unaligned, " << n_bits << "-bits, construct(" << val << ")\n";
|
Chris@102
|
307 # endif
|
Chris@102
|
308 detail::store_big_endian<T, n_bits/8>(this->m_value, val);
|
Chris@102
|
309 }
|
Chris@102
|
310 # endif
|
Chris@102
|
311 endian_arithmetic& operator=(T val) BOOST_NOEXCEPT
|
Chris@102
|
312 { detail::store_big_endian<T, n_bits/8>(this->m_value, val); return *this; }
|
Chris@102
|
313 operator value_type() const BOOST_NOEXCEPT { return this->value(); }
|
Chris@102
|
314 };
|
Chris@102
|
315
|
Chris@102
|
316 // unaligned little endian specialization
|
Chris@102
|
317 template <typename T, std::size_t n_bits>
|
Chris@102
|
318 class endian_arithmetic< order::little, T, n_bits, align::no >
|
Chris@102
|
319 : public endian_buffer< order::little, T, n_bits, align::no >,
|
Chris@102
|
320 cover_operators< endian_arithmetic< order::little, T, n_bits >, T >
|
Chris@102
|
321 {
|
Chris@102
|
322 BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
|
Chris@102
|
323 public:
|
Chris@102
|
324 typedef T value_type;
|
Chris@102
|
325 # ifndef BOOST_ENDIAN_NO_CTORS
|
Chris@102
|
326 endian_arithmetic() BOOST_ENDIAN_DEFAULT_CONSTRUCT
|
Chris@102
|
327 BOOST_ENDIAN_EXPLICIT_OPT endian_arithmetic(T val) BOOST_NOEXCEPT
|
Chris@102
|
328 {
|
Chris@102
|
329 # ifdef BOOST_ENDIAN_LOG
|
Chris@102
|
330 if ( endian_log )
|
Chris@102
|
331 std::cout << "little, unaligned, " << n_bits << "-bits, construct(" << val << ")\n";
|
Chris@102
|
332 # endif
|
Chris@102
|
333 detail::store_little_endian<T, n_bits/8>(this->m_value, val);
|
Chris@102
|
334 }
|
Chris@102
|
335 # endif
|
Chris@102
|
336 endian_arithmetic& operator=(T val) BOOST_NOEXCEPT
|
Chris@102
|
337 { detail::store_little_endian<T, n_bits/8>(this->m_value, val); return *this; }
|
Chris@102
|
338 operator value_type() const BOOST_NOEXCEPT { return this->value(); }
|
Chris@102
|
339 };
|
Chris@102
|
340
|
Chris@102
|
341 // align::yes specializations; only n_bits == 16/32/64 supported
|
Chris@102
|
342
|
Chris@102
|
343 // aligned big endian specialization
|
Chris@102
|
344 template <typename T, std::size_t n_bits>
|
Chris@102
|
345 class endian_arithmetic<order::big, T, n_bits, align::yes>
|
Chris@102
|
346 : public endian_buffer< order::big, T, n_bits, align::yes >,
|
Chris@102
|
347 cover_operators<endian_arithmetic<order::big, T, n_bits, align::yes>, T>
|
Chris@102
|
348 {
|
Chris@102
|
349 BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
|
Chris@102
|
350 BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
|
Chris@102
|
351 public:
|
Chris@102
|
352 typedef T value_type;
|
Chris@102
|
353 # ifndef BOOST_ENDIAN_NO_CTORS
|
Chris@102
|
354 endian_arithmetic() BOOST_ENDIAN_DEFAULT_CONSTRUCT
|
Chris@102
|
355 BOOST_ENDIAN_EXPLICIT_OPT endian_arithmetic(T val) BOOST_NOEXCEPT
|
Chris@102
|
356 {
|
Chris@102
|
357 # ifdef BOOST_ENDIAN_LOG
|
Chris@102
|
358 if ( endian_log )
|
Chris@102
|
359 std::cout << "big, aligned, " << n_bits << "-bits, construct(" << val << ")\n";
|
Chris@102
|
360 # endif
|
Chris@102
|
361 this->m_value = ::boost::endian::native_to_big(val);
|
Chris@102
|
362 }
|
Chris@102
|
363
|
Chris@102
|
364 # endif
|
Chris@102
|
365 endian_arithmetic& operator=(T val) BOOST_NOEXCEPT
|
Chris@102
|
366 {
|
Chris@102
|
367 this->m_value = ::boost::endian::native_to_big(val);
|
Chris@102
|
368 return *this;
|
Chris@102
|
369 }
|
Chris@102
|
370 operator value_type() const BOOST_NOEXCEPT { return this->value(); }
|
Chris@102
|
371 };
|
Chris@102
|
372
|
Chris@102
|
373 // aligned little endian specialization
|
Chris@102
|
374 template <typename T, std::size_t n_bits>
|
Chris@102
|
375 class endian_arithmetic<order::little, T, n_bits, align::yes>
|
Chris@102
|
376 : public endian_buffer< order::little, T, n_bits, align::yes >,
|
Chris@102
|
377 cover_operators<endian_arithmetic<order::little, T, n_bits, align::yes>, T>
|
Chris@102
|
378 {
|
Chris@102
|
379 BOOST_STATIC_ASSERT( (n_bits/8)*8 == n_bits );
|
Chris@102
|
380 BOOST_STATIC_ASSERT( sizeof(T) == n_bits/8 );
|
Chris@102
|
381 public:
|
Chris@102
|
382 typedef T value_type;
|
Chris@102
|
383 # ifndef BOOST_ENDIAN_NO_CTORS
|
Chris@102
|
384 endian_arithmetic() BOOST_ENDIAN_DEFAULT_CONSTRUCT
|
Chris@102
|
385 BOOST_ENDIAN_EXPLICIT_OPT endian_arithmetic(T val) BOOST_NOEXCEPT
|
Chris@102
|
386 {
|
Chris@102
|
387 # ifdef BOOST_ENDIAN_LOG
|
Chris@102
|
388 if ( endian_log )
|
Chris@102
|
389 std::cout << "little, aligned, " << n_bits << "-bits, construct(" << val << ")\n";
|
Chris@102
|
390 # endif
|
Chris@102
|
391 this->m_value = ::boost::endian::native_to_little(val);
|
Chris@102
|
392 }
|
Chris@102
|
393 # endif
|
Chris@102
|
394 endian_arithmetic& operator=(T val) BOOST_NOEXCEPT
|
Chris@102
|
395 {
|
Chris@102
|
396 this->m_value = ::boost::endian::native_to_little(val);
|
Chris@102
|
397 return *this;
|
Chris@102
|
398 }
|
Chris@102
|
399 operator value_type() const BOOST_NOEXCEPT { return this->value(); }
|
Chris@102
|
400 };
|
Chris@102
|
401
|
Chris@102
|
402 } // namespace endian
|
Chris@102
|
403 } // namespace boost
|
Chris@102
|
404
|
Chris@102
|
405 #if defined(__BORLANDC__) || defined( __CODEGEARC__)
|
Chris@102
|
406 # pragma pack(pop)
|
Chris@102
|
407 #endif
|
Chris@102
|
408
|
Chris@102
|
409 #if defined(_MSC_VER)
|
Chris@102
|
410 # pragma warning(pop)
|
Chris@102
|
411 #endif
|
Chris@102
|
412
|
Chris@102
|
413 #endif // BOOST_ENDIAN_ARITHMETIC_HPP
|