conversion.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. // boost/endian/conversion.hpp -------------------------------------------------------//
  2. // Copyright Beman Dawes 2010, 2011, 2014
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // http://www.boost.org/LICENSE_1_0.txt
  5. #ifndef BOOST_ENDIAN_CONVERSION_HPP
  6. #define BOOST_ENDIAN_CONVERSION_HPP
  7. #include <boost/endian/detail/endian_reverse.hpp>
  8. #include <boost/endian/detail/endian_load.hpp>
  9. #include <boost/endian/detail/endian_store.hpp>
  10. #include <boost/endian/detail/order.hpp>
  11. #include <boost/type_traits/is_class.hpp>
  12. #include <boost/type_traits/is_integral.hpp>
  13. #include <boost/type_traits/is_same.hpp>
  14. #include <boost/type_traits/integral_constant.hpp>
  15. #include <boost/predef/other/endian.h>
  16. #include <boost/static_assert.hpp>
  17. #include <boost/cstdint.hpp>
  18. #include <boost/config.hpp>
  19. //------------------------------------- synopsis ---------------------------------------//
  20. namespace boost
  21. {
  22. namespace endian
  23. {
  24. //--------------------------------------------------------------------------------------//
  25. // //
  26. // return-by-value interfaces //
  27. // suggested by Phil Endecott //
  28. // //
  29. // user-defined types (UDTs) //
  30. // //
  31. // All return-by-value conversion function templates are required to be implemented in //
  32. // terms of an unqualified call to "endian_reverse(x)", a function returning the //
  33. // value of x with endianness reversed. This provides a customization point for any //
  34. // UDT that provides a "endian_reverse" free-function meeting the requirements. //
  35. // It must be defined in the same namespace as the UDT itself so that it will be found //
  36. // by argument dependent lookup (ADL). //
  37. // //
  38. //--------------------------------------------------------------------------------------//
  39. // reverse byte order
  40. // requires T to be a non-bool integral type
  41. // in detail/endian_reverse.hpp
  42. template<class T> inline BOOST_CONSTEXPR T endian_reverse( T x ) BOOST_NOEXCEPT;
  43. // reverse byte order unless native endianness is big
  44. template <class EndianReversible >
  45. inline BOOST_CONSTEXPR EndianReversible big_to_native(EndianReversible x) BOOST_NOEXCEPT;
  46. // Returns: x if native endian order is big, otherwise endian_reverse(x)
  47. template <class EndianReversible >
  48. inline BOOST_CONSTEXPR EndianReversible native_to_big(EndianReversible x) BOOST_NOEXCEPT;
  49. // Returns: x if native endian order is big, otherwise endian_reverse(x)
  50. // reverse byte order unless native endianness is little
  51. template <class EndianReversible >
  52. inline BOOST_CONSTEXPR EndianReversible little_to_native(EndianReversible x) BOOST_NOEXCEPT;
  53. // Returns: x if native endian order is little, otherwise endian_reverse(x)
  54. template <class EndianReversible >
  55. inline BOOST_CONSTEXPR EndianReversible native_to_little(EndianReversible x) BOOST_NOEXCEPT;
  56. // Returns: x if native endian order is little, otherwise endian_reverse(x)
  57. // generic conditional reverse byte order
  58. template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To,
  59. class EndianReversible>
  60. inline BOOST_CONSTEXPR EndianReversible conditional_reverse(EndianReversible from) BOOST_NOEXCEPT;
  61. // Returns: If From == To have different values, from.
  62. // Otherwise endian_reverse(from).
  63. // Remarks: The From == To test, and as a consequence which form the return takes, is
  64. // is determined at compile time.
  65. // runtime conditional reverse byte order
  66. template <class EndianReversible >
  67. inline BOOST_CONSTEXPR EndianReversible conditional_reverse(EndianReversible from,
  68. BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order)
  69. BOOST_NOEXCEPT;
  70. // Returns: from_order == to_order ? from : endian_reverse(from).
  71. //------------------------------------------------------------------------------------//
  72. // Q: What happened to bswap, htobe, and the other synonym functions based on names
  73. // popularized by BSD, OS X, and Linux?
  74. // A: Turned out these may be implemented as macros on some systems. Ditto POSIX names
  75. // for such functionality. Since macros would cause endless problems with functions
  76. // of the same names, and these functions are just synonyms anyhow, they have been
  77. // removed.
  78. //------------------------------------------------------------------------------------//
  79. // //
  80. // reverse in place interfaces //
  81. // //
  82. // user-defined types (UDTs) //
  83. // //
  84. // All reverse in place function templates are required to be implemented in terms //
  85. // of an unqualified call to "endian_reverse_inplace(x)", a function reversing //
  86. // the endianness of x, which is a non-const reference. This provides a //
  87. // customization point for any UDT that provides a "reverse_inplace" free-function //
  88. // meeting the requirements. The free-function must be declared in the same //
  89. // namespace as the UDT itself so that it will be found by argument-dependent //
  90. // lookup (ADL). //
  91. // //
  92. //------------------------------------------------------------------------------------//
  93. // reverse in place
  94. // in detail/endian_reverse.hpp
  95. template <class EndianReversible>
  96. inline void endian_reverse_inplace(EndianReversible& x) BOOST_NOEXCEPT;
  97. // Effects: x = endian_reverse(x)
  98. // reverse in place unless native endianness is big
  99. template <class EndianReversibleInplace>
  100. inline void big_to_native_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
  101. // Effects: none if native byte-order is big, otherwise endian_reverse_inplace(x)
  102. template <class EndianReversibleInplace>
  103. inline void native_to_big_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
  104. // Effects: none if native byte-order is big, otherwise endian_reverse_inplace(x)
  105. // reverse in place unless native endianness is little
  106. template <class EndianReversibleInplace>
  107. inline void little_to_native_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
  108. // Effects: none if native byte-order is little, otherwise endian_reverse_inplace(x);
  109. template <class EndianReversibleInplace>
  110. inline void native_to_little_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
  111. // Effects: none if native byte-order is little, otherwise endian_reverse_inplace(x);
  112. // generic conditional reverse in place
  113. template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To,
  114. class EndianReversibleInplace>
  115. inline void conditional_reverse_inplace(EndianReversibleInplace& x) BOOST_NOEXCEPT;
  116. // runtime reverse in place
  117. template <class EndianReversibleInplace>
  118. inline void conditional_reverse_inplace(EndianReversibleInplace& x,
  119. BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order)
  120. BOOST_NOEXCEPT;
  121. //----------------------------------- end synopsis -------------------------------------//
  122. namespace detail
  123. {
  124. template<class T> struct is_endian_reversible: boost::integral_constant<bool,
  125. boost::is_class<T>::value || ( boost::is_integral<T>::value && !boost::is_same<T, bool>::value )>
  126. {
  127. };
  128. } // namespace detail
  129. template <class EndianReversible>
  130. inline BOOST_CONSTEXPR EndianReversible big_to_native( EndianReversible x ) BOOST_NOEXCEPT
  131. {
  132. BOOST_STATIC_ASSERT( detail::is_endian_reversible<EndianReversible>::value );
  133. #if BOOST_ENDIAN_BIG_BYTE
  134. return x;
  135. #else
  136. return endian_reverse(x);
  137. #endif
  138. }
  139. template <class EndianReversible>
  140. inline BOOST_CONSTEXPR EndianReversible native_to_big( EndianReversible x ) BOOST_NOEXCEPT
  141. {
  142. BOOST_STATIC_ASSERT( detail::is_endian_reversible<EndianReversible>::value );
  143. #if BOOST_ENDIAN_BIG_BYTE
  144. return x;
  145. #else
  146. return endian_reverse(x);
  147. #endif
  148. }
  149. template <class EndianReversible>
  150. inline BOOST_CONSTEXPR EndianReversible little_to_native( EndianReversible x ) BOOST_NOEXCEPT
  151. {
  152. BOOST_STATIC_ASSERT( detail::is_endian_reversible<EndianReversible>::value );
  153. #if BOOST_ENDIAN_LITTLE_BYTE
  154. return x;
  155. #else
  156. return endian_reverse(x);
  157. #endif
  158. }
  159. template <class EndianReversible>
  160. inline BOOST_CONSTEXPR EndianReversible native_to_little( EndianReversible x ) BOOST_NOEXCEPT
  161. {
  162. BOOST_STATIC_ASSERT( detail::is_endian_reversible<EndianReversible>::value );
  163. #if BOOST_ENDIAN_LITTLE_BYTE
  164. return x;
  165. #else
  166. return endian_reverse(x);
  167. #endif
  168. }
  169. namespace detail
  170. {
  171. template<class EndianReversible>
  172. inline BOOST_CONSTEXPR EndianReversible conditional_reverse_impl( EndianReversible x, boost::true_type ) BOOST_NOEXCEPT
  173. {
  174. return x;
  175. }
  176. template<class EndianReversible>
  177. inline BOOST_CONSTEXPR EndianReversible conditional_reverse_impl( EndianReversible x, boost::false_type ) BOOST_NOEXCEPT
  178. {
  179. return endian_reverse( x );
  180. }
  181. } // namespace detail
  182. // generic conditional reverse
  183. template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class EndianReversible>
  184. inline BOOST_CONSTEXPR EndianReversible conditional_reverse( EndianReversible x ) BOOST_NOEXCEPT
  185. {
  186. BOOST_STATIC_ASSERT( detail::is_endian_reversible<EndianReversible>::value );
  187. return detail::conditional_reverse_impl( x, boost::integral_constant<bool, From == To>() );
  188. }
  189. // runtime conditional reverse
  190. template <class EndianReversible>
  191. inline BOOST_CONSTEXPR EndianReversible conditional_reverse( EndianReversible x,
  192. BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order ) BOOST_NOEXCEPT
  193. {
  194. BOOST_STATIC_ASSERT( detail::is_endian_reversible<EndianReversible>::value );
  195. return from_order == to_order? x: endian_reverse( x );
  196. }
  197. //--------------------------------------------------------------------------------------//
  198. // reverse-in-place implementation //
  199. //--------------------------------------------------------------------------------------//
  200. namespace detail
  201. {
  202. template<class T> struct is_endian_reversible_inplace: boost::integral_constant<bool,
  203. boost::is_class<T>::value || ( boost::is_integral<T>::value && !boost::is_same<T, bool>::value )>
  204. {
  205. };
  206. } // namespace detail
  207. #if BOOST_ENDIAN_BIG_BYTE
  208. template <class EndianReversibleInplace>
  209. inline void big_to_native_inplace( EndianReversibleInplace& ) BOOST_NOEXCEPT
  210. {
  211. BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
  212. }
  213. #else
  214. template <class EndianReversibleInplace>
  215. inline void big_to_native_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
  216. {
  217. BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
  218. endian_reverse_inplace( x );
  219. }
  220. #endif
  221. #if BOOST_ENDIAN_BIG_BYTE
  222. template <class EndianReversibleInplace>
  223. inline void native_to_big_inplace( EndianReversibleInplace& ) BOOST_NOEXCEPT
  224. {
  225. BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
  226. }
  227. #else
  228. template <class EndianReversibleInplace>
  229. inline void native_to_big_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
  230. {
  231. BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
  232. endian_reverse_inplace( x );
  233. }
  234. #endif
  235. #if BOOST_ENDIAN_LITTLE_BYTE
  236. template <class EndianReversibleInplace>
  237. inline void little_to_native_inplace( EndianReversibleInplace& ) BOOST_NOEXCEPT
  238. {
  239. BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
  240. }
  241. #else
  242. template <class EndianReversibleInplace>
  243. inline void little_to_native_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
  244. {
  245. BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
  246. endian_reverse_inplace( x );
  247. }
  248. #endif
  249. #if BOOST_ENDIAN_LITTLE_BYTE
  250. template <class EndianReversibleInplace>
  251. inline void native_to_little_inplace( EndianReversibleInplace& ) BOOST_NOEXCEPT
  252. {
  253. BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
  254. }
  255. #else
  256. template <class EndianReversibleInplace>
  257. inline void native_to_little_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
  258. {
  259. BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
  260. endian_reverse_inplace( x );
  261. }
  262. #endif
  263. namespace detail
  264. {
  265. template<class EndianReversibleInplace>
  266. inline void conditional_reverse_inplace_impl( EndianReversibleInplace&, boost::true_type ) BOOST_NOEXCEPT
  267. {
  268. }
  269. template<class EndianReversibleInplace>
  270. inline void conditional_reverse_inplace_impl( EndianReversibleInplace& x, boost::false_type ) BOOST_NOEXCEPT
  271. {
  272. endian_reverse_inplace( x );
  273. }
  274. } // namespace detail
  275. // generic conditional reverse in place
  276. template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class EndianReversibleInplace>
  277. inline void conditional_reverse_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
  278. {
  279. BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
  280. detail::conditional_reverse_inplace_impl( x, boost::integral_constant<bool, From == To>() );
  281. }
  282. // runtime reverse in place
  283. template <class EndianReversibleInplace>
  284. inline void conditional_reverse_inplace( EndianReversibleInplace& x,
  285. BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order ) BOOST_NOEXCEPT
  286. {
  287. BOOST_STATIC_ASSERT( detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
  288. if( from_order != to_order )
  289. {
  290. endian_reverse_inplace( x );
  291. }
  292. }
  293. // load/store convenience functions
  294. // load 16
  295. inline boost::int16_t load_little_s16( unsigned char const * p ) BOOST_NOEXCEPT
  296. {
  297. return boost::endian::endian_load<boost::int16_t, 2, order::little>( p );
  298. }
  299. inline boost::uint16_t load_little_u16( unsigned char const * p ) BOOST_NOEXCEPT
  300. {
  301. return boost::endian::endian_load<boost::uint16_t, 2, order::little>( p );
  302. }
  303. inline boost::int16_t load_big_s16( unsigned char const * p ) BOOST_NOEXCEPT
  304. {
  305. return boost::endian::endian_load<boost::int16_t, 2, order::big>( p );
  306. }
  307. inline boost::uint16_t load_big_u16( unsigned char const * p ) BOOST_NOEXCEPT
  308. {
  309. return boost::endian::endian_load<boost::uint16_t, 2, order::big>( p );
  310. }
  311. // load 24
  312. inline boost::int32_t load_little_s24( unsigned char const * p ) BOOST_NOEXCEPT
  313. {
  314. return boost::endian::endian_load<boost::int32_t, 3, order::little>( p );
  315. }
  316. inline boost::uint32_t load_little_u24( unsigned char const * p ) BOOST_NOEXCEPT
  317. {
  318. return boost::endian::endian_load<boost::uint32_t, 3, order::little>( p );
  319. }
  320. inline boost::int32_t load_big_s24( unsigned char const * p ) BOOST_NOEXCEPT
  321. {
  322. return boost::endian::endian_load<boost::int32_t, 3, order::big>( p );
  323. }
  324. inline boost::uint32_t load_big_u24( unsigned char const * p ) BOOST_NOEXCEPT
  325. {
  326. return boost::endian::endian_load<boost::uint32_t, 3, order::big>( p );
  327. }
  328. // load 32
  329. inline boost::int32_t load_little_s32( unsigned char const * p ) BOOST_NOEXCEPT
  330. {
  331. return boost::endian::endian_load<boost::int32_t, 4, order::little>( p );
  332. }
  333. inline boost::uint32_t load_little_u32( unsigned char const * p ) BOOST_NOEXCEPT
  334. {
  335. return boost::endian::endian_load<boost::uint32_t, 4, order::little>( p );
  336. }
  337. inline boost::int32_t load_big_s32( unsigned char const * p ) BOOST_NOEXCEPT
  338. {
  339. return boost::endian::endian_load<boost::int32_t, 4, order::big>( p );
  340. }
  341. inline boost::uint32_t load_big_u32( unsigned char const * p ) BOOST_NOEXCEPT
  342. {
  343. return boost::endian::endian_load<boost::uint32_t, 4, order::big>( p );
  344. }
  345. // load 40
  346. inline boost::int64_t load_little_s40( unsigned char const * p ) BOOST_NOEXCEPT
  347. {
  348. return boost::endian::endian_load<boost::int64_t, 5, order::little>( p );
  349. }
  350. inline boost::uint64_t load_little_u40( unsigned char const * p ) BOOST_NOEXCEPT
  351. {
  352. return boost::endian::endian_load<boost::uint64_t, 5, order::little>( p );
  353. }
  354. inline boost::int64_t load_big_s40( unsigned char const * p ) BOOST_NOEXCEPT
  355. {
  356. return boost::endian::endian_load<boost::int64_t, 5, order::big>( p );
  357. }
  358. inline boost::uint64_t load_big_u40( unsigned char const * p ) BOOST_NOEXCEPT
  359. {
  360. return boost::endian::endian_load<boost::uint64_t, 5, order::big>( p );
  361. }
  362. // load 48
  363. inline boost::int64_t load_little_s48( unsigned char const * p ) BOOST_NOEXCEPT
  364. {
  365. return boost::endian::endian_load<boost::int64_t, 6, order::little>( p );
  366. }
  367. inline boost::uint64_t load_little_u48( unsigned char const * p ) BOOST_NOEXCEPT
  368. {
  369. return boost::endian::endian_load<boost::uint64_t, 6, order::little>( p );
  370. }
  371. inline boost::int64_t load_big_s48( unsigned char const * p ) BOOST_NOEXCEPT
  372. {
  373. return boost::endian::endian_load<boost::int64_t, 6, order::big>( p );
  374. }
  375. inline boost::uint64_t load_big_u48( unsigned char const * p ) BOOST_NOEXCEPT
  376. {
  377. return boost::endian::endian_load<boost::uint64_t, 6, order::big>( p );
  378. }
  379. // load 56
  380. inline boost::int64_t load_little_s56( unsigned char const * p ) BOOST_NOEXCEPT
  381. {
  382. return boost::endian::endian_load<boost::int64_t, 7, order::little>( p );
  383. }
  384. inline boost::uint64_t load_little_u56( unsigned char const * p ) BOOST_NOEXCEPT
  385. {
  386. return boost::endian::endian_load<boost::uint64_t, 7, order::little>( p );
  387. }
  388. inline boost::int64_t load_big_s56( unsigned char const * p ) BOOST_NOEXCEPT
  389. {
  390. return boost::endian::endian_load<boost::int64_t, 7, order::big>( p );
  391. }
  392. inline boost::uint64_t load_big_u56( unsigned char const * p ) BOOST_NOEXCEPT
  393. {
  394. return boost::endian::endian_load<boost::uint64_t, 7, order::big>( p );
  395. }
  396. // load 64
  397. inline boost::int64_t load_little_s64( unsigned char const * p ) BOOST_NOEXCEPT
  398. {
  399. return boost::endian::endian_load<boost::int64_t, 8, order::little>( p );
  400. }
  401. inline boost::uint64_t load_little_u64( unsigned char const * p ) BOOST_NOEXCEPT
  402. {
  403. return boost::endian::endian_load<boost::uint64_t, 8, order::little>( p );
  404. }
  405. inline boost::int64_t load_big_s64( unsigned char const * p ) BOOST_NOEXCEPT
  406. {
  407. return boost::endian::endian_load<boost::int64_t, 8, order::big>( p );
  408. }
  409. inline boost::uint64_t load_big_u64( unsigned char const * p ) BOOST_NOEXCEPT
  410. {
  411. return boost::endian::endian_load<boost::uint64_t, 8, order::big>( p );
  412. }
  413. // store 16
  414. inline void store_little_s16( unsigned char * p, boost::int16_t v )
  415. {
  416. boost::endian::endian_store<boost::int16_t, 2, order::little>( p, v );
  417. }
  418. inline void store_little_u16( unsigned char * p, boost::uint16_t v )
  419. {
  420. boost::endian::endian_store<boost::uint16_t, 2, order::little>( p, v );
  421. }
  422. inline void store_big_s16( unsigned char * p, boost::int16_t v )
  423. {
  424. boost::endian::endian_store<boost::int16_t, 2, order::big>( p, v );
  425. }
  426. inline void store_big_u16( unsigned char * p, boost::uint16_t v )
  427. {
  428. boost::endian::endian_store<boost::uint16_t, 2, order::big>( p, v );
  429. }
  430. // store 24
  431. inline void store_little_s24( unsigned char * p, boost::int32_t v )
  432. {
  433. boost::endian::endian_store<boost::int32_t, 3, order::little>( p, v );
  434. }
  435. inline void store_little_u24( unsigned char * p, boost::uint32_t v )
  436. {
  437. boost::endian::endian_store<boost::uint32_t, 3, order::little>( p, v );
  438. }
  439. inline void store_big_s24( unsigned char * p, boost::int32_t v )
  440. {
  441. boost::endian::endian_store<boost::int32_t, 3, order::big>( p, v );
  442. }
  443. inline void store_big_u24( unsigned char * p, boost::uint32_t v )
  444. {
  445. boost::endian::endian_store<boost::uint32_t, 3, order::big>( p, v );
  446. }
  447. // store 32
  448. inline void store_little_s32( unsigned char * p, boost::int32_t v )
  449. {
  450. boost::endian::endian_store<boost::int32_t, 4, order::little>( p, v );
  451. }
  452. inline void store_little_u32( unsigned char * p, boost::uint32_t v )
  453. {
  454. boost::endian::endian_store<boost::uint32_t, 4, order::little>( p, v );
  455. }
  456. inline void store_big_s32( unsigned char * p, boost::int32_t v )
  457. {
  458. boost::endian::endian_store<boost::int32_t, 4, order::big>( p, v );
  459. }
  460. inline void store_big_u32( unsigned char * p, boost::uint32_t v )
  461. {
  462. boost::endian::endian_store<boost::uint32_t, 4, order::big>( p, v );
  463. }
  464. // store 40
  465. inline void store_little_s40( unsigned char * p, boost::int64_t v )
  466. {
  467. boost::endian::endian_store<boost::int64_t, 5, order::little>( p, v );
  468. }
  469. inline void store_little_u40( unsigned char * p, boost::uint64_t v )
  470. {
  471. boost::endian::endian_store<boost::uint64_t, 5, order::little>( p, v );
  472. }
  473. inline void store_big_s40( unsigned char * p, boost::int64_t v )
  474. {
  475. boost::endian::endian_store<boost::int64_t, 5, order::big>( p, v );
  476. }
  477. inline void store_big_u40( unsigned char * p, boost::uint64_t v )
  478. {
  479. boost::endian::endian_store<boost::uint64_t, 5, order::big>( p, v );
  480. }
  481. // store 48
  482. inline void store_little_s48( unsigned char * p, boost::int64_t v )
  483. {
  484. boost::endian::endian_store<boost::int64_t, 6, order::little>( p, v );
  485. }
  486. inline void store_little_u48( unsigned char * p, boost::uint64_t v )
  487. {
  488. boost::endian::endian_store<boost::uint64_t, 6, order::little>( p, v );
  489. }
  490. inline void store_big_s48( unsigned char * p, boost::int64_t v )
  491. {
  492. boost::endian::endian_store<boost::int64_t, 6, order::big>( p, v );
  493. }
  494. inline void store_big_u48( unsigned char * p, boost::uint64_t v )
  495. {
  496. boost::endian::endian_store<boost::uint64_t, 6, order::big>( p, v );
  497. }
  498. // store 56
  499. inline void store_little_s56( unsigned char * p, boost::int64_t v )
  500. {
  501. boost::endian::endian_store<boost::int64_t, 7, order::little>( p, v );
  502. }
  503. inline void store_little_u56( unsigned char * p, boost::uint64_t v )
  504. {
  505. boost::endian::endian_store<boost::uint64_t, 7, order::little>( p, v );
  506. }
  507. inline void store_big_s56( unsigned char * p, boost::int64_t v )
  508. {
  509. boost::endian::endian_store<boost::int64_t, 7, order::big>( p, v );
  510. }
  511. inline void store_big_u56( unsigned char * p, boost::uint64_t v )
  512. {
  513. boost::endian::endian_store<boost::uint64_t, 7, order::big>( p, v );
  514. }
  515. // store 64
  516. inline void store_little_s64( unsigned char * p, boost::int64_t v )
  517. {
  518. boost::endian::endian_store<boost::int64_t, 8, order::little>( p, v );
  519. }
  520. inline void store_little_u64( unsigned char * p, boost::uint64_t v )
  521. {
  522. boost::endian::endian_store<boost::uint64_t, 8, order::little>( p, v );
  523. }
  524. inline void store_big_s64( unsigned char * p, boost::int64_t v )
  525. {
  526. boost::endian::endian_store<boost::int64_t, 8, order::big>( p, v );
  527. }
  528. inline void store_big_u64( unsigned char * p, boost::uint64_t v )
  529. {
  530. boost::endian::endian_store<boost::uint64_t, 8, order::big>( p, v );
  531. }
  532. } // namespace endian
  533. } // namespace boost
  534. #endif // BOOST_ENDIAN_CONVERSION_HPP