xplatform.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /***************************************************************************
  2. * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
  3. * Copyright (c) QuantStack *
  4. * *
  5. * Distributed under the terms of the BSD 3-Clause License. *
  6. * *
  7. * The full license is in the file LICENSE, distributed with this software. *
  8. ****************************************************************************/
  9. #ifndef XTL_XPLATFORM_HPP
  10. #define XTL_XPLATFORM_HPP
  11. #include <cstring>
  12. #include <cstdint>
  13. namespace xtl
  14. {
  15. enum class endian
  16. {
  17. big_endian,
  18. little_endian,
  19. mixed
  20. };
  21. inline endian endianness()
  22. {
  23. uint32_t utmp = 0x01020304;
  24. char btmp[sizeof(utmp)];
  25. std::memcpy(&btmp[0], &utmp, sizeof(utmp));
  26. switch(btmp[0])
  27. {
  28. case 0x01:
  29. return endian::big_endian;
  30. case 0x04:
  31. return endian::little_endian;
  32. default:
  33. return endian::mixed;
  34. }
  35. }
  36. }
  37. #endif