/src/boost/boost/endian/detail/endian_store.hpp
Line | Count | Source |
1 | | #ifndef BOOST_ENDIAN_DETAIL_ENDIAN_STORE_HPP_INCLUDED |
2 | | #define BOOST_ENDIAN_DETAIL_ENDIAN_STORE_HPP_INCLUDED |
3 | | |
4 | | // Copyright 2019 Peter Dimov |
5 | | // |
6 | | // Distributed under the Boost Software License, Version 1.0. |
7 | | // http://www.boost.org/LICENSE_1_0.txt |
8 | | |
9 | | #include <boost/endian/detail/endian_reverse.hpp> |
10 | | #include <boost/endian/detail/order.hpp> |
11 | | #include <boost/endian/detail/integral_by_size.hpp> |
12 | | #include <boost/endian/detail/is_trivially_copyable.hpp> |
13 | | #include <boost/endian/detail/static_assert.hpp> |
14 | | #include <type_traits> |
15 | | #include <cstddef> |
16 | | #include <cstring> |
17 | | |
18 | | namespace boost |
19 | | { |
20 | | namespace endian |
21 | | { |
22 | | |
23 | | namespace detail |
24 | | { |
25 | | |
26 | | template<class T, std::size_t N1, order O1, std::size_t N2, order O2> struct endian_store_impl |
27 | | { |
28 | | }; |
29 | | |
30 | | } // namespace detail |
31 | | |
32 | | // Requires: |
33 | | // |
34 | | // sizeof(T) must be 1, 2, 4, or 8 |
35 | | // 1 <= N <= sizeof(T) |
36 | | // T is TriviallyCopyable |
37 | | // if N < sizeof(T), T is integral or enum |
38 | | |
39 | | template<class T, std::size_t N, order Order> |
40 | | inline void endian_store( unsigned char * p, T const & v ) BOOST_NOEXCEPT |
41 | 0 | { |
42 | 0 | BOOST_ENDIAN_STATIC_ASSERT( sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8 ); |
43 | 0 | BOOST_ENDIAN_STATIC_ASSERT( N >= 1 && N <= sizeof(T) ); |
44 | 0 |
|
45 | 0 | return detail::endian_store_impl<T, sizeof(T), order::native, N, Order>()( p, v ); |
46 | 0 | } Unexecuted instantiation: void boost::endian::endian_store<short, 2ul, (boost::endian::order)1>(unsigned char*, short const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned short, 2ul, (boost::endian::order)1>(unsigned char*, unsigned short const&) Unexecuted instantiation: void boost::endian::endian_store<short, 2ul, (boost::endian::order)0>(unsigned char*, short const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned short, 2ul, (boost::endian::order)0>(unsigned char*, unsigned short const&) Unexecuted instantiation: void boost::endian::endian_store<int, 3ul, (boost::endian::order)1>(unsigned char*, int const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned int, 3ul, (boost::endian::order)1>(unsigned char*, unsigned int const&) Unexecuted instantiation: void boost::endian::endian_store<int, 3ul, (boost::endian::order)0>(unsigned char*, int const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned int, 3ul, (boost::endian::order)0>(unsigned char*, unsigned int const&) Unexecuted instantiation: void boost::endian::endian_store<int, 4ul, (boost::endian::order)1>(unsigned char*, int const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned int, 4ul, (boost::endian::order)1>(unsigned char*, unsigned int const&) Unexecuted instantiation: void boost::endian::endian_store<int, 4ul, (boost::endian::order)0>(unsigned char*, int const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned int, 4ul, (boost::endian::order)0>(unsigned char*, unsigned int const&) Unexecuted instantiation: void boost::endian::endian_store<long, 5ul, (boost::endian::order)1>(unsigned char*, long const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned long, 5ul, (boost::endian::order)1>(unsigned char*, unsigned long const&) Unexecuted instantiation: void boost::endian::endian_store<long, 5ul, (boost::endian::order)0>(unsigned char*, long const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned long, 5ul, (boost::endian::order)0>(unsigned char*, unsigned long const&) Unexecuted instantiation: void boost::endian::endian_store<long, 6ul, (boost::endian::order)1>(unsigned char*, long const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned long, 6ul, (boost::endian::order)1>(unsigned char*, unsigned long const&) Unexecuted instantiation: void boost::endian::endian_store<long, 6ul, (boost::endian::order)0>(unsigned char*, long const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned long, 6ul, (boost::endian::order)0>(unsigned char*, unsigned long const&) Unexecuted instantiation: void boost::endian::endian_store<long, 7ul, (boost::endian::order)1>(unsigned char*, long const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned long, 7ul, (boost::endian::order)1>(unsigned char*, unsigned long const&) Unexecuted instantiation: void boost::endian::endian_store<long, 7ul, (boost::endian::order)0>(unsigned char*, long const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned long, 7ul, (boost::endian::order)0>(unsigned char*, unsigned long const&) Unexecuted instantiation: void boost::endian::endian_store<long, 8ul, (boost::endian::order)1>(unsigned char*, long const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned long, 8ul, (boost::endian::order)1>(unsigned char*, unsigned long const&) Unexecuted instantiation: void boost::endian::endian_store<long, 8ul, (boost::endian::order)0>(unsigned char*, long const&) Unexecuted instantiation: void boost::endian::endian_store<unsigned long, 8ul, (boost::endian::order)0>(unsigned char*, unsigned long const&) |
47 | | |
48 | | namespace detail |
49 | | { |
50 | | |
51 | | // same endianness, same size |
52 | | |
53 | | template<class T, std::size_t N, order O> struct endian_store_impl<T, N, O, N, O> |
54 | | { |
55 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
56 | 0 | { |
57 | 0 | BOOST_ENDIAN_STATIC_ASSERT( is_trivially_copyable<T>::value ); |
58 | 0 |
|
59 | 0 | std::memcpy( p, &v, N ); |
60 | 0 | } Unexecuted instantiation: boost::endian::detail::endian_store_impl<short, 2ul, (boost::endian::order)1, 2ul, (boost::endian::order)1>::operator()(unsigned char*, short const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned short, 2ul, (boost::endian::order)1, 2ul, (boost::endian::order)1>::operator()(unsigned char*, unsigned short const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<int, 4ul, (boost::endian::order)1, 4ul, (boost::endian::order)1>::operator()(unsigned char*, int const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned int, 4ul, (boost::endian::order)1, 4ul, (boost::endian::order)1>::operator()(unsigned char*, unsigned int const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<long, 8ul, (boost::endian::order)1, 8ul, (boost::endian::order)1>::operator()(unsigned char*, long const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned long, 8ul, (boost::endian::order)1, 8ul, (boost::endian::order)1>::operator()(unsigned char*, unsigned long const&) const |
61 | | }; |
62 | | |
63 | | // same size, reverse endianness |
64 | | |
65 | | template<class T, std::size_t N, order O1, order O2> struct endian_store_impl<T, N, O1, N, O2> |
66 | | { |
67 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
68 | 0 | { |
69 | 0 | BOOST_ENDIAN_STATIC_ASSERT( is_trivially_copyable<T>::value ); |
70 | 0 |
|
71 | 0 | typename integral_by_size<N>::type tmp; |
72 | 0 | std::memcpy( &tmp, &v, N ); |
73 | 0 |
|
74 | 0 | endian_reverse_inplace( tmp ); |
75 | 0 |
|
76 | 0 | std::memcpy( p, &tmp, N ); |
77 | 0 | } Unexecuted instantiation: boost::endian::detail::endian_store_impl<short, 2ul, (boost::endian::order)1, 2ul, (boost::endian::order)0>::operator()(unsigned char*, short const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned short, 2ul, (boost::endian::order)1, 2ul, (boost::endian::order)0>::operator()(unsigned char*, unsigned short const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<int, 4ul, (boost::endian::order)1, 4ul, (boost::endian::order)0>::operator()(unsigned char*, int const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned int, 4ul, (boost::endian::order)1, 4ul, (boost::endian::order)0>::operator()(unsigned char*, unsigned int const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<long, 8ul, (boost::endian::order)1, 8ul, (boost::endian::order)0>::operator()(unsigned char*, long const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned long, 8ul, (boost::endian::order)1, 8ul, (boost::endian::order)0>::operator()(unsigned char*, unsigned long const&) const |
78 | | }; |
79 | | |
80 | | // truncating store 2 -> 1 |
81 | | |
82 | | template<class T, order Order> struct endian_store_impl<T, 2, Order, 1, order::little> |
83 | | { |
84 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
85 | | { |
86 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
87 | | |
88 | | unsigned char tmp[ 2 ]; |
89 | | boost::endian::endian_store<T, 2, order::little>( tmp, v ); |
90 | | |
91 | | p[0] = tmp[0]; |
92 | | } |
93 | | }; |
94 | | |
95 | | template<class T, order Order> struct endian_store_impl<T, 2, Order, 1, order::big> |
96 | | { |
97 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
98 | | { |
99 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
100 | | |
101 | | unsigned char tmp[ 2 ]; |
102 | | boost::endian::endian_store<T, 2, order::big>( tmp, v ); |
103 | | |
104 | | p[0] = tmp[1]; |
105 | | } |
106 | | }; |
107 | | |
108 | | // truncating store 4 -> 1 |
109 | | |
110 | | template<class T, order Order> struct endian_store_impl<T, 4, Order, 1, order::little> |
111 | | { |
112 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
113 | | { |
114 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
115 | | |
116 | | unsigned char tmp[ 4 ]; |
117 | | boost::endian::endian_store<T, 4, order::little>( tmp, v ); |
118 | | |
119 | | p[0] = tmp[0]; |
120 | | } |
121 | | }; |
122 | | |
123 | | template<class T, order Order> struct endian_store_impl<T, 4, Order, 1, order::big> |
124 | | { |
125 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
126 | | { |
127 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
128 | | |
129 | | unsigned char tmp[ 4 ]; |
130 | | boost::endian::endian_store<T, 4, order::big>( tmp, v ); |
131 | | |
132 | | p[0] = tmp[3]; |
133 | | } |
134 | | }; |
135 | | |
136 | | // truncating store 4 -> 2 |
137 | | |
138 | | template<class T, order Order> struct endian_store_impl<T, 4, Order, 2, order::little> |
139 | | { |
140 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
141 | | { |
142 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
143 | | |
144 | | unsigned char tmp[ 4 ]; |
145 | | boost::endian::endian_store<T, 4, order::little>( tmp, v ); |
146 | | |
147 | | p[0] = tmp[0]; |
148 | | p[1] = tmp[1]; |
149 | | } |
150 | | }; |
151 | | |
152 | | template<class T, order Order> struct endian_store_impl<T, 4, Order, 2, order::big> |
153 | | { |
154 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
155 | | { |
156 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
157 | | |
158 | | unsigned char tmp[ 4 ]; |
159 | | boost::endian::endian_store<T, 4, order::big>( tmp, v ); |
160 | | |
161 | | p[0] = tmp[2]; |
162 | | p[1] = tmp[3]; |
163 | | } |
164 | | }; |
165 | | |
166 | | // truncating store 4 -> 3 |
167 | | |
168 | | template<class T, order Order> struct endian_store_impl<T, 4, Order, 3, order::little> |
169 | | { |
170 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
171 | 0 | { |
172 | 0 | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
173 | 0 |
|
174 | 0 | unsigned char tmp[ 4 ]; |
175 | 0 | boost::endian::endian_store<T, 4, order::little>( tmp, v ); |
176 | 0 |
|
177 | 0 | p[0] = tmp[0]; |
178 | 0 | p[1] = tmp[1]; |
179 | 0 | p[2] = tmp[2]; |
180 | 0 | } Unexecuted instantiation: boost::endian::detail::endian_store_impl<int, 4ul, (boost::endian::order)1, 3ul, (boost::endian::order)1>::operator()(unsigned char*, int const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned int, 4ul, (boost::endian::order)1, 3ul, (boost::endian::order)1>::operator()(unsigned char*, unsigned int const&) const |
181 | | }; |
182 | | |
183 | | template<class T, order Order> struct endian_store_impl<T, 4, Order, 3, order::big> |
184 | | { |
185 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
186 | 0 | { |
187 | 0 | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
188 | 0 |
|
189 | 0 | unsigned char tmp[ 4 ]; |
190 | 0 | boost::endian::endian_store<T, 4, order::big>( tmp, v ); |
191 | 0 |
|
192 | 0 | p[0] = tmp[1]; |
193 | 0 | p[1] = tmp[2]; |
194 | 0 | p[2] = tmp[3]; |
195 | 0 | } Unexecuted instantiation: boost::endian::detail::endian_store_impl<int, 4ul, (boost::endian::order)1, 3ul, (boost::endian::order)0>::operator()(unsigned char*, int const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned int, 4ul, (boost::endian::order)1, 3ul, (boost::endian::order)0>::operator()(unsigned char*, unsigned int const&) const |
196 | | }; |
197 | | |
198 | | // truncating store 8 -> 1 |
199 | | |
200 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 1, order::little> |
201 | | { |
202 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
203 | | { |
204 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
205 | | |
206 | | unsigned char tmp[ 8 ]; |
207 | | boost::endian::endian_store<T, 8, order::little>( tmp, v ); |
208 | | |
209 | | p[0] = tmp[0]; |
210 | | } |
211 | | }; |
212 | | |
213 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 1, order::big> |
214 | | { |
215 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
216 | | { |
217 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
218 | | |
219 | | unsigned char tmp[ 8 ]; |
220 | | boost::endian::endian_store<T, 8, order::big>( tmp, v ); |
221 | | |
222 | | p[0] = tmp[7]; |
223 | | } |
224 | | }; |
225 | | |
226 | | // truncating store 8 -> 2 |
227 | | |
228 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 2, order::little> |
229 | | { |
230 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
231 | | { |
232 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
233 | | |
234 | | unsigned char tmp[ 8 ]; |
235 | | boost::endian::endian_store<T, 8, order::little>( tmp, v ); |
236 | | |
237 | | p[0] = tmp[0]; |
238 | | p[1] = tmp[1]; |
239 | | } |
240 | | }; |
241 | | |
242 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 2, order::big> |
243 | | { |
244 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
245 | | { |
246 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
247 | | |
248 | | unsigned char tmp[ 8 ]; |
249 | | boost::endian::endian_store<T, 8, order::big>( tmp, v ); |
250 | | |
251 | | p[0] = tmp[6]; |
252 | | p[1] = tmp[7]; |
253 | | } |
254 | | }; |
255 | | |
256 | | // truncating store 8 -> 3 |
257 | | |
258 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 3, order::little> |
259 | | { |
260 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
261 | | { |
262 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
263 | | |
264 | | unsigned char tmp[ 8 ]; |
265 | | boost::endian::endian_store<T, 8, order::little>( tmp, v ); |
266 | | |
267 | | p[0] = tmp[0]; |
268 | | p[1] = tmp[1]; |
269 | | p[2] = tmp[2]; |
270 | | } |
271 | | }; |
272 | | |
273 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 3, order::big> |
274 | | { |
275 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
276 | | { |
277 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
278 | | |
279 | | unsigned char tmp[ 8 ]; |
280 | | boost::endian::endian_store<T, 8, order::big>( tmp, v ); |
281 | | |
282 | | p[0] = tmp[5]; |
283 | | p[1] = tmp[6]; |
284 | | p[2] = tmp[7]; |
285 | | } |
286 | | }; |
287 | | |
288 | | // truncating store 8 -> 4 |
289 | | |
290 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 4, order::little> |
291 | | { |
292 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
293 | | { |
294 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
295 | | |
296 | | unsigned char tmp[ 8 ]; |
297 | | boost::endian::endian_store<T, 8, order::little>( tmp, v ); |
298 | | |
299 | | p[0] = tmp[0]; |
300 | | p[1] = tmp[1]; |
301 | | p[2] = tmp[2]; |
302 | | p[3] = tmp[3]; |
303 | | } |
304 | | }; |
305 | | |
306 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 4, order::big> |
307 | | { |
308 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
309 | | { |
310 | | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
311 | | |
312 | | unsigned char tmp[ 8 ]; |
313 | | boost::endian::endian_store<T, 8, order::big>( tmp, v ); |
314 | | |
315 | | p[0] = tmp[4]; |
316 | | p[1] = tmp[5]; |
317 | | p[2] = tmp[6]; |
318 | | p[3] = tmp[7]; |
319 | | } |
320 | | }; |
321 | | |
322 | | // truncating store 8 -> 5 |
323 | | |
324 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 5, order::little> |
325 | | { |
326 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
327 | 0 | { |
328 | 0 | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
329 | 0 |
|
330 | 0 | unsigned char tmp[ 8 ]; |
331 | 0 | boost::endian::endian_store<T, 8, order::little>( tmp, v ); |
332 | 0 |
|
333 | 0 | p[0] = tmp[0]; |
334 | 0 | p[1] = tmp[1]; |
335 | 0 | p[2] = tmp[2]; |
336 | 0 | p[3] = tmp[3]; |
337 | 0 | p[4] = tmp[4]; |
338 | 0 | } Unexecuted instantiation: boost::endian::detail::endian_store_impl<long, 8ul, (boost::endian::order)1, 5ul, (boost::endian::order)1>::operator()(unsigned char*, long const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned long, 8ul, (boost::endian::order)1, 5ul, (boost::endian::order)1>::operator()(unsigned char*, unsigned long const&) const |
339 | | }; |
340 | | |
341 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 5, order::big> |
342 | | { |
343 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
344 | 0 | { |
345 | 0 | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
346 | 0 |
|
347 | 0 | unsigned char tmp[ 8 ]; |
348 | 0 | boost::endian::endian_store<T, 8, order::big>( tmp, v ); |
349 | 0 |
|
350 | 0 | p[0] = tmp[3]; |
351 | 0 | p[1] = tmp[4]; |
352 | 0 | p[2] = tmp[5]; |
353 | 0 | p[3] = tmp[6]; |
354 | 0 | p[4] = tmp[7]; |
355 | 0 | } Unexecuted instantiation: boost::endian::detail::endian_store_impl<long, 8ul, (boost::endian::order)1, 5ul, (boost::endian::order)0>::operator()(unsigned char*, long const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned long, 8ul, (boost::endian::order)1, 5ul, (boost::endian::order)0>::operator()(unsigned char*, unsigned long const&) const |
356 | | }; |
357 | | |
358 | | // truncating store 8 -> 6 |
359 | | |
360 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 6, order::little> |
361 | | { |
362 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
363 | 0 | { |
364 | 0 | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
365 | 0 |
|
366 | 0 | unsigned char tmp[ 8 ]; |
367 | 0 | boost::endian::endian_store<T, 8, order::little>( tmp, v ); |
368 | 0 |
|
369 | 0 | p[0] = tmp[0]; |
370 | 0 | p[1] = tmp[1]; |
371 | 0 | p[2] = tmp[2]; |
372 | 0 | p[3] = tmp[3]; |
373 | 0 | p[4] = tmp[4]; |
374 | 0 | p[5] = tmp[5]; |
375 | 0 | } Unexecuted instantiation: boost::endian::detail::endian_store_impl<long, 8ul, (boost::endian::order)1, 6ul, (boost::endian::order)1>::operator()(unsigned char*, long const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned long, 8ul, (boost::endian::order)1, 6ul, (boost::endian::order)1>::operator()(unsigned char*, unsigned long const&) const |
376 | | }; |
377 | | |
378 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 6, order::big> |
379 | | { |
380 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
381 | 0 | { |
382 | 0 | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
383 | 0 |
|
384 | 0 | unsigned char tmp[ 8 ]; |
385 | 0 | boost::endian::endian_store<T, 8, order::big>( tmp, v ); |
386 | 0 |
|
387 | 0 | p[0] = tmp[2]; |
388 | 0 | p[1] = tmp[3]; |
389 | 0 | p[2] = tmp[4]; |
390 | 0 | p[3] = tmp[5]; |
391 | 0 | p[4] = tmp[6]; |
392 | 0 | p[5] = tmp[7]; |
393 | 0 | } Unexecuted instantiation: boost::endian::detail::endian_store_impl<long, 8ul, (boost::endian::order)1, 6ul, (boost::endian::order)0>::operator()(unsigned char*, long const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned long, 8ul, (boost::endian::order)1, 6ul, (boost::endian::order)0>::operator()(unsigned char*, unsigned long const&) const |
394 | | }; |
395 | | |
396 | | // truncating store 8 -> 7 |
397 | | |
398 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 7, order::little> |
399 | | { |
400 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
401 | 0 | { |
402 | 0 | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
403 | 0 |
|
404 | 0 | unsigned char tmp[ 8 ]; |
405 | 0 | boost::endian::endian_store<T, 8, order::little>( tmp, v ); |
406 | 0 |
|
407 | 0 | p[0] = tmp[0]; |
408 | 0 | p[1] = tmp[1]; |
409 | 0 | p[2] = tmp[2]; |
410 | 0 | p[3] = tmp[3]; |
411 | 0 | p[4] = tmp[4]; |
412 | 0 | p[5] = tmp[5]; |
413 | 0 | p[6] = tmp[6]; |
414 | 0 | } Unexecuted instantiation: boost::endian::detail::endian_store_impl<long, 8ul, (boost::endian::order)1, 7ul, (boost::endian::order)1>::operator()(unsigned char*, long const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned long, 8ul, (boost::endian::order)1, 7ul, (boost::endian::order)1>::operator()(unsigned char*, unsigned long const&) const |
415 | | }; |
416 | | |
417 | | template<class T, order Order> struct endian_store_impl<T, 8, Order, 7, order::big> |
418 | | { |
419 | | inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT |
420 | 0 | { |
421 | 0 | BOOST_ENDIAN_STATIC_ASSERT( std::is_integral<T>::value || std::is_enum<T>::value ); |
422 | 0 |
|
423 | 0 | unsigned char tmp[ 8 ]; |
424 | 0 | boost::endian::endian_store<T, 8, order::big>( tmp, v ); |
425 | 0 |
|
426 | 0 | p[0] = tmp[1]; |
427 | 0 | p[1] = tmp[2]; |
428 | 0 | p[2] = tmp[3]; |
429 | 0 | p[3] = tmp[4]; |
430 | 0 | p[4] = tmp[5]; |
431 | 0 | p[5] = tmp[6]; |
432 | 0 | p[6] = tmp[7]; |
433 | 0 | } Unexecuted instantiation: boost::endian::detail::endian_store_impl<long, 8ul, (boost::endian::order)1, 7ul, (boost::endian::order)0>::operator()(unsigned char*, long const&) const Unexecuted instantiation: boost::endian::detail::endian_store_impl<unsigned long, 8ul, (boost::endian::order)1, 7ul, (boost::endian::order)0>::operator()(unsigned char*, unsigned long const&) const |
434 | | }; |
435 | | |
436 | | } // namespace detail |
437 | | |
438 | | } // namespace endian |
439 | | } // namespace boost |
440 | | |
441 | | #endif // BOOST_ENDIAN_DETAIL_ENDIAN_STORE_HPP_INCLUDED |