endian.hpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // boost/endian/endian.hpp -----------------------------------------------------------//
  2. // Copyright Beman Dawes 2015
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. // See library home page at http://www.boost.org/libs/endian
  6. #ifndef BOOST_ENDIAN_ENDIAN_HPP
  7. #define BOOST_ENDIAN_ENDIAN_HPP
  8. #ifndef BOOST_ENDIAN_DEPRECATED_NAMES
  9. # error "<boost/endian/endian.hpp> is deprecated. Define BOOST_ENDIAN_DEPRECATED_NAMES to use."
  10. #endif
  11. #include <boost/config/header_deprecated.hpp>
  12. BOOST_HEADER_DEPRECATED( "<boost/endian/arithmetic.hpp>" )
  13. #include <boost/endian/arithmetic.hpp>
  14. #include <boost/config.hpp>
  15. namespace boost
  16. {
  17. namespace endian
  18. {
  19. typedef order endianness;
  20. typedef align alignment;
  21. # ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES
  22. template <BOOST_SCOPED_ENUM(order) Order, class T, std::size_t n_bits,
  23. BOOST_SCOPED_ENUM(align) Align = align::no>
  24. using endian = endian_arithmetic<Order, T, n_bits, Align>;
  25. # endif
  26. // unaligned big endian signed integer types
  27. typedef endian_arithmetic< order::big, int_least8_t, 8 > big8_t;
  28. typedef endian_arithmetic< order::big, int_least16_t, 16 > big16_t;
  29. typedef endian_arithmetic< order::big, int_least32_t, 24 > big24_t;
  30. typedef endian_arithmetic< order::big, int_least32_t, 32 > big32_t;
  31. typedef endian_arithmetic< order::big, int_least64_t, 40 > big40_t;
  32. typedef endian_arithmetic< order::big, int_least64_t, 48 > big48_t;
  33. typedef endian_arithmetic< order::big, int_least64_t, 56 > big56_t;
  34. typedef endian_arithmetic< order::big, int_least64_t, 64 > big64_t;
  35. // unaligned big endian_arithmetic unsigned integer types
  36. typedef endian_arithmetic< order::big, uint_least8_t, 8 > ubig8_t;
  37. typedef endian_arithmetic< order::big, uint_least16_t, 16 > ubig16_t;
  38. typedef endian_arithmetic< order::big, uint_least32_t, 24 > ubig24_t;
  39. typedef endian_arithmetic< order::big, uint_least32_t, 32 > ubig32_t;
  40. typedef endian_arithmetic< order::big, uint_least64_t, 40 > ubig40_t;
  41. typedef endian_arithmetic< order::big, uint_least64_t, 48 > ubig48_t;
  42. typedef endian_arithmetic< order::big, uint_least64_t, 56 > ubig56_t;
  43. typedef endian_arithmetic< order::big, uint_least64_t, 64 > ubig64_t;
  44. // unaligned little endian_arithmetic signed integer types
  45. typedef endian_arithmetic< order::little, int_least8_t, 8 > little8_t;
  46. typedef endian_arithmetic< order::little, int_least16_t, 16 > little16_t;
  47. typedef endian_arithmetic< order::little, int_least32_t, 24 > little24_t;
  48. typedef endian_arithmetic< order::little, int_least32_t, 32 > little32_t;
  49. typedef endian_arithmetic< order::little, int_least64_t, 40 > little40_t;
  50. typedef endian_arithmetic< order::little, int_least64_t, 48 > little48_t;
  51. typedef endian_arithmetic< order::little, int_least64_t, 56 > little56_t;
  52. typedef endian_arithmetic< order::little, int_least64_t, 64 > little64_t;
  53. // unaligned little endian_arithmetic unsigned integer types
  54. typedef endian_arithmetic< order::little, uint_least8_t, 8 > ulittle8_t;
  55. typedef endian_arithmetic< order::little, uint_least16_t, 16 > ulittle16_t;
  56. typedef endian_arithmetic< order::little, uint_least32_t, 24 > ulittle24_t;
  57. typedef endian_arithmetic< order::little, uint_least32_t, 32 > ulittle32_t;
  58. typedef endian_arithmetic< order::little, uint_least64_t, 40 > ulittle40_t;
  59. typedef endian_arithmetic< order::little, uint_least64_t, 48 > ulittle48_t;
  60. typedef endian_arithmetic< order::little, uint_least64_t, 56 > ulittle56_t;
  61. typedef endian_arithmetic< order::little, uint_least64_t, 64 > ulittle64_t;
  62. // unaligned native endian_arithmetic signed integer types
  63. typedef endian_arithmetic< order::native, int_least8_t, 8 > native8_t;
  64. typedef endian_arithmetic< order::native, int_least16_t, 16 > native16_t;
  65. typedef endian_arithmetic< order::native, int_least32_t, 24 > native24_t;
  66. typedef endian_arithmetic< order::native, int_least32_t, 32 > native32_t;
  67. typedef endian_arithmetic< order::native, int_least64_t, 40 > native40_t;
  68. typedef endian_arithmetic< order::native, int_least64_t, 48 > native48_t;
  69. typedef endian_arithmetic< order::native, int_least64_t, 56 > native56_t;
  70. typedef endian_arithmetic< order::native, int_least64_t, 64 > native64_t;
  71. // unaligned native endian_arithmetic unsigned integer types
  72. typedef endian_arithmetic< order::native, uint_least8_t, 8 > unative8_t;
  73. typedef endian_arithmetic< order::native, uint_least16_t, 16 > unative16_t;
  74. typedef endian_arithmetic< order::native, uint_least32_t, 24 > unative24_t;
  75. typedef endian_arithmetic< order::native, uint_least32_t, 32 > unative32_t;
  76. typedef endian_arithmetic< order::native, uint_least64_t, 40 > unative40_t;
  77. typedef endian_arithmetic< order::native, uint_least64_t, 48 > unative48_t;
  78. typedef endian_arithmetic< order::native, uint_least64_t, 56 > unative56_t;
  79. typedef endian_arithmetic< order::native, uint_least64_t, 64 > unative64_t;
  80. // aligned native endian_arithmetic typedefs are not provided because
  81. // <cstdint> types are superior for this use case
  82. typedef endian_arithmetic< order::big, int16_t, 16, align::yes > aligned_big16_t;
  83. typedef endian_arithmetic< order::big, uint16_t, 16, align::yes > aligned_ubig16_t;
  84. typedef endian_arithmetic< order::little, int16_t, 16, align::yes > aligned_little16_t;
  85. typedef endian_arithmetic< order::little, uint16_t, 16, align::yes > aligned_ulittle16_t;
  86. typedef endian_arithmetic< order::big, int32_t, 32, align::yes > aligned_big32_t;
  87. typedef endian_arithmetic< order::big, uint32_t, 32, align::yes > aligned_ubig32_t;
  88. typedef endian_arithmetic< order::little, int32_t, 32, align::yes > aligned_little32_t;
  89. typedef endian_arithmetic< order::little, uint32_t, 32, align::yes > aligned_ulittle32_t;
  90. typedef endian_arithmetic< order::big, int64_t, 64, align::yes > aligned_big64_t;
  91. typedef endian_arithmetic< order::big, uint64_t, 64, align::yes > aligned_ubig64_t;
  92. typedef endian_arithmetic< order::little, int64_t, 64, align::yes > aligned_little64_t;
  93. typedef endian_arithmetic< order::little, uint64_t, 64, align::yes > aligned_ulittle64_t;
  94. } // namespace endian
  95. } // namespace boost
  96. #endif //BOOST_ENDIAN_ENDIAN_HPP