buffers.hpp 20 KB

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